Class: FanartApi::Base

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/fanart_api/base.rb

Direct Known Subclasses

Movie, Music, Tv

Instance Method Summary collapse

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(options)
  @params = options

  self
end

#prepare_uriObject



29
30
31
# File 'lib/fanart_api/base.rb', line 29

def prepare_uri
  @uri_template ? @uri_template.expand(@params.merge(api_key: @client.api_key)) : nil
end

#responseObject



25
26
27
# File 'lib/fanart_api/base.rb', line 25

def response
  @uri_template ? self.class.get(uri, body: @options) : nil
end

#restful_param_keys(uri_expanded) ⇒ Object



40
41
42
# File 'lib/fanart_api/base.rb', line 40

def restful_param_keys(uri_expanded)
  @uri_template.extract(uri_expanded).keys
end

#shared_uriObject



44
45
46
# File 'lib/fanart_api/base.rb', line 44

def shared_uri
  '{api_key}/{id}/json/{type}/{sort}/{limit}'
end

#uriObject



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