api_roulette 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +34 -0
- data/Gemfile +4 -0
- data/LICENSE +21 -0
- data/README.md +9 -0
- data/Rakefile +1 -0
- data/api_roulette.gemspec +24 -0
- data/lib/api_roulette.rb +4 -0
- data/lib/api_roulette/api.rb +13 -0
- data/lib/api_roulette/api_loader.rb +61 -0
- data/lib/api_roulette/api_roulette_controller.rb +16 -0
- data/lib/api_roulette/api_store.rb +11 -0
- metadata +97 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: fd2bbe16f87137663f14c4784f16c0aad7d71f3a
|
4
|
+
data.tar.gz: c3ebd65f958682b419a5835d07e94e95a41ea615
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 83dd66029e7562a3f56854e2f3fcce9b9e13c1a2caeeda4d4073b3ba7a1143ad7fb9bd3a6ee553750effc496669abf8fb6857d879839eaecbe5ebbc2c410ee45
|
7
|
+
data.tar.gz: 8b841dd06e9634eae18730e6d36579537516f030732aeaccfe7ca02a7793656c7ed2529c2a24f7b41fcf93058849c3dfe7eccc1c88f50d979b6f4606f744979c
|
data/.gitignore
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/test/tmp/
|
9
|
+
/test/version_tmp/
|
10
|
+
/tmp/
|
11
|
+
|
12
|
+
## Specific to RubyMotion:
|
13
|
+
.dat*
|
14
|
+
.repl_history
|
15
|
+
build/
|
16
|
+
|
17
|
+
## Documentation cache and generated files:
|
18
|
+
/.yardoc/
|
19
|
+
/_yardoc/
|
20
|
+
/doc/
|
21
|
+
/rdoc/
|
22
|
+
|
23
|
+
## Environment normalisation:
|
24
|
+
/.bundle/
|
25
|
+
/lib/bundler/man/
|
26
|
+
|
27
|
+
# for a library or gem, you might want to ignore these files since the code is
|
28
|
+
# intended to run in multiple environments; otherwise, check them in:
|
29
|
+
# Gemfile.lock
|
30
|
+
# .ruby-version
|
31
|
+
# .ruby-gemset
|
32
|
+
|
33
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
34
|
+
.rvmrc
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2014 Clark Feusier
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
api-roulette
|
2
|
+
============
|
3
|
+
|
4
|
+
Get random APIs from ProgrammableWeb.com
|
5
|
+
|
6
|
+
Scrapes API titles, links, categories and descriptions from a pecpage of ProgrammableWeb.com, or provides a given quantity of random APIs
|
7
|
+
|
8
|
+
APIRoulette.get_random_api(quantity)
|
9
|
+
APIRoulette.get_all_apis_on_page(page_number)
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,24 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
|
4
|
+
Gem::Specification.new do |spec|
|
5
|
+
spec.name = 'api_roulette'
|
6
|
+
spec.version = '0.0.5'
|
7
|
+
spec.date = '2014-08-16'
|
8
|
+
spec.summary = "Get random APIs from ProgrammableWeb.com"
|
9
|
+
spec.description = "Scrapes API titles, links, categories and descriptions from a pecpage of ProgrammableWeb.com, or provides a given quantity of random APIs"
|
10
|
+
spec.authors = ["James Robinson"]
|
11
|
+
spec.email = 'james.michael.robinson@gmail.com'
|
12
|
+
spec.files = ["lib/api_roulette.rb"]
|
13
|
+
spec.homepage = 'http://rubygems.org/gems/api_roulette'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_runtime_dependency "nokogiri", '~> 1.6'
|
24
|
+
end
|
data/lib/api_roulette.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
class API
|
2
|
+
attr_reader :title, :description, :category, :url
|
3
|
+
def initialize(params)
|
4
|
+
@url = params.fetch(:url)
|
5
|
+
@title = params.fetch(:title)
|
6
|
+
@description = params.fetch(:description)
|
7
|
+
@category = params.fetch(:category)
|
8
|
+
end
|
9
|
+
|
10
|
+
def to_s
|
11
|
+
"(#{@category}) #{@title} - #{@url}"
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
class APILoader
|
2
|
+
def self.load_api_list(page_number=nil)
|
3
|
+
page = (page_number.nil? ? get_random_api_page : get_api_page(page_number))
|
4
|
+
get_apis_from_page(page)
|
5
|
+
end
|
6
|
+
|
7
|
+
private
|
8
|
+
|
9
|
+
def self.get_apis_from_page(page)
|
10
|
+
api_links = extract_api_links_from_page(page)
|
11
|
+
api_descriptions = extract_api_descriptions_from_page(page)
|
12
|
+
api_categories = extract_api_categories_from_page(page)
|
13
|
+
|
14
|
+
convert_api_data_to_api_objects(api_links, api_descriptions, api_categories)
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.get_api_page(page_number)
|
18
|
+
url = "http://www.programmableweb.com/apis/directory?page=#{page_number}"
|
19
|
+
get_webpage(url)
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.get_random_api_page
|
23
|
+
page_number = rand(1..104)
|
24
|
+
get_api_page(page_number)
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.get_webpage(url)
|
28
|
+
Nokogiri::HTML(open(url))
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.extract_api_links_from_page(page)
|
32
|
+
page.css('table tr td.views-field-title a')
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.extract_api_descriptions_from_page(page)
|
36
|
+
page.css('table tr td.views-field-field-api-description')
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.extract_api_categories_from_page(page)
|
40
|
+
page.css('table tr td.views-field-field-article-primary-category')
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.convert_api_data_to_api_objects(links, descriptions, categories)
|
44
|
+
links.map.with_index do |link, index|
|
45
|
+
API.new(convert_link_to_hash(link).merge(convert_description_to_hash(descriptions[index])).merge(convert_category_to_hash(categories[index])))
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.convert_link_to_hash(link)
|
50
|
+
{url: "#{PW_URL}#{link['href']}", title: link.text}
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.convert_description_to_hash(description)
|
54
|
+
{description: description.text.strip }
|
55
|
+
end
|
56
|
+
|
57
|
+
def self.convert_category_to_hash(category)
|
58
|
+
{category: (category.nil? ? "" : category.text.strip) }
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
require 'open-uri'
|
3
|
+
|
4
|
+
PW_URL = "http://www.programmableweb.com"
|
5
|
+
|
6
|
+
class APIRoulette
|
7
|
+
def self.get_random_api(quantity=1)
|
8
|
+
@api_store = APIStore.new(APILoader.load_api_list)
|
9
|
+
@api_store.get_random_api(quantity)
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.get_all_apis_on_page(page_number=0)
|
13
|
+
@api_store = APIStore.new(APILoader.load_api_list(page_number))
|
14
|
+
@api_store.apis
|
15
|
+
end
|
16
|
+
end
|
metadata
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: api_roulette
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.5
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- James Robinson
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-08-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: nokogiri
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.6'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.6'
|
55
|
+
description: Scrapes API titles, links, categories and descriptions from a pecpage
|
56
|
+
of ProgrammableWeb.com, or provides a given quantity of random APIs
|
57
|
+
email: james.michael.robinson@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- api_roulette.gemspec
|
68
|
+
- lib/api_roulette.rb
|
69
|
+
- lib/api_roulette/api.rb
|
70
|
+
- lib/api_roulette/api_loader.rb
|
71
|
+
- lib/api_roulette/api_roulette_controller.rb
|
72
|
+
- lib/api_roulette/api_store.rb
|
73
|
+
homepage: http://rubygems.org/gems/api_roulette
|
74
|
+
licenses:
|
75
|
+
- MIT
|
76
|
+
metadata: {}
|
77
|
+
post_install_message:
|
78
|
+
rdoc_options: []
|
79
|
+
require_paths:
|
80
|
+
- lib
|
81
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
requirements: []
|
92
|
+
rubyforge_project:
|
93
|
+
rubygems_version: 2.4.1
|
94
|
+
signing_key:
|
95
|
+
specification_version: 4
|
96
|
+
summary: Get random APIs from ProgrammableWeb.com
|
97
|
+
test_files: []
|