Class: GiantBomb::Resource
- Inherits:
-
Object
- Object
- GiantBomb::Resource
show all
- Defined in:
- lib/giantbomb/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.
49
50
51
52
53
54
55
|
# File 'lib/giantbomb/resource.rb', line 49
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
22
23
24
25
26
|
# File 'lib/giantbomb/resource.rb', line 22
def self.detail(id, conditions={})
search = GiantBomb::Search.new("/#{self.endpoints[:singular]}/#{self.endpoint_id + id.to_s}/")
search.filter(conditions)
self.new(search.fetch)
end
|
.endpoint_id ⇒ Object
18
19
20
|
# File 'lib/giantbomb/resource.rb', line 18
def self.endpoint_id
@@endpoint_id[self.name.downcase]
end
|
.endpoints ⇒ Object
14
15
16
|
# File 'lib/giantbomb/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/giantbomb/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
28
29
30
31
32
33
34
|
# File 'lib/giantbomb/resource.rb', line 28
def self.list(conditions={})
search = GiantBomb::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
36
37
38
39
40
41
42
43
|
# File 'lib/giantbomb/resource.rb', line 36
def self.search(query)
search = GiantBomb::Search.new
search.resources("#{self.endpoints[:singular]}")
search.query(query)
search.fetch.collect do |result|
self.new(result)
end
end
|