Class: TMDB::API

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/tmdb/api.rb

Constant Summary collapse

@@api_key =
''

Class Method Summary collapse

Class Method Details

.api_keyObject



11
12
13
# File 'lib/tmdb/api.rb', line 11

def self.api_key
  @@api_key
end

.api_key=(key) ⇒ Object



15
16
17
# File 'lib/tmdb/api.rb', line 15

def self.api_key=(key)
  @@api_key = key
end

.configObject



19
20
21
22
23
24
# File 'lib/tmdb/api.rb', line 19

def self.config
  options = { api_key: self.api_key }
  response = TMDB::API.get("/3/configuration", query: options).parsed_response
  Hashie::Mash.new(response)
  # configuration.images.base_url => "http://image.tmdb.org/t/p/" 
end

.genres(source = "movie") ⇒ Object

Returns a hash of genres => genre name, etc.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/tmdb/api.rb', line 27

def self.genres(source="movie")
  options = { api_key: self.api_key,
              language: 'en' }

  case source.downcase
  when "movie", "movies"
    source = "movie"
  when "tv"
    source = "tv"
  end

  genres = {}
  TMDB::API.get("/3/genre/#{source}/list", query: options)['genres'].each do |genre|
    genres[genre['id']] = genre['name']
  end
  
  return genres
end