Class: Jservice

Inherits:
Object
  • Object
show all
Defined in:
lib/jservice.rb,
lib/jservice/version.rb

Defined Under Namespace

Classes: Error

Constant Summary collapse

VERSION =
"1.0.0"

Instance Method Summary collapse

Constructor Details

#initialize(**config) ⇒ Jservice

Returns a new instance of Jservice.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/jservice.rb', line 12

def initialize(**config)
  @config = {
    # base URL of API
    url: 'jservice.io',
    # use https
    use_ssl: true,
    # port to use for API (`nil` for default)
    port: nil,
    # ignore clues above the given invalid_count (`nil` ignored)
    invalid_filter: nil
  }
  @config.merge!(config)
  @config[:port] ||= @config[:use_ssl] ? 443 : 80

  @http = Net::HTTP.new(@config[:url], @config[:port])
  @http.use_ssl = @config[:use_ssl]
  @http.start()
end

Instance Method Details

#categories(**options) ⇒ Object

request a list/page of categories

options =

count (int): amount of categories to return, limited to 100 at a time

offset (int): offsets the starting id of categories returned. Useful in pagination.



82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/jservice.rb', line 82

def categories(**options)
  # validate input
  filter_keys(options, :count, :offset)
  
  result = nil
  begin
    result = api_request('categories', options)
  rescue ex
    raise ex
  else
    return result
  end
end

#category(id) ⇒ Object

request a specific category id: integer ID of category



98
99
100
101
102
103
104
105
106
107
# File 'lib/jservice.rb', line 98

def category(id)
  result = nil
  begin
    result = api_request('category', id: id)
  rescue ex
    raise ex
  else
    return result
  end
end

#clues(**options) ⇒ Object

request a page of clues

options =

value ( int): the value of the clue in dollars

category ( int): the id of the category you want to return min_date (date): earliest date to show, based on original air date max_date (date): latest date to show, based on original air date

offset ( int): offsets the returned clues. Useful in pagination


38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/jservice.rb', line 38

def clues(**options)
  # validate input
  filter_keys(options, :value, :category, :min_date, :max_date, :offset, :page)
  
  result = nil
  begin
    result = api_request('clues', options)
  rescue ex
    raise ex
  else
    return result
  end
end

#random_clues(count = 1) ⇒ Object

request random clues count: number of clues to return



54
55
56
57
58
59
60
61
62
63
# File 'lib/jservice.rb', line 54

def random_clues(count = 1)
  result = nil
  begin
    result = api_request('random', count: count)
  rescue ex
    raise ex
  else
    return result
  end
end

#random_finals(count = 1) ⇒ Object

request random final jeopardy clues count: number of clues to return



67
68
69
70
71
72
73
74
75
76
# File 'lib/jservice.rb', line 67

def random_finals(count = 1)
  result = nil
  begin
    result = api_request('final', count: count)
  rescue ex
    raise ex
  else
    return result
  end
end