Class: ThetvdbApi::Base

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

Direct Known Subclasses

Actor, Banner, Episode, Search, Series, Update

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Base

Returns a new instance of Base.



8
9
10
# File 'lib/thetvdb_api/base.rb', line 8

def initialize(client)
  @client = client
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



6
7
8
# File 'lib/thetvdb_api/base.rb', line 6

def client
  @client
end

#optionsObject (readonly)

Returns the value of attribute options.



6
7
8
# File 'lib/thetvdb_api/base.rb', line 6

def options
  @options
end

#uriObject (readonly)

Returns the value of attribute uri.



6
7
8
# File 'lib/thetvdb_api/base.rb', line 6

def uri
  @uri
end

Instance Method Details

#api_keyObject



39
40
41
# File 'lib/thetvdb_api/base.rb', line 39

def api_key
  client.api_key
end

#api_urlObject



35
36
37
# File 'lib/thetvdb_api/base.rb', line 35

def api_url
  client.api_url
end

#get(uri, options = {}) ⇒ Object



12
13
14
15
16
17
# File 'lib/thetvdb_api/base.rb', line 12

def get(uri, options = {})
  @uri = uri
  @options = options

  self
end

#languageObject



43
44
45
# File 'lib/thetvdb_api/base.rb', line 43

def language
  client.language
end

#request_options(options = {}) ⇒ Object



24
25
26
27
28
29
# File 'lib/thetvdb_api/base.rb', line 24

def request_options(options = {})
  {
    query: options,
    base_uri: api_url
  }
end

#responseObject



19
20
21
22
# File 'lib/thetvdb_api/base.rb', line 19

def response
  response = self.class.get(uri, request_options(options))
  response.code == 200 ? response.parsed_response : nil
end

#series_uri(series_id) ⇒ Object



31
32
33
# File 'lib/thetvdb_api/base.rb', line 31

def series_uri(series_id)
  "#{api_key}/series/#{series_id}/"
end