Sha256: 7bff6032c2c296e99b9c49f4f10044fa383dc48996c0184be844f2da3ff225e2
Contents?: true
Size: 1.04 KB
Versions: 1
Compression:
Stored size: 1.04 KB
Contents
module MySportsFeeds class Api def initialize(username, password, options = {}) @username = username @password = password @options = options end def get(url, params = {}) request = make_request(url, :get, params) response = request.run Response::Success.new(JSON.parse(response.response_body), response.response_code) rescue JSON::ParserError => e Response::Error.new(e.message) end def make_request(url, method, params = {}) Typhoeus::Request.new( build_url(url), method: method, params: params, userpwd: "#{@username}:#{@password}", accept_encoding: "gzip", followlocation: true ) end private def build_url(url) "https://www.mysportsfeeds.com/api/feed/pull/nba/#{season}/#{url}.#{format}" end def format @format ||= @options.fetch(:format, 'json') end def season @season ||= @options.fetch(:season) end def force @force ||= @options.fetch(:force, true) end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
mysportsfeeds-0.1.0 | lib/mysportsfeeds/api.rb |