Class: Tmdb::Resource

Inherits:
Object
  • Object
show all
Defined in:
lib/themoviedb/resource.rb

Direct Known Subclasses

Collection, Company, Episode, Find, Keyword, Movie, Person, Season, TV

Constant Summary collapse

@@endpoints =
{}
@@endpoint_id =
{}

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Resource

Returns a new instance of Resource.



50
51
52
53
54
# File 'lib/themoviedb/resource.rb', line 50

def initialize(attributes = {})
  attributes.each do |key, value|
    instance_variable_set("@#{key}", value) if respond_to?(key.to_sym)
  end
end

Class Method Details

.detail(id, conditions = {}) ⇒ Object

Get the basic resource information for a specific id.



23
24
25
26
27
# File 'lib/themoviedb/resource.rb', line 23

def self.detail(id, conditions = {})
  search = Tmdb::Search.new("/#{endpoints[:singular]}/#{endpoint_id + id.to_s}")
  search.filter(conditions)
  search.fetch_response
end

.endpoint_idObject



18
19
20
# File 'lib/themoviedb/resource.rb', line 18

def self.endpoint_id
  @@endpoint_id[name.downcase]
end

.endpointsObject



14
15
16
# File 'lib/themoviedb/resource.rb', line 14

def self.endpoints
  @@endpoints[name.downcase]
end

.has_resource(singular = nil, opts = {}) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/themoviedb/resource.rb', line 6

def self.has_resource(singular = nil, opts = {})
  @@endpoints[name.downcase] = {
    singular: singular.nil? ? name.downcase.to_s : singular,
    plural: opts[:plural].nil? ? "#{name.downcase}s" : opts[:plural]
  }
  @@endpoint_id[name.downcase] = opts[:id].nil? ? "" : "#{opts[:id]}-"
end

.list(conditions = {}) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/themoviedb/resource.rb', line 29

def self.list(conditions = {})
  search = Tmdb::Search.new("/#{endpoints[:plural]}")
  search.filter(conditions)
  search.fetch.collect do |result|
    new(result)
  end
end

.search(query) ⇒ Object Also known as: find



37
38
39
40
41
42
43
44
# File 'lib/themoviedb/resource.rb', line 37

def self.search(query)
  search = Tmdb::Search.new
  search.resource(endpoints[:singular].to_s)
  search.query(query)
  search.fetch.collect do |result|
    new(result)
  end
end