Class: FanartApi::Base
- Inherits:
-
Object
- Object
- FanartApi::Base
- Includes:
- HTTParty
- Defined in:
- lib/fanart_api/base.rb
Instance Method Summary collapse
- #get(uri) ⇒ Object
-
#initialize(client) ⇒ Base
constructor
A new instance of Base.
- #params(options) ⇒ Object
- #prepare_uri ⇒ Object
- #response ⇒ Object
- #restful_param_keys(uri_expanded) ⇒ Object
- #shared_uri ⇒ Object
- #uri ⇒ Object
Constructor Details
#initialize(client) ⇒ Base
Returns a new instance of Base.
8 9 10 11 |
# File 'lib/fanart_api/base.rb', line 8 def initialize(client) @client = client @params = {} end |
Instance Method Details
#get(uri) ⇒ Object
13 14 15 16 17 |
# File 'lib/fanart_api/base.rb', line 13 def get(uri) @uri_template = URITemplate.new(uri) self end |
#params(options) ⇒ Object
19 20 21 22 23 |
# File 'lib/fanart_api/base.rb', line 19 def params() @params = self end |
#prepare_uri ⇒ Object
29 30 31 |
# File 'lib/fanart_api/base.rb', line 29 def prepare_uri @uri_template ? @uri_template.(@params.merge(api_key: @client.api_key)) : nil end |
#response ⇒ Object
25 26 27 |
# File 'lib/fanart_api/base.rb', line 25 def response @uri_template ? self.class.get(uri, body: ) : nil end |
#restful_param_keys(uri_expanded) ⇒ Object
40 41 42 |
# File 'lib/fanart_api/base.rb', line 40 def restful_param_keys() @uri_template.extract().keys end |
#shared_uri ⇒ Object
44 45 46 |
# File 'lib/fanart_api/base.rb', line 44 def shared_uri '{api_key}/{id}/json/{type}/{sort}/{limit}' end |
#uri ⇒ Object
33 34 35 36 37 38 |
# File 'lib/fanart_api/base.rb', line 33 def uri uri = prepare_uri @params.reject!{ |param| restful_param_keys(uri).include?(param.to_s) } uri end |