class NflData::MySportsFeeds::Client
Attributes
api_host[R]
api_key[R]
api_version[R]
base_url[R]
format[R]
Public Class Methods
new( api_host: ENV.fetch("MYSPORTSFEEDS_API_HOST"), api_key: ENV.fetch("MYSPORTSFEEDS_API_KEY"), api_version: ENV.fetch("MYSPORTSFEEDS_API_VERSION") )
click to toggle source
# File lib/nfl_data/my_sports_feeds/client.rb, line 8 def initialize( api_host: ENV.fetch("MYSPORTSFEEDS_API_HOST"), api_key: ENV.fetch("MYSPORTSFEEDS_API_KEY"), api_version: ENV.fetch("MYSPORTSFEEDS_API_VERSION") ) @api_host = api_host @api_key = api_key @api_version = api_version @format = "json" @base_url = "#{@api_host}/#{@api_version}/pull/nfl/" end
Public Instance Methods
get(endpoint:, params: {})
click to toggle source
# File lib/nfl_data/my_sports_feeds/client.rb, line 20 def get(endpoint:, params: {}) request(method: :get, endpoint: endpoint, params: params) end
Private Instance Methods
request(method:, endpoint:, params:)
click to toggle source
# File lib/nfl_data/my_sports_feeds/client.rb, line 26 def request(method:, endpoint:, params:) request = Typhoeus::Request.new( "#{base_url}#{endpoint}.#{format}", method: method, params: params, accept_encoding: "gzip", userpwd: "#{api_key}:MYSPORTSFEEDS" ) # request.on_complete do |response| # if response.success? # end # end response = request.run JSON.parse(response.body) end