Class: Locomotive::Coal::Resources::Accounts

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

Instance Attribute Summary

Attributes inherited from Base

#credentials, #uri

Instance Method Summary collapse

Methods inherited from Base

#create, #destroy, #destroy_all, #initialize, #update, #update_with_locale

Methods included from Concerns::Request

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

Constructor Details

This class inherits a constructor from Locomotive::Coal::Resources::Base

Instance Method Details

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



19
20
21
22
23
24
25
26
# File 'lib/locomotive/coal/resources/accounts.rb', line 19

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

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



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/locomotive/coal/resources/accounts.rb', line 6

def index(query = nil, options = {})
  parameters = { where: (query || {}).to_json }.merge(options || {})

  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