class Igdb::ApiResource
Attributes
path[RW]
representer[RW]
Public Class Methods
all(opts={})
click to toggle source
# File lib/igdb/models/api_resource.rb, line 27 def self.all(opts={}) params = Hash.new.tap do |hash| hash['offset'] = opts[:offset] || 0 hash['limit'] = opts[:limit] || 50 hash['fields'] = '*' end build_collection(Igdb::Requester.get("#{self.path}", params), self.representer) end
count()
click to toggle source
# File lib/igdb/models/api_resource.rb, line 9 def self.count Igdb::Requester.get("#{self.path}/count")['count'] end
find(id)
click to toggle source
# File lib/igdb/models/api_resource.rb, line 13 def self.find(id) params = { fields: '*' } build_single_resource(Igdb::Requester.get("#{self.path}/#{id}", params)[0], self.representer) end
search(opts={})
click to toggle source
# File lib/igdb/models/api_resource.rb, line 18 def self.search(opts={}) params = Hash.new.tap do |hash| hash['search'] = opts[:query] if opts[:query] hash['filters'] = opts[:filters] if opts[:filters] hash['fields'] = '*' end build_collection(Igdb::Requester.get("#{self.path}", params), self.representer) end
Private Class Methods
build_collection(response, representer)
click to toggle source
# File lib/igdb/models/api_resource.rb, line 41 def self.build_collection(response, representer) response.reduce([]) do |resources, response| resources << self.new.extend(representer).from_hash(response) end end
build_single_resource(response, representer)
click to toggle source
# File lib/igdb/models/api_resource.rb, line 37 def self.build_single_resource(response, representer) self.new.extend(representer).from_hash(response) end
Private Instance Methods
build_for_collection(response, representer)
click to toggle source
# File lib/igdb/models/api_resource.rb, line 47 def build_for_collection(response, representer) [].extend(representer.for_collection).from_hash(response) end