Class: MySportsFeeds::Api
- Inherits:
-
Object
- Object
- MySportsFeeds::Api
- Defined in:
- lib/mysportsfeeds/api.rb
Instance Method Summary collapse
- #get(url, params = {}) ⇒ Object
-
#initialize(username, password, options = {}) ⇒ Api
constructor
A new instance of Api.
- #make_request(url, method, params = {}) ⇒ Object
Constructor Details
#initialize(username, password, options = {}) ⇒ Api
Returns a new instance of Api.
3 4 5 6 7 |
# File 'lib/mysportsfeeds/api.rb', line 3 def initialize(username, password, = {}) @username = username @password = password @options = end |
Instance Method Details
#get(url, params = {}) ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/mysportsfeeds/api.rb', line 9 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.) end |
#make_request(url, method, params = {}) ⇒ Object
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/mysportsfeeds/api.rb', line 17 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 |