Class: Bookafy::Customer
- Inherits:
-
BaseService
- Object
- BaseService
- Bookafy::Customer
- Defined in:
- lib/bookafy/customer.rb
Constant Summary
Constants inherited from BaseService
Instance Method Summary collapse
- #all(query_params = {}) ⇒ Object
-
#initialize ⇒ Customer
constructor
A new instance of Customer.
- #uri ⇒ Object
Methods inherited from BaseService
#access_token, #bookafy_api_url, #get
Constructor Details
#initialize ⇒ Customer
Returns a new instance of Customer.
4 5 6 7 |
# File 'lib/bookafy/customer.rb', line 4 def initialize super @page = 1 end |
Instance Method Details
#all(query_params = {}) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/bookafy/customer.rb', line 13 def all(query_params = {}) query_params[:page] = @page response = get(uri, query_params) unless response.code == 200 return [] end response_json = JSON.parse(response.body)['response'] customers_json = response_json['customers'] customers = customers_json.map do |data| Bookafy::Model::Customer.new(data) end if response_json['remaining'] > 0 @page = @page + 1 customers += all(query_params) end customers rescue => e puts "Error at fetching customers: #{e.}" return [] end |
#uri ⇒ Object
9 10 11 |
# File 'lib/bookafy/customer.rb', line 9 def uri 'customers' end |