Class: Tmdb::Resource
- Inherits:
-
Object
show all
- Defined in:
- lib/themoviedb-jzg/resource.rb
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
55
56
|
# File 'lib/themoviedb-jzg/resource.rb', line 50
def initialize(attributes={})
attributes.each do |key, value|
if self.respond_to?(key.to_sym)
self.instance_variable_set("@#{key}", value)
end
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-jzg/resource.rb', line 23
def self.detail(id, conditions={})
search = Tmdb::Search.new("/#{self.endpoints[:singular]}/#{self.endpoint_id + id.to_s}")
search.filter(conditions)
search.fetch_response
end
|
.endpoint_id ⇒ Object
18
19
20
|
# File 'lib/themoviedb-jzg/resource.rb', line 18
def self.endpoint_id
@@endpoint_id[self.name.downcase]
end
|
.endpoints ⇒ Object
14
15
16
|
# File 'lib/themoviedb-jzg/resource.rb', line 14
def self.endpoints
@@endpoints[self.name.downcase]
end
|
.has_resource(singular = nil, opts = {}) ⇒ Object
6
7
8
9
10
11
12
|
# File 'lib/themoviedb-jzg/resource.rb', line 6
def self.has_resource(singular=nil, opts={})
@@endpoints[self.name.downcase] = {
:singular => singular.nil? ? "#{self.name.downcase}" : singular,
:plural => opts[:plural].nil? ? "#{self.name.downcase}s" : opts[:plural]
}
@@endpoint_id[self.name.downcase] = opts[:id].nil? ? "" : "#{opts[:id]}-"
end
|
.list(conditions = {}) ⇒ Object
29
30
31
32
33
34
35
|
# File 'lib/themoviedb-jzg/resource.rb', line 29
def self.list(conditions={})
search = Tmdb::Search.new("/#{self.endpoints[:plural]}")
search.filter(conditions)
search.fetch.collect do |result|
self.new(result)
end
end
|
.search(query) ⇒ Object
Also known as:
find
37
38
39
40
41
42
43
44
|
# File 'lib/themoviedb-jzg/resource.rb', line 37
def self.search(query)
search = Tmdb::Search.new
search.resource("#{self.endpoints[:singular]}")
search.query(query)
search.fetch.collect do |result|
self.new(result)
end
end
|