class Bookafy::Customer
Public Class Methods
new()
click to toggle source
Calls superclass method
Bookafy::BaseService::new
# File lib/bookafy/customer.rb, line 4 def initialize super @page = 1 end
Public Instance Methods
all(query_params = {})
click to toggle source
# 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.message}" return [] end
uri()
click to toggle source
# File lib/bookafy/customer.rb, line 9 def uri 'customers' end