Class: Locomotive::Coal::Resources::ContentEntries

Inherits:
Base
  • Object
show all
Defined in:
lib/locomotive/coal/resources/content_entries.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#credentials, #uri

Instance Method Summary collapse

Methods inherited from Base

#create, #destroy, #destroy_all, #update_with_locale

Methods included from Locomotive::Coal::Resources::Concerns::Request

#delete, #do_request, #get, #post, #put, #without_authentication

Constructor Details

#initialize(uri, credentials, content_type) ⇒ ContentEntries

Returns a new instance of ContentEntries.



9
10
11
12
# File 'lib/locomotive/coal/resources/content_entries.rb', line 9

def initialize(uri, credentials, content_type)
  @content_type = content_type
  super(uri, credentials)
end

Instance Attribute Details

#content_typeObject

Returns the value of attribute content_type.



7
8
9
# File 'lib/locomotive/coal/resources/content_entries.rb', line 7

def content_type
  @content_type
end

Instance Method Details

#each(query = nil, options = nil, locale = nil, &block) ⇒ Object



28
29
30
31
32
33
34
35
# File 'lib/locomotive/coal/resources/content_entries.rb', line 28

def each(query = nil, options = nil, locale = nil, &block)
  page = 1
  while page do
    resources = all(query, (options || {}).merge(page: page), locale)
    resources.each(&block)
    page = resources._next_page
  end
end

#index(query = nil, options = {}, locale = nil) ⇒ Object Also known as: all



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/locomotive/coal/resources/content_entries.rb', line 14

def index(query = nil, options = {}, locale = nil)
  parameters = { where: (query || {}).to_json }.merge(options || {})
  parameters[:_locale] = locale if locale

  response = get(resources_name, parameters, true)

  list = response.body.map { |attributes| Resource.new(attributes) }

  PaginatedResources.new(list,
    options[:page] || 1,
    response.headers[:x_total_pages].to_i,
    response.headers[:x_total_entries].to_i)
end