Class: Custplace::Stores

Inherits:
Base
  • Object
show all
Defined in:
lib/custplace/stores.rb

Constant Summary

Constants inherited from Base

Base::API_VERSION

Instance Attribute Summary

Attributes inherited from Base

#client

Instance Method Summary collapse

Methods inherited from Base

#default_headers, #get, #initialize, #post

Constructor Details

This class inherits a constructor from Custplace::Base

Instance Method Details

#find(store_id) ⇒ Custplace::Entities::Store

Retrieves the details of an existing store.

Parameters:

  • store_id (String)

    the id of the store to retrieve

Returns:



34
35
36
37
# File 'lib/custplace/stores.rb', line 34

def find(store_id)
  response = get("/shops/#{store_id}")
  Custplace::Entities::Store.new(response["data"])
end

#list(params: {}) ⇒ Array<Custplace::Entities::Store>

Get the list of all active stores

Parameters:

  • params (Hash) (defaults to: {})

    the params to use for the request

Returns:



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/custplace/stores.rb', line 11

def list(params: {})
  page = 1
  stores = []
  response = get("/shops", params: params.merge(page: page))
  data = response["data"]
  stores = stores.concat(data.map { |store| Custplace::Entities::Store.new(store) })
  pagination = response["links"]

  while pagination["next"]
    page += 1
    response = get("/shops", params: params.merge(page: page))
    data = response["data"]
    stores = stores.concat(data.map { |store| Custplace::Entities::Store.new(store) })
    pagination = response["links"]
  end

  stores
end