Class: JAPI::Trebek
- Inherits:
-
Object
- Object
- JAPI::Trebek
- Defined in:
- lib/japi/trebek.rb
Class Method Summary collapse
-
.categories(options = {}) ⇒ Array<Category>
Get a list of categories from the service.
-
.category(id) ⇒ Category
Get clues of a single category from the service.
-
.clues(options = {}) ⇒ Array<Clue>
Get a list of clues from the service.
-
.random(count = 1) ⇒ Array<Clue>
Get a random clue from the service.
Class Method Details
.categories(options = {}) ⇒ Array<Category>
Get a list of categories from the service
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/japi/trebek.rb', line 52 def categories( = {}) allowed_keys = ['count', 'offset'] .keys.each do |key| unless allowed_keys.include?(key.to_s) = "#{key} is not allowed, please only use the following options: #{allowed_keys.join(', ')}" raise InvalidParamError.new() end end query = URI.encode_www_form() response = JSON.parse(open(base_url << 'categories/?' << query).read) response.map do |category| Category.new(category) end end |
.category(id) ⇒ Category
Get clues of a single category from the service
73 74 75 76 77 |
# File 'lib/japi/trebek.rb', line 73 def category(id) query = URI.encode_www_form(id: id) response = JSON.parse(open(base_url << 'category/?' << query).read) Category.new(response) end |
.clues(options = {}) ⇒ Array<Clue>
Get a list of clues from the service
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/japi/trebek.rb', line 29 def clues( = {}) allowed_keys = ['value', 'category', 'max_date', 'min_date', 'offset'] .keys.each do |key| unless allowed_keys.include?(key.to_s) = "#{key} is not allowed, please only use the following options: #{allowed_keys.join(', ')}" raise InvalidParamError.new() end end query = URI.encode_www_form() response = JSON.parse(open(base_url << 'clues/?' << query).read) response.map do |clue| Clue.new(clue) end end |
.random(count = 1) ⇒ Array<Clue>
Get a random clue from the service
10 11 12 13 14 15 16 17 |
# File 'lib/japi/trebek.rb', line 10 def random(count = 1) url = base_url << "random/?" << URI.encode_www_form({count: count}) response = JSON.parse(open(url).read) response.map do |clue| Clue.new(clue) end end |