class Spoll::Client
Constants
- HEADERS
Attributes
token[R]
version[R]
Public Class Methods
new(client_id, client_secret, host, version)
click to toggle source
# File lib/spoll/client.rb, line 7 def initialize(client_id, client_secret, host, version) @client = ::OAuth2::Client.new(client_id, client_secret, site: host) @version = version get_token end
Public Instance Methods
get_event(id, params = {})
click to toggle source
# File lib/spoll/client.rb, line 29 def get_event(id, params = {}) get("/events/#{id}", params) end
get_events(params)
click to toggle source
# File lib/spoll/client.rb, line 25 def get_events(params) get('/events', params) end
get_match(id, params = {})
click to toggle source
# File lib/spoll/client.rb, line 21 def get_match(id, params = {}) get("/matches/#{id}", params) end
post_match(params)
click to toggle source
# File lib/spoll/client.rb, line 13 def post_match(params) post('/matches', { match: params }) end
put_match(id, params)
click to toggle source
# File lib/spoll/client.rb, line 17 def put_match(id, params) put("/matches/#{id}", { match: params }) end
Private Instance Methods
get(url, params)
click to toggle source
# File lib/spoll/client.rb, line 39 def get(url, params) request(:get, url, params, {}) end
get_token()
click to toggle source
# File lib/spoll/client.rb, line 35 def get_token @token = @client.client_credentials.get_token end
post(url, body)
click to toggle source
# File lib/spoll/client.rb, line 43 def post(url, body) request(:post, url, {}, body) end
put(url, body)
click to toggle source
# File lib/spoll/client.rb, line 47 def put(url, body) request(:put, url, {}, body) end
request(method, url, params, body)
click to toggle source
# File lib/spoll/client.rb, line 51 def request(method, url, params, body) with_retry do json = token.send(method, "/#{version}/#{url}", headers: HEADERS, params: params, body: body.to_json) Spoll::Response.new(json) end end
with_retry() { || ... }
click to toggle source
# File lib/spoll/client.rb, line 58 def with_retry tries = 0 begin yield rescue ::OAuth2::Error => error if error.response.status.eql?(401) if tries < 3 tries += 1 get_token retry end else error.response end end end