Class: Bookafy::Appointment
- Inherits:
-
BaseService
- Object
- BaseService
- Bookafy::Appointment
- Defined in:
- lib/bookafy/appointment.rb
Constant Summary
Constants inherited from BaseService
Instance Method Summary collapse
- #all(query_params = {}) ⇒ Object
-
#initialize ⇒ Appointment
constructor
A new instance of Appointment.
- #uri ⇒ Object
Methods inherited from BaseService
#access_token, #bookafy_api_url, #get
Constructor Details
#initialize ⇒ Appointment
Returns a new instance of Appointment.
4 5 6 7 |
# File 'lib/bookafy/appointment.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/appointment.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'] appointments_json = response_json['appointments'] appointments = appointments_json.map do |data| Bookafy::Model::Appointment.new(data) end if response_json['remaining'] > 0 @page = @page + 1 appointments += all(query_params) end appointments rescue => e puts "Error at fetching appointments: #{e.}" return [] end |
#uri ⇒ Object
9 10 11 |
# File 'lib/bookafy/appointment.rb', line 9 def uri 'appointments' end |