Class: Locomotive::Coal::Resources::Accounts
- Defined in:
- lib/locomotive/coal/resources/accounts.rb
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
- #each(query = nil, options = nil, &block) ⇒ Object
- #index(query = nil, options = {}) ⇒ Object (also: #all)
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, = nil, &block) page = 1 while page do resources = all(query, ( || {}).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, = {}) parameters = { where: (query || {}).to_json }.merge( || {}) response = get(resources_name, parameters, true) list = response.body.map { |attributes| Resource.new(attributes) } PaginatedResources.new(list, [:page] || 1, response.headers[:x_total_pages].to_i, response.headers[:x_total_entries].to_i) end |