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

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