booker_ruby 1.14.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (120) hide show
  1. checksums.yaml +4 -4
  2. data/lib/booker/client.rb +154 -49
  3. data/lib/booker/errors.rb +6 -2
  4. data/lib/booker/model.rb +84 -0
  5. data/lib/booker/v4.1/availability.rb +21 -0
  6. data/lib/booker/v4.1/booking.rb +87 -0
  7. data/lib/booker/v4.1/merchant.rb +55 -0
  8. data/lib/booker/v4/business_client.rb +9 -0
  9. data/lib/booker/v4/business_rest.rb +88 -0
  10. data/lib/booker/v4/common_rest.rb +21 -0
  11. data/lib/booker/v4/customer_client.rb +15 -0
  12. data/lib/booker/v4/customer_rest.rb +15 -0
  13. data/lib/booker/v4/models/address.rb +14 -0
  14. data/lib/booker/v4/models/appointment.rb +79 -0
  15. data/lib/booker/v4/models/appointment_treatment.rb +53 -0
  16. data/lib/booker/v4/models/available_time.rb +15 -0
  17. data/lib/booker/v4/models/business_type.rb +7 -0
  18. data/lib/booker/v4/models/category.rb +7 -0
  19. data/lib/booker/v4/models/class_instance.rb +27 -0
  20. data/lib/booker/v4/models/country.rb +21 -0
  21. data/lib/booker/v4/models/current_price.rb +7 -0
  22. data/lib/booker/v4/models/customer.rb +54 -0
  23. data/lib/booker/v4/models/customer_2.rb +7 -0
  24. data/lib/booker/v4/models/customer_record_type.rb +7 -0
  25. data/lib/booker/v4/models/discount.rb +7 -0
  26. data/lib/booker/v4/models/dynamic_price.rb +13 -0
  27. data/lib/booker/v4/models/employee.rb +12 -0
  28. data/lib/booker/v4/models/feature_settings.rb +9 -0
  29. data/lib/booker/v4/models/final_total.rb +7 -0
  30. data/lib/booker/v4/models/gender.rb +7 -0
  31. data/lib/booker/v4/models/itinerary_time_slot.rb +9 -0
  32. data/lib/booker/v4/models/itinerary_time_slots_list.rb +9 -0
  33. data/lib/booker/v4/models/location.rb +40 -0
  34. data/lib/booker/v4/models/location_day_schedule.rb +20 -0
  35. data/lib/booker/v4/models/model.rb +78 -0
  36. data/lib/booker/v4/models/multi_service_availability_result.rb +9 -0
  37. data/lib/booker/v4/models/notification_settings.rb +14 -0
  38. data/lib/booker/v4/models/online_booking_settings.rb +25 -0
  39. data/lib/booker/v4/models/original_price.rb +7 -0
  40. data/lib/booker/v4/models/payment_method.rb +7 -0
  41. data/lib/booker/v4/models/preferred_staff_gender.rb +7 -0
  42. data/lib/booker/v4/models/price.rb +10 -0
  43. data/lib/booker/v4/models/receipt_display_price.rb +7 -0
  44. data/lib/booker/v4/models/room.rb +14 -0
  45. data/lib/booker/v4/models/shipping_address.rb +7 -0
  46. data/lib/booker/v4/models/source.rb +7 -0
  47. data/lib/booker/v4/models/spa.rb +7 -0
  48. data/lib/booker/v4/models/spa_employee_availability_search_item.rb +13 -0
  49. data/lib/booker/v4/models/status.rb +7 -0
  50. data/lib/booker/v4/models/sub_category.rb +7 -0
  51. data/lib/booker/v4/models/tag_price.rb +7 -0
  52. data/lib/booker/v4/models/teacher.rb +7 -0
  53. data/lib/booker/v4/models/teacher_2.rb +7 -0
  54. data/lib/booker/v4/models/time_zone.rb +10 -0
  55. data/lib/booker/v4/models/treatment.rb +21 -0
  56. data/lib/booker/v4/models/treatment_time_slot.rb +7 -0
  57. data/lib/booker/v4/models/type.rb +10 -0
  58. data/lib/booker/v4/models/user.rb +75 -0
  59. data/lib/booker/v4/request_helper.rb +33 -0
  60. data/lib/booker/v5/availability.rb +45 -0
  61. data/lib/booker/v5/models/availability.rb +18 -0
  62. data/lib/booker/v5/models/availability_result.rb +12 -0
  63. data/lib/booker/v5/models/location_hour.rb +16 -0
  64. data/lib/booker/v5/models/model.rb +9 -0
  65. data/lib/booker/v5/models/service.rb +13 -0
  66. data/lib/booker/v5/models/service_category.rb +11 -0
  67. data/lib/booker/version.rb +1 -1
  68. data/lib/booker_ruby.rb +70 -52
  69. metadata +80 -54
  70. data/lib/booker/business_client.rb +0 -22
  71. data/lib/booker/business_rest.rb +0 -112
  72. data/lib/booker/common_rest.rb +0 -43
  73. data/lib/booker/customer_client.rb +0 -17
  74. data/lib/booker/customer_rest.rb +0 -53
  75. data/lib/booker/models/address.rb +0 -12
  76. data/lib/booker/models/appointment.rb +0 -77
  77. data/lib/booker/models/appointment_treatment.rb +0 -51
  78. data/lib/booker/models/available_time.rb +0 -13
  79. data/lib/booker/models/business_type.rb +0 -5
  80. data/lib/booker/models/category.rb +0 -5
  81. data/lib/booker/models/class_instance.rb +0 -25
  82. data/lib/booker/models/country.rb +0 -19
  83. data/lib/booker/models/current_price.rb +0 -5
  84. data/lib/booker/models/customer.rb +0 -52
  85. data/lib/booker/models/customer_2.rb +0 -5
  86. data/lib/booker/models/customer_record_type.rb +0 -5
  87. data/lib/booker/models/discount.rb +0 -5
  88. data/lib/booker/models/dynamic_price.rb +0 -11
  89. data/lib/booker/models/employee.rb +0 -10
  90. data/lib/booker/models/feature_settings.rb +0 -7
  91. data/lib/booker/models/final_total.rb +0 -5
  92. data/lib/booker/models/gender.rb +0 -5
  93. data/lib/booker/models/itinerary_time_slot.rb +0 -7
  94. data/lib/booker/models/itinerary_time_slots_list.rb +0 -7
  95. data/lib/booker/models/location.rb +0 -38
  96. data/lib/booker/models/location_day_schedule.rb +0 -18
  97. data/lib/booker/models/model.rb +0 -150
  98. data/lib/booker/models/multi_service_availability_result.rb +0 -7
  99. data/lib/booker/models/notification_settings.rb +0 -12
  100. data/lib/booker/models/online_booking_settings.rb +0 -23
  101. data/lib/booker/models/original_price.rb +0 -5
  102. data/lib/booker/models/payment_method.rb +0 -5
  103. data/lib/booker/models/preferred_staff_gender.rb +0 -5
  104. data/lib/booker/models/price.rb +0 -8
  105. data/lib/booker/models/receipt_display_price.rb +0 -5
  106. data/lib/booker/models/room.rb +0 -12
  107. data/lib/booker/models/shipping_address.rb +0 -5
  108. data/lib/booker/models/source.rb +0 -5
  109. data/lib/booker/models/spa.rb +0 -5
  110. data/lib/booker/models/spa_employee_availability_search_item.rb +0 -11
  111. data/lib/booker/models/status.rb +0 -5
  112. data/lib/booker/models/sub_category.rb +0 -5
  113. data/lib/booker/models/tag_price.rb +0 -5
  114. data/lib/booker/models/teacher.rb +0 -5
  115. data/lib/booker/models/teacher_2.rb +0 -5
  116. data/lib/booker/models/time_zone.rb +0 -8
  117. data/lib/booker/models/treatment.rb +0 -19
  118. data/lib/booker/models/treatment_time_slot.rb +0 -5
  119. data/lib/booker/models/type.rb +0 -8
  120. data/lib/booker/models/user.rb +0 -73
@@ -0,0 +1,55 @@
1
+ module Booker
2
+ module V41
3
+ class Merchant < Client
4
+ include Booker::V4::RequestHelper
5
+
6
+ API_METHODS = {
7
+ appointments: '/v4.1/merchant/appointments'.freeze,
8
+ customers: '/v4.1/merchant/customers'.freeze,
9
+ create_special: '/v4.1/merchant/special'.freeze
10
+ }.freeze
11
+
12
+ def appointments(location_id:, start_date:, end_date:, fetch_all: true, options: {})
13
+ additional_params = {
14
+ LocationID: location_id,
15
+ FromStartDate: start_date.to_date,
16
+ ToStartDate: end_date.to_date
17
+ }
18
+
19
+ paginated_request(
20
+ method: :post,
21
+ path: API_METHODS[:appointments],
22
+ params: build_params(additional_params, options, true),
23
+ model: Booker::V4::Models::Appointment,
24
+ fetch_all: fetch_all
25
+ )
26
+ end
27
+
28
+ def customers(location_id:, fetch_all: true, options: {})
29
+ additional_params = {
30
+ FilterByExactLocationID: true,
31
+ LocationID: location_id,
32
+ CustomerRecordType: 1,
33
+ }
34
+
35
+ paginated_request(
36
+ method: :post,
37
+ path: API_METHODS[:customers],
38
+ params: build_params(additional_params, options, true),
39
+ model: Booker::V4::Models::Customer,
40
+ fetch_all: fetch_all
41
+ )
42
+ end
43
+
44
+ def create_special(location_id:, start_date:, end_date:, coupon_code:, name:, options: {})
45
+ post(API_METHODS[:create_special], build_params({
46
+ LocationID: location_id,
47
+ ApplicableStartDate: start_date.in_time_zone,
48
+ ApplicableEndDate: end_date.in_time_zone,
49
+ CouponCode: coupon_code,
50
+ Name: name
51
+ }, options))
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,9 @@
1
+ module Booker
2
+ module V4
3
+ class BusinessClient < Booker::Client
4
+ include Booker::V4::BusinessREST
5
+ ENV_BASE_URL_KEY = 'BOOKER_BUSINESS_SERVICE_URL'.freeze
6
+ DEFAULT_BASE_URL = 'https://apicurrent-app.booker.ninja/webservice4/json/BusinessService.svc'.freeze
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,88 @@
1
+ module Booker
2
+ module V4
3
+ module BusinessREST
4
+ include Booker::V4::CommonREST
5
+
6
+ def get_logged_in_user
7
+ response = get('/user', build_params)
8
+ result = Booker::V4::Models::User.from_hash(response['User'])
9
+ result.LocationID = response['LocationID']
10
+ result.BrandID = response['BrandID']
11
+ result
12
+ end
13
+
14
+ def get_location_day_schedules(booker_location_id:, params: {})
15
+ # Booker requires fromDate and toDate for JSON API, but does not use them when getDefaultDaySchedule is true
16
+ # So datetime used for these fields does not matter
17
+ random_datetime = Booker::V4::Models::Model.time_to_booker_datetime(Time.now)
18
+
19
+ additional_params = {getDefaultDaySchedule: true, fromDate: random_datetime, toDate: random_datetime}
20
+ response = get("/location/#{booker_location_id}/schedule", build_params(additional_params, params))
21
+ response['LocationDaySchedules'].map { |sched| Booker::V4::Models::LocationDaySchedule.from_hash(sched) }
22
+ end
23
+
24
+ def find_locations(options: {})
25
+ paginated_request(
26
+ method: :post,
27
+ path: '/locations',
28
+ params: build_params({}, options, true),
29
+ model: Booker::V4::Models::Location
30
+ )
31
+ end
32
+
33
+ def find_employees(booker_location_id:, fetch_all: true, options: {})
34
+ paginated_request(
35
+ method: :post,
36
+ path: '/employees',
37
+ params: build_params({LocationID: booker_location_id}, options, true),
38
+ model: Booker::V4::Models::Employee,
39
+ fetch_all: fetch_all
40
+ )
41
+ end
42
+
43
+ def find_treatments(booker_location_id:, fetch_all: true, options: {})
44
+ paginated_request(
45
+ method: :post,
46
+ path: '/treatments',
47
+ params: build_params({LocationID: booker_location_id}, options, true),
48
+ model: Booker::V4::Models::Treatment,
49
+ fetch_all: fetch_all
50
+ )
51
+ end
52
+
53
+ def find_appointments_partial(booker_location_id:, start_date:, end_date:, fetch_all: true, options: {})
54
+ additional_params = {
55
+ LocationID: booker_location_id,
56
+ FromStartDate: start_date.to_date,
57
+ ToStartDate: end_date.to_date
58
+ }
59
+
60
+ paginated_request(
61
+ method: :post,
62
+ path: '/appointments/partial',
63
+ params: build_params(additional_params, options, true),
64
+ model: Booker::V4::Models::Appointment,
65
+ fetch_all: fetch_all
66
+ )
67
+ end
68
+
69
+ def get_location_notification_settings(booker_location_id:)
70
+ response = get "/location/#{booker_location_id}/notification_settings", build_params
71
+ Booker::V4::Models::NotificationSettings.from_hash response['NotificationSettings']
72
+ end
73
+
74
+ def update_location_notification_settings(booker_location_id:, send_appointment_reminders:)
75
+ put "/location/#{booker_location_id}/notification_settings", build_params({
76
+ NotificationSettings: {
77
+ SendAppointmentReminders: send_appointment_reminders
78
+ }
79
+ })
80
+ end
81
+
82
+ def get_location_feature_settings(booker_location_id:)
83
+ response = get "/location/#{booker_location_id}/feature_settings", build_params
84
+ Booker::V4::Models::FeatureSettings.from_hash response['FeatureSettings']
85
+ end
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,21 @@
1
+ module Booker
2
+ module V4
3
+ module CommonREST
4
+ include Booker::V4::RequestHelper
5
+
6
+ def get_online_booking_settings(booker_location_id:)
7
+ response = get("/location/#{booker_location_id}/online_booking_settings", build_params)
8
+ Booker::V4::Models::OnlineBookingSettings.from_hash(response['OnlineBookingSettings'])
9
+ end
10
+
11
+ def confirm_appointment(appointment_id:)
12
+ put '/appointment/confirm', build_params(:ID => appointment_id), Booker::V4::Models::Appointment
13
+ end
14
+
15
+ def get_location(booker_location_id:)
16
+ response = get("/location/#{booker_location_id}", build_params)
17
+ Booker::V4::Models::Location.from_hash(response)
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,15 @@
1
+ module Booker
2
+ module V4
3
+ class CustomerClient < Client
4
+ include Booker::V4::CustomerREST
5
+ ENV_BASE_URL_KEY = 'BOOKER_CUSTOMER_SERVICE_URL'.freeze
6
+ DEFAULT_BASE_URL = 'https://apicurrent-app.booker.ninja/webservice4/json/CustomerService.svc'.freeze
7
+
8
+ def initialize(options={})
9
+ super
10
+ self.token_store ||= GenericTokenStore
11
+ self.token_store_callback_method ||= :update_booker_access_token!
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ module Booker
2
+ module V4
3
+ module CustomerREST
4
+ include Booker::V4::CommonREST
5
+
6
+ def create_class_appointment(booker_location_id:, class_instance_id:, customer:, options: {})
7
+ post '/class_appointment/create', build_params({
8
+ LocationID: booker_location_id,
9
+ ClassInstanceID: class_instance_id,
10
+ Customer: customer
11
+ }, options), Booker::V4::Models::Appointment
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,14 @@
1
+ module Booker
2
+ module V4
3
+ module Models
4
+ class Address < Model
5
+ attr_accessor 'Street1',
6
+ 'Street2',
7
+ 'City',
8
+ 'State',
9
+ 'Zip',
10
+ 'Country'
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,79 @@
1
+ module Booker
2
+ module V4
3
+ module Models
4
+ class Appointment < Model
5
+ attr_accessor 'BookingNumber',
6
+ 'Confirmable',
7
+ 'EndDateTime',
8
+ 'FinalTotal',
9
+ 'ID',
10
+ 'IsCancelled',
11
+ 'IsNoShow',
12
+ 'LocationID',
13
+ 'StartDateTime',
14
+ 'Status',
15
+ 'CanTakePayment',
16
+ 'DateCreated',
17
+ 'BelongsToEnrollment',
18
+ 'Address',
19
+ 'AddressID',
20
+ 'AllowAutoPay',
21
+ 'AppointmentTreatments',
22
+ 'BelongsToGroup',
23
+ 'BelongsToGroupAndGroupOrder',
24
+ 'BelongsToOrder',
25
+ 'CanCancel',
26
+ 'CanCheckin',
27
+ 'CanHaveCustomer2',
28
+ 'CanRevertNoShow',
29
+ 'CanUndoCheckin',
30
+ 'CancellationID',
31
+ 'Customer',
32
+ 'Customer2',
33
+ 'Customer2ID',
34
+ 'CustomerID',
35
+ 'CustomerLastName',
36
+ 'CustomerMobilePhone',
37
+ 'CustomerWorkPhone',
38
+ 'DateBooked',
39
+ 'DateNoShow',
40
+ 'Employee',
41
+ 'EmployeeFirstName',
42
+ 'EmployeeLastName',
43
+ 'GroupID',
44
+ 'GroupName',
45
+ 'GroupNumber',
46
+ 'GroupTypeID',
47
+ 'IsCancelledOrNoShow',
48
+ 'IsCheckedInInService',
49
+ 'IsPartOfClassPackageBooking',
50
+ 'IsPreBookedAtPastCheckout',
51
+ 'IsRecurring',
52
+ 'IsWebBooking',
53
+ 'Notes',
54
+ 'OrderID',
55
+ 'OrderStatusID',
56
+ 'PackageID',
57
+ 'PaymentID',
58
+ 'PaymentItemID',
59
+ 'PrimaryAppointmentTreatmentID',
60
+ 'RecurrenceID',
61
+ 'Room',
62
+ 'Source',
63
+ 'Treatment',
64
+ 'TreatmentName',
65
+ 'Type',
66
+ 'IsHeld',
67
+ 'HoldForMinutes',
68
+ 'HeldSince',
69
+ 'IsServiceComplete',
70
+ 'IsCheckout',
71
+ 'DateCheckIn',
72
+ 'IsFromWaitList',
73
+ 'IsFromClassWaitList',
74
+ 'CustomerRecordTypeID',
75
+ 'CustomerParentID'
76
+ end
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,53 @@
1
+ module Booker
2
+ module V4
3
+ module Models
4
+ class AppointmentTreatment < Model
5
+ attr_accessor 'AppointmentID',
6
+ 'DynamicPrice',
7
+ 'EndDateTime',
8
+ 'ID',
9
+ 'StartDateTime',
10
+ 'ChildID',
11
+ 'ChildName',
12
+ 'AllowChangeStartTime',
13
+ 'DynamicPriceID',
14
+ 'Employee',
15
+ 'Employee2FullName',
16
+ 'Employee2ID',
17
+ 'EmployeeFirstName',
18
+ 'EmployeeFullName',
19
+ 'EmployeeID',
20
+ 'EmployeeLastName',
21
+ 'EmployeeRecoveryDuration',
22
+ 'EmployeeTypeID',
23
+ 'EmployeeWasRequested',
24
+ 'FinishStartDateTime',
25
+ 'FinishTimeAppliedToEmployee',
26
+ 'FinishTimeAppliedToRoom',
27
+ 'FinishTimeDuration',
28
+ 'FinishTimeOriginalDuration',
29
+ 'ProcessingStartDateTime',
30
+ 'ProcessingTimeAppliedToRoom',
31
+ 'ProcessingTimeAppliedToEmployee',
32
+ 'ProcessingTimeDuration',
33
+ 'ProcessingTimeOriginalDuration',
34
+ 'RequiresProcessingTime',
35
+ 'Room',
36
+ 'RoomID',
37
+ 'RoomName',
38
+ 'RoomRecoveryDuration',
39
+ 'StartTimeDuration',
40
+ 'StartTimeOriginalDuration',
41
+ 'TagPrice',
42
+ 'Treatment',
43
+ 'TreatmentDuration',
44
+ 'TreatmentID',
45
+ 'TreatmentIsForCouples',
46
+ 'TreatmentName',
47
+ 'ClassInstanceID',
48
+ 'IsDurationOverridden'
49
+ end
50
+ end
51
+ end
52
+ end
53
+
@@ -0,0 +1,15 @@
1
+ module Booker
2
+ module V4
3
+ module Models
4
+ class AvailableTime < Model
5
+ attr_accessor 'CurrentPrice',
6
+ 'Duration',
7
+ 'EmployeeID',
8
+ 'StartDateTime',
9
+ 'TreatmentID',
10
+ 'RoomID',
11
+ 'Employee2ID'
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,7 @@
1
+ module Booker
2
+ module V4
3
+ module Models
4
+ class BusinessType < Type; end
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module Booker
2
+ module V4
3
+ module Models
4
+ class Category < Type; end
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,27 @@
1
+ module Booker
2
+ module V4
3
+ module Models
4
+ class ClassInstance < Model
5
+ attr_accessor 'ID',
6
+ 'EndDateTime',
7
+ 'HasClassFilled',
8
+ 'IsForMembersOnly',
9
+ 'IsRecurring',
10
+ 'IsSpecialEvent',
11
+ 'IsWorkshop',
12
+ 'NumReserved',
13
+ 'Price',
14
+ 'RoomName',
15
+ 'StartDateTime',
16
+ 'Teacher',
17
+ 'Teacher2',
18
+ 'TotalCapacity',
19
+ 'TreatmentDuration',
20
+ 'ListAsSubstitute',
21
+ 'IsEnrollable',
22
+ 'SeriesID',
23
+ 'Treatment'
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,21 @@
1
+ module Booker
2
+ module V4
3
+ module Models
4
+ class Country < Type
5
+ # ISO 3166-1 alpha-2 Codes
6
+ IDS_TO_ISO_CODES = YAML::load_file(File.join(__dir__, '..', '..', 'config', 'booker_country_ids_to_iso_codes.yml')).freeze
7
+
8
+ def country_code; IDS_TO_ISO_CODES[self.ID]; end
9
+
10
+ def self.from_country_code(code)
11
+ country = self.new ID: IDS_TO_ISO_CODES.detect{|k, v| v == code}.try(:[], 0)
12
+ if country.ID.nil?
13
+ raise ArgumentError, 'Country code not recognized'
14
+ else
15
+ country
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end