Class: Igdb::ApiResource

Inherits:
OpenStruct
  • Object
show all
Defined in:
lib/igdb/models/api_resource.rb

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.pathObject

Returns the value of attribute path.



7
8
9
# File 'lib/igdb/models/api_resource.rb', line 7

def path
  @path
end

.representerObject

Returns the value of attribute representer.



7
8
9
# File 'lib/igdb/models/api_resource.rb', line 7

def representer
  @representer
end

Class Method Details

.all(opts = {}) ⇒ Object



46
47
48
49
50
51
52
53
54
# File 'lib/igdb/models/api_resource.rb', line 46

def all(opts = {})
  params = {}.tap do |hash|
    hash['offset'] = opts[:offset] || 0
    hash['limit'] = opts[:limit] || 50
    hash['fields'] = '*'
  end

  build_collection(Igdb::Requester.get("#{path}/", opts), representer)
end

.countObject



9
10
11
# File 'lib/igdb/models/api_resource.rb', line 9

def count
  Igdb::Requester.get("#{path}/count")['count']
end

.find(id, options = {}) ⇒ Object



17
18
19
20
21
22
23
24
25
26
# File 'lib/igdb/models/api_resource.rb', line 17

def find(id, options = {})
  params = options
  params[:fields] = '*' unless params[:fields]

  if id.class == Array
    build_collection(Igdb::Requester.get("#{path}/#{id.join(',')}", params), representer)
  else
    build_single_resource(Igdb::Requester.get("#{path}/#{id}", params)[0], representer)
  end
end

.metaObject



13
14
15
# File 'lib/igdb/models/api_resource.rb', line 13

def meta
  Igdb::Requester.get("#{path}/meta")
end

.search(opts = {}) ⇒ Object



36
37
38
39
40
41
42
43
44
# File 'lib/igdb/models/api_resource.rb', line 36

def search(opts = {})
  params = {}.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("#{path}/", params), representer)
end

.slug(id, options = {}) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/igdb/models/api_resource.rb', line 28

def slug(id, options = {})
  params = options
  params['fields'] = '*' unless params[:fields]
  params['filter[slug][eq]'] = id

  build_single_resource(Igdb::Requester.get("#{path}/", params)[0], representer)
end