japi 1.0.2 → 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +2 -0
- data/README.md +14 -1
- data/japi.gemspec +15 -12
- data/lib/japi.rb +18 -6
- data/lib/japi/category.rb +14 -2
- data/lib/japi/clue.rb +20 -1
- data/lib/japi/trebek.rb +15 -6
- data/lib/japi/version.rb +2 -1
- metadata +19 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bbe49a679d0618c5e14265c3a2a6359a7950df63
|
4
|
+
data.tar.gz: 96c5973c545bfa378203ca5d8184b9ed7989c79b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 010d4fb6603bfd2fe31157615457e0be63f545427ec65f72e515a3b180486fd8b5e188b63fcbfa0aa484636fb8a289477fdb7cd4779f0acb4c61b2c79dd693ed
|
7
|
+
data.tar.gz: 43511e4f1e3c0ce7a694d9cab5fef84bbc73017c2d5a53c2deaf693964cef60ead46e549a7a10567da0ee1408e9ee3a713628536ffb3530a643cdeea639b8be3
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -23,7 +23,7 @@ Or install it yourself as:
|
|
23
23
|
## Usage
|
24
24
|
|
25
25
|
```ruby
|
26
|
-
clue = JAPI::Trebek.random # ask trebek for a random question!
|
26
|
+
clue = JAPI::Trebek.random.first # ask trebek for a random question!
|
27
27
|
puts clue.category.title # THE SOLAR SYSTEM
|
28
28
|
puts clue.question # Only 1 of 9 planets not named for a Greek or Roman mythological figure
|
29
29
|
|
@@ -35,6 +35,19 @@ else
|
|
35
35
|
puts "Too bad!"
|
36
36
|
end
|
37
37
|
```
|
38
|
+
|
39
|
+
You can host your own jservice.io, and configure the gem to use arbitrary endpoints.
|
40
|
+
|
41
|
+
### Example Configuration
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
require 'japi'
|
45
|
+
|
46
|
+
JAPI.configuration do |config|
|
47
|
+
config.jservice_url = "http://my-selfhosted-jservice.com"
|
48
|
+
end
|
49
|
+
```
|
50
|
+
|
38
51
|
## Development
|
39
52
|
|
40
53
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/japi.gemspec
CHANGED
@@ -4,20 +4,23 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
require 'japi/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name
|
8
|
-
spec.version
|
9
|
-
spec.authors
|
10
|
-
spec.email
|
7
|
+
spec.name = "japi"
|
8
|
+
spec.version = JAPI::VERSION
|
9
|
+
spec.authors = ["Dean Silfen"]
|
10
|
+
spec.email = ["dean.silfen@gmail.com"]
|
11
11
|
|
12
|
-
spec.summary
|
13
|
-
spec.description
|
14
|
-
spec.homepage
|
15
|
-
spec.license
|
12
|
+
spec.summary = %q{A simple object wrapper for the jservice.io API.}
|
13
|
+
spec.description = %q{A simple object wrapper for the jservice.io API.}
|
14
|
+
spec.homepage = "http://jeopardean.com"
|
15
|
+
spec.license = "MIT"
|
16
|
+
spec.required_ruby_version = '>= 1.9.3'
|
16
17
|
|
17
|
-
spec.files
|
18
|
-
spec.bindir
|
19
|
-
spec.executables
|
20
|
-
spec.require_paths
|
18
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
19
|
+
spec.bindir = "exe"
|
20
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
|
+
spec.require_paths = ["lib"]
|
22
|
+
|
23
|
+
spec.add_runtime_dependency 'configurations', '~> 2.2.0'
|
21
24
|
|
22
25
|
spec.add_development_dependency "bundler", "~> 1.10"
|
23
26
|
spec.add_development_dependency "rake", "~> 10.0"
|
data/lib/japi.rb
CHANGED
@@ -1,14 +1,26 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
|
1
|
+
require 'japi/version'
|
2
|
+
require 'japi/trebek'
|
3
|
+
require 'japi/category'
|
4
|
+
require 'japi/clue'
|
6
5
|
|
6
|
+
# namespace for JAPI, holds Clue, Category, Trebek, etc...
|
7
|
+
#
|
8
|
+
# @author Dean Silfen
|
7
9
|
module JAPI
|
8
|
-
require
|
10
|
+
require 'configurations'
|
11
|
+
require 'open-uri'
|
9
12
|
require 'json'
|
10
13
|
require 'uri'
|
11
14
|
|
15
|
+
# Exception for attempting to pass illegal params to the API
|
16
|
+
#
|
17
|
+
# @author Dean Silfen
|
12
18
|
class InvalidParamError < StandardError; end
|
19
|
+
|
20
|
+
include Configurations
|
21
|
+
configurable String, :jservice_url
|
22
|
+
configuration_defaults do |config|
|
23
|
+
config.jservice_url = "http://jservice.io/api/"
|
24
|
+
end
|
13
25
|
end
|
14
26
|
|
data/lib/japi/category.rb
CHANGED
@@ -1,6 +1,13 @@
|
|
1
1
|
module JAPI
|
2
|
-
|
3
|
-
|
2
|
+
# Category object with associated clues and a title.
|
3
|
+
#
|
4
|
+
# @author Dean Silfen
|
5
|
+
class Category
|
6
|
+
# @param options [Hash{String, Symbol => Fixnum, String}]
|
7
|
+
# @option options [Fixnum] :clues_count amount of clues associated with this category
|
8
|
+
# @option options [Fixnum] :id category id
|
9
|
+
# @option options [Array<Hash>] :clues hashes for constructing clues. see {Clue}
|
10
|
+
# @option options [String] :title the name of the category
|
4
11
|
def initialize(options = {})
|
5
12
|
@options = options
|
6
13
|
if @options["clues"]
|
@@ -8,18 +15,22 @@ module JAPI
|
|
8
15
|
end
|
9
16
|
end
|
10
17
|
|
18
|
+
# @return [String] title of the category
|
11
19
|
def title
|
12
20
|
@options["title"]
|
13
21
|
end
|
14
22
|
|
23
|
+
# @return [Fixnum] id of the category
|
15
24
|
def category_id
|
16
25
|
@options["id"]
|
17
26
|
end
|
18
27
|
|
28
|
+
# @return [Fixnum] amount of clues associated with this category
|
19
29
|
def clues_count
|
20
30
|
@options["clues_count"]
|
21
31
|
end
|
22
32
|
|
33
|
+
# @return [Array<Clue>] array of clues associated with a Category
|
23
34
|
def clues
|
24
35
|
return @options["clues"] unless @options["clues"].nil?
|
25
36
|
@options["clues"] = Trebek.category(category_id).clues
|
@@ -27,3 +38,4 @@ module JAPI
|
|
27
38
|
end
|
28
39
|
end
|
29
40
|
|
41
|
+
|
data/lib/japi/clue.rb
CHANGED
@@ -1,34 +1,53 @@
|
|
1
1
|
module JAPI
|
2
|
-
class Clue
|
3
2
|
|
3
|
+
# Clue object with a question, answer and other details.
|
4
|
+
#
|
5
|
+
# @author Dean Silfen
|
6
|
+
class Clue
|
7
|
+
|
8
|
+
# @param options [Hash{String, Symbol => Fixnum, String, DateTime, Hash}]
|
9
|
+
# @option options [Fixnum] :value amount in dollars of question
|
10
|
+
# @option options [Fixnum] :id clue id
|
11
|
+
# @option options [Fixnum] :category_id id of the clue's category
|
12
|
+
# @option options [Fixnum] :game_id id of the game where the clue appeared
|
13
|
+
# @option options [Hash] :category Hash containing Category info. see {JAPI::Category}
|
14
|
+
# @option options [String] :question the question text
|
15
|
+
# @option options [String] :answer the answer text
|
4
16
|
def initialize(options = {})
|
5
17
|
@options = options
|
6
18
|
end
|
7
19
|
|
20
|
+
# @return [Fixnum] amount in dollars of question
|
8
21
|
def value
|
9
22
|
@options["value"]
|
10
23
|
end
|
11
24
|
|
25
|
+
# @return [Fixnum] clue id
|
12
26
|
def clue_id
|
13
27
|
@options["id"]
|
14
28
|
end
|
15
29
|
|
30
|
+
# @return [Fixnum] category id
|
16
31
|
def category_id
|
17
32
|
@options["category_id"]
|
18
33
|
end
|
19
34
|
|
35
|
+
# @return [Category] category associated with this Clue
|
20
36
|
def category
|
21
37
|
Category.new(@options["category"])
|
22
38
|
end
|
23
39
|
|
40
|
+
# @return [Fixnum] id of the game this clue initially aired on
|
24
41
|
def game_id
|
25
42
|
@options["game_id"]
|
26
43
|
end
|
27
44
|
|
45
|
+
# @return [String] question text for this clue
|
28
46
|
def question
|
29
47
|
@options["question"]
|
30
48
|
end
|
31
49
|
|
50
|
+
# @return [String] answer text for this clue
|
32
51
|
def answer
|
33
52
|
@options["answer"]
|
34
53
|
end
|
data/lib/japi/trebek.rb
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
module JAPI
|
2
|
-
|
2
|
+
# Interface for creating and requesting Clues & Categories
|
3
|
+
#
|
4
|
+
# @author Dean Silfen
|
5
|
+
class Trebek
|
3
6
|
class << self
|
4
7
|
|
5
8
|
# Get a random clue from the service
|
@@ -8,7 +11,7 @@ module JAPI
|
|
8
11
|
#
|
9
12
|
# @return [Array<Clue>] A list of random clues
|
10
13
|
def random(count = 1)
|
11
|
-
url = base_url
|
14
|
+
url = base_url + "random/?" + URI.encode_www_form({count: count})
|
12
15
|
response = JSON.parse(open(url).read)
|
13
16
|
|
14
17
|
response.map do |clue|
|
@@ -26,6 +29,7 @@ module JAPI
|
|
26
29
|
# @option options [Fixnum] :offset offsets the returned clues. Useful in pagination
|
27
30
|
#
|
28
31
|
# @return [Array<Clue>] A list of clues that fit the query params
|
32
|
+
# @raise [InvalidParamError] if param not accepted by API is passed
|
29
33
|
def clues(options = {})
|
30
34
|
allowed_keys = ['value', 'category', 'max_date', 'min_date', 'offset']
|
31
35
|
options.keys.each do |key|
|
@@ -35,7 +39,7 @@ module JAPI
|
|
35
39
|
end
|
36
40
|
end
|
37
41
|
query = URI.encode_www_form(options)
|
38
|
-
response = JSON.parse(open(base_url
|
42
|
+
response = JSON.parse(open(base_url + 'clues/?' + query).read)
|
39
43
|
|
40
44
|
response.map do |clue|
|
41
45
|
Clue.new(clue)
|
@@ -49,6 +53,7 @@ module JAPI
|
|
49
53
|
# @option options [Fixnum] :offset offsets the starting id of categories returned. Useful in pagination.
|
50
54
|
#
|
51
55
|
# @return [Array<Category>] A list of clues that fit the query params
|
56
|
+
# @raise [InvalidParamError] if param not accepted by API is passed
|
52
57
|
def categories(options = {})
|
53
58
|
allowed_keys = ['count', 'offset']
|
54
59
|
options.keys.each do |key|
|
@@ -58,7 +63,7 @@ module JAPI
|
|
58
63
|
end
|
59
64
|
end
|
60
65
|
query = URI.encode_www_form(options)
|
61
|
-
response = JSON.parse(open(base_url
|
66
|
+
response = JSON.parse(open(base_url + 'categories/?' + query).read)
|
62
67
|
|
63
68
|
response.map do |category|
|
64
69
|
Category.new(category)
|
@@ -72,13 +77,17 @@ module JAPI
|
|
72
77
|
# @return [Category] A list of clues that fit the query params
|
73
78
|
def category(id)
|
74
79
|
query = URI.encode_www_form(id: id)
|
75
|
-
response = JSON.parse(open(base_url
|
80
|
+
response = JSON.parse(open(base_url + 'category/?' + query).read)
|
76
81
|
Category.new(response)
|
77
82
|
end
|
78
83
|
|
79
84
|
private
|
85
|
+
|
86
|
+
# @private
|
87
|
+
# @return [String] base url for jservice.io endpoint, configurable with
|
88
|
+
# JAPI.configuration block method.
|
80
89
|
def base_url
|
81
|
-
|
90
|
+
JAPI.configuration.jservice_url
|
82
91
|
end
|
83
92
|
end
|
84
93
|
end
|
data/lib/japi/version.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: japi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dean Silfen
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-12-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: configurations
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 2.2.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 2.2.0
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: bundler
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -89,7 +103,7 @@ files:
|
|
89
103
|
- lib/japi/clue.rb
|
90
104
|
- lib/japi/trebek.rb
|
91
105
|
- lib/japi/version.rb
|
92
|
-
homepage: http://
|
106
|
+
homepage: http://jeopardean.com
|
93
107
|
licenses:
|
94
108
|
- MIT
|
95
109
|
metadata: {}
|
@@ -101,7 +115,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
101
115
|
requirements:
|
102
116
|
- - ">="
|
103
117
|
- !ruby/object:Gem::Version
|
104
|
-
version:
|
118
|
+
version: 1.9.3
|
105
119
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
120
|
requirements:
|
107
121
|
- - ">="
|
@@ -109,7 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
109
123
|
version: '0'
|
110
124
|
requirements: []
|
111
125
|
rubyforge_project:
|
112
|
-
rubygems_version: 2.
|
126
|
+
rubygems_version: 2.5.1
|
113
127
|
signing_key:
|
114
128
|
specification_version: 4
|
115
129
|
summary: A simple object wrapper for the jservice.io API.
|