booker_ruby 1.3.0 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/booker/business_rest.rb +10 -0
- data/lib/booker/client.rb +0 -6
- data/lib/booker/helpers/active_support_helper.rb +102 -0
- data/lib/booker/helpers/logging_helper.rb +11 -0
- data/lib/booker/models/location_day_schedule.rb +18 -0
- data/lib/booker/models/model.rb +38 -11
- data/lib/booker/version.rb +1 -1
- data/lib/booker_ruby.rb +5 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c32d18a501108616082cfd6f1c4d9a9bb77c4acf
|
4
|
+
data.tar.gz: 1b518f4e5395d7a9221d34e36cb23c2cdcf42db5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5c8fe78924f6479548746e2b428b97beed68012a8f4baebd628c382dc1738d31a1294cfc63ad46a881967ca8487cdf52e38aa8b0e48ce4ff1fa8a356e8b11860
|
7
|
+
data.tar.gz: c3882ef8de57340214414ccdc1dd19605ea73c94ec1ba6e666fde98f4f910f1b1e9115e50c00a2bede580d692ff26c0ab6c9b6cfd66217e4d5ced3adbbf9c9be
|
data/lib/booker/business_rest.rb
CHANGED
@@ -15,6 +15,16 @@ module Booker
|
|
15
15
|
Booker::Models::Location.from_hash(response)
|
16
16
|
end
|
17
17
|
|
18
|
+
def get_location_day_schedules(booker_location_id:, params: {})
|
19
|
+
# Booker requires fromDate and toDate for JSON API, but does not use them when getDefaultDaySchedule is true
|
20
|
+
# So datetime used for these fields does not matter
|
21
|
+
random_datetime = Booker::Models::Model.time_to_booker_datetime(Time.now)
|
22
|
+
|
23
|
+
additional_params = {'getDefaultDaySchedule' => true, 'fromDate' => random_datetime, 'toDate' => random_datetime}
|
24
|
+
response = get("/location/#{booker_location_id}/schedule", build_params(additional_params, params))
|
25
|
+
response['LocationDaySchedules'].map { |sched| Booker::Models::LocationDaySchedule.from_hash(sched) }
|
26
|
+
end
|
27
|
+
|
18
28
|
def find_locations(params: {})
|
19
29
|
paginated_request(
|
20
30
|
method: :post,
|
data/lib/booker/client.rb
CHANGED
@@ -65,12 +65,6 @@ module Booker
|
|
65
65
|
end
|
66
66
|
end
|
67
67
|
|
68
|
-
def log_issue(message, extra_info = {})
|
69
|
-
if (log_message_block = Booker.config[:log_message])
|
70
|
-
log_message_block.call(message, extra_info)
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
68
|
def get_booker_resources(http_method, path, params=nil, body=nil, booker_model=nil)
|
75
69
|
http_options = request_options(params, body)
|
76
70
|
puts "BOOKER REQUEST: #{http_method} #{path} #{http_options}" if ENV['BOOKER_API_DEBUG'] == 'true'
|
@@ -0,0 +1,102 @@
|
|
1
|
+
module Booker
|
2
|
+
module Helpers
|
3
|
+
module ActiveSupport
|
4
|
+
BOOKER_TO_ACTIVE_SUPPORT_TIMEZONE = {
|
5
|
+
'(GMT-12:00) International Date Line West' => 'International Date Line West',
|
6
|
+
'(GMT-11:00) Midway Island, Samoa' => 'Samoa',
|
7
|
+
'(GMT-10:00) Hawaii' => 'Hawaii',
|
8
|
+
'(GMT-09:00) Alaska' => 'Alaska',
|
9
|
+
'(GMT-08:00) Tijuana, Baja California' => 'Tijuana',
|
10
|
+
'(GMT-08:00) Pacific Time (US & Canada)' => 'Pacific Time (US & Canada)',
|
11
|
+
'(GMT-07:00) Chihuahua, La Paz, Mazatlan - New' => 'Chihuahua',
|
12
|
+
'(GMT-07:00) Arizona' => 'Arizona',
|
13
|
+
'(GMT-07:00) Mountain Time (US & Canada)' => 'Mountain Time (US & Canada)',
|
14
|
+
'(GMT-07:00) Chihuahua, La Paz, Mazatlan - Old' => 'Chihuahua',
|
15
|
+
'(GMT-06:00) Guadalajara, Mexico City, Monterrey - New' => 'Guadalajara',
|
16
|
+
'(GMT-06:00) Central Time (US & Canada)' => 'Central Time (US & Canada)',
|
17
|
+
'(GMT-06:00) Central America' => 'Central America',
|
18
|
+
'(GMT-06:00) Guadalajara, Mexico City, Monterrey - Old' => 'Guadalajara',
|
19
|
+
'(GMT-06:00) Saskatchewan' => 'Saskatchewan',
|
20
|
+
'(GMT-05:00) Bogota, Lima, Quito, Rio Branco' => 'Bogota',
|
21
|
+
'(GMT-05:00) Indiana (East)' => 'Indiana (East)',
|
22
|
+
'(GMT-05:00) Eastern Time (US & Canada)' => 'Eastern Time (US & Canada)',
|
23
|
+
'(GMT-04:00) Santiago' => 'Santiago',
|
24
|
+
'(GMT-04:00) Caracas, La Paz' => 'Caracas',
|
25
|
+
'(GMT-04:00) Atlantic Time (Canada)' => 'Atlantic Time (Canada)',
|
26
|
+
'(GMT-04:00) Manaus' => 'Atlantic Time (Canada)',
|
27
|
+
'(GMT-03:30) Newfoundland' => 'Newfoundland',
|
28
|
+
'(GMT-03:00) Brasilia' => 'Brasilia',
|
29
|
+
'(GMT-03:00) Greenland' => 'Greenland',
|
30
|
+
'(GMT-03:00) Montevideo' => 'Montevideo',
|
31
|
+
'(GMT-03:00) Buenos Aires, Georgetown' => 'Buenos Aires',
|
32
|
+
'(GMT-02:00) Mid-Atlantic' => 'Mid-Atlantic',
|
33
|
+
'(GMT-01:00) Cape Verde Is.' => 'Cape Verde Is.',
|
34
|
+
'(GMT-01:00) Azores' => 'Azores',
|
35
|
+
'(GMT) Casablanca, Monrovia, Reykjavik' => 'Casablanca',
|
36
|
+
'(GMT) Greenwich Mean Time : Dublin, Edinburgh, Lisbon, London' => 'Dublin',
|
37
|
+
'(GMT+01:00) West Central Africa' => 'West Central Africa',
|
38
|
+
'(GMT+01:00) Sarajevo, Skopje, Warsaw, Zagreb' => 'Sarajevo',
|
39
|
+
'(GMT+01:00) Amsterdam, Berlin, Bern, Rome, Stockholm, Vienna' => 'Amsterdam',
|
40
|
+
'(GMT+01:00) Brussels, Copenhagen, Madrid, Paris' => 'Brussels',
|
41
|
+
'(GMT+01:00) Belgrade, Bratislava, Budapest, Ljubljana, Prague' => 'Belgrade',
|
42
|
+
'(GMT+02:00) Windhoek' => 'Harare',
|
43
|
+
'(GMT+02:00) Jerusalem' => 'Jerusalem',
|
44
|
+
'(GMT+02:00) Amman' => 'Jerusalem',
|
45
|
+
'(GMT+02:00) Beirut' => 'Jerusalem',
|
46
|
+
'(GMT+02:00) Harare, Pretoria' => 'Harare',
|
47
|
+
'(GMT+02:00) Helsinki, Kyiv, Riga, Sofia, Tallinn, Vilnius' => 'Helsinki',
|
48
|
+
'(GMT+02:00) Cairo' => 'Cairo',
|
49
|
+
'(GMT+02:00) Minsk' => 'Minsk',
|
50
|
+
'(GMT+02:00) Athens, Bucharest, Istanbul' => 'Athens',
|
51
|
+
'(GMT+03:00) Moscow, St. Petersburg, Volgograd' => 'Moscow',
|
52
|
+
'(GMT+03:00) Nairobi' => 'Nairobi',
|
53
|
+
'(GMT+03:00) Kuwait, Riyadh' => 'Kuwait',
|
54
|
+
'(GMT+03:00) Tbilisi' => 'Tbilisi',
|
55
|
+
'(GMT+03:00) Baghdad' => 'Baghdad',
|
56
|
+
'(GMT+03:30) Tehran' => 'Tehran',
|
57
|
+
'(GMT+04:00) Caucasus Standard Time' => 'Yerevan',
|
58
|
+
'(GMT+04:00) Yerevan' => 'Yerevan',
|
59
|
+
'(GMT+04:00) Abu Dhabi, Muscat' => 'Abu Dhabi',
|
60
|
+
'(GMT+04:00) Baku' => 'Baku',
|
61
|
+
'(GMT+04:30) Kabul' => 'Kabul',
|
62
|
+
'(GMT+05:00) Ekaterinburg' => 'Ekaterinburg',
|
63
|
+
'(GMT+05:00) Islamabad, Karachi, Tashkent' => 'Islamabad',
|
64
|
+
'(GMT+05:30) Sri Jayawardenepura' => 'Sri Jayawardenepura',
|
65
|
+
'(GMT+05:30) Chennai, Kolkata, Mumbai, New Delhi' => 'Chennai',
|
66
|
+
'(GMT+05:45) Kathmandu' => 'Kathmandu',
|
67
|
+
'(GMT+06:00) Almaty, Novosibirsk' => 'Almaty',
|
68
|
+
'(GMT+06:00) Astana, Dhaka' => 'Astana',
|
69
|
+
'(GMT+06:30) Yangon (Rangoon)' => 'Rangoon',
|
70
|
+
'(GMT+07:00) Bangkok, Hanoi, Jakarta' => 'Bangkok',
|
71
|
+
'(GMT+07:00) Krasnoyarsk' => 'Krasnoyarsk',
|
72
|
+
'(GMT+08:00) Taipei' => 'Taipei',
|
73
|
+
'(GMT+08:00) Kuala Lumpur, Singapore' => 'Kuala',
|
74
|
+
'(GMT+08:00) Irkutsk, Ulaan Bataar' => 'Irkutsk',
|
75
|
+
'(GMT+08:00) Beijing, Chongqing, Hong Kong, Urumqi' => 'Beijing',
|
76
|
+
'(GMT+08:00) Perth' => 'Perth',
|
77
|
+
'(GMT+09:00) Osaka, Sapporo, Tokyo' => 'Osaka',
|
78
|
+
'(GMT+09:00) Seoul' => 'Seoul',
|
79
|
+
'(GMT+09:00) Yakutsk' => 'Yakutsk',
|
80
|
+
'(GMT+09:30) Darwin' => 'Darwin',
|
81
|
+
'(GMT+09:30) Adelaide' => 'Adelaide',
|
82
|
+
'(GMT+10:00) Hobart' => 'Hobart',
|
83
|
+
'(GMT+10:00) Brisbane' => 'Brisbane',
|
84
|
+
'(GMT+10:00) Vladivostok' => 'Vladivostok',
|
85
|
+
'(GMT+10:00) Guam, Port Moresby' => 'Guam',
|
86
|
+
'(GMT+10:00) Canberra, Melbourne, Sydney' => 'Canberra',
|
87
|
+
'(GMT+11:00) Magadan, Solomon Is., New Caledonia' => 'Magadan',
|
88
|
+
'(GMT+12:00) Fiji, Kamchatka, Marshall Is.' => 'Fiji',
|
89
|
+
'(GMT+12:00) Auckland, Wellington' => 'Auckland',
|
90
|
+
"(GMT+13:00) Nuku'alofa" => "Nuku'alofa"
|
91
|
+
}.freeze
|
92
|
+
|
93
|
+
def self.to_active_support(booker_timezone_name)
|
94
|
+
BOOKER_TO_ACTIVE_SUPPORT_TIMEZONE[booker_timezone_name]
|
95
|
+
end
|
96
|
+
|
97
|
+
def self.booker_timezone_names
|
98
|
+
BOOKER_TO_ACTIVE_SUPPORT_TIMEZONE.keys
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Booker
|
2
|
+
module Models
|
3
|
+
class LocationDaySchedule < Model
|
4
|
+
attr_accessor 'Weekday',
|
5
|
+
'StartTime',
|
6
|
+
'EndTime'
|
7
|
+
|
8
|
+
def self.from_hash(hash)
|
9
|
+
model = super
|
10
|
+
model.Weekday = to_wday(model.Weekday)
|
11
|
+
strftime_format = '%T'
|
12
|
+
model.StartTime = model.StartTime.try(:strftime, strftime_format)
|
13
|
+
model.EndTime = model.EndTime.try(:strftime, strftime_format)
|
14
|
+
model
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/booker/models/model.rb
CHANGED
@@ -1,11 +1,8 @@
|
|
1
1
|
module Booker
|
2
2
|
module Models
|
3
3
|
class Model
|
4
|
-
|
5
4
|
def initialize(options = {})
|
6
|
-
options.each
|
7
|
-
send(:"#{key}=", value)
|
8
|
-
end
|
5
|
+
options.each { |key, value| send(:"#{key}=", value) }
|
9
6
|
end
|
10
7
|
|
11
8
|
def to_hash
|
@@ -29,9 +26,7 @@ module Booker
|
|
29
26
|
hash
|
30
27
|
end
|
31
28
|
|
32
|
-
def to_json
|
33
|
-
Oj.dump(to_hash, mode: :compat)
|
34
|
-
end
|
29
|
+
def to_json; Oj.dump(to_hash, mode: :compat); end
|
35
30
|
|
36
31
|
def self.from_hash(hash)
|
37
32
|
model = self.new
|
@@ -58,9 +53,7 @@ module Booker
|
|
58
53
|
model
|
59
54
|
end
|
60
55
|
|
61
|
-
def self.from_list(array)
|
62
|
-
array.map{|item| self.from_hash(item)}
|
63
|
-
end
|
56
|
+
def self.from_list(array); array.map { |item| self.from_hash(item) }; end
|
64
57
|
|
65
58
|
def self.constantize(key)
|
66
59
|
begin
|
@@ -105,8 +98,42 @@ module Booker
|
|
105
98
|
"/Date(#{timestamp})/"
|
106
99
|
end
|
107
100
|
|
108
|
-
|
101
|
+
def self.timezone_from_booker_timezone(booker_timezone_name)
|
102
|
+
normalized_booker_timezone_name = Booker::Helpers::ActiveSupport.to_active_support(booker_timezone_name)
|
103
|
+
return normalized_booker_timezone_name if normalized_booker_timezone_name.present?
|
104
|
+
|
105
|
+
begin
|
106
|
+
Booker::Helpers::LoggingHelper.log_issue(
|
107
|
+
'Unable to find time zone name using Booker::Helpers::ActiveSupport.to_active_support',
|
108
|
+
booker_timezone_name: booker_timezone_name
|
109
|
+
)
|
110
|
+
rescue
|
111
|
+
end
|
112
|
+
|
113
|
+
timezone_from_booker_offset!(booker_timezone_name)
|
114
|
+
end
|
115
|
+
|
116
|
+
def self.timezone_from_booker_offset!(booker_timezone_name)
|
117
|
+
booker_offset_match = booker_timezone_name.scan(/(\A)(.*)(?=\))/).first
|
109
118
|
|
119
|
+
if booker_offset_match.present?
|
120
|
+
booker_offset = booker_offset_match.delete_if { |match| match.blank? }.first
|
121
|
+
|
122
|
+
if booker_offset
|
123
|
+
booker_timezone_map_key = Booker::Helpers::ActiveSupport.booker_timezone_names.find do |key|
|
124
|
+
key.start_with?(booker_offset)
|
125
|
+
end
|
126
|
+
|
127
|
+
return Booker::Helpers::ActiveSupport.to_active_support(booker_timezone_map_key) if booker_timezone_map_key
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
raise Booker::Error
|
132
|
+
end
|
133
|
+
|
134
|
+
def self.to_wday(booker_wday); Date.parse(booker_wday).wday; end
|
135
|
+
|
136
|
+
private
|
110
137
|
def hash_list(array)
|
111
138
|
array.map do |item|
|
112
139
|
if item.is_a? Array
|
data/lib/booker/version.rb
CHANGED
data/lib/booker_ruby.rb
CHANGED
@@ -69,6 +69,7 @@ require 'booker/models/available_time'
|
|
69
69
|
require 'booker/models/class_instance'
|
70
70
|
require 'booker/models/online_booking_settings'
|
71
71
|
require 'booker/models/user'
|
72
|
+
require 'booker/models/location_day_schedule'
|
72
73
|
|
73
74
|
# Base Client
|
74
75
|
require 'booker/client'
|
@@ -84,3 +85,7 @@ require 'booker/generic_token_store'
|
|
84
85
|
# Client Subclasses
|
85
86
|
require 'booker/business_client'
|
86
87
|
require 'booker/customer_client'
|
88
|
+
|
89
|
+
# Helpers
|
90
|
+
require 'booker/helpers/logging_helper'
|
91
|
+
require 'booker/helpers/active_support_helper'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: booker_ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Frederick
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-02-
|
11
|
+
date: 2016-02-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -124,6 +124,8 @@ files:
|
|
124
124
|
- lib/booker/customer_rest.rb
|
125
125
|
- lib/booker/errors.rb
|
126
126
|
- lib/booker/generic_token_store.rb
|
127
|
+
- lib/booker/helpers/active_support_helper.rb
|
128
|
+
- lib/booker/helpers/logging_helper.rb
|
127
129
|
- lib/booker/models/address.rb
|
128
130
|
- lib/booker/models/appointment.rb
|
129
131
|
- lib/booker/models/appointment_treatment.rb
|
@@ -142,6 +144,7 @@ files:
|
|
142
144
|
- lib/booker/models/final_total.rb
|
143
145
|
- lib/booker/models/gender.rb
|
144
146
|
- lib/booker/models/location.rb
|
147
|
+
- lib/booker/models/location_day_schedule.rb
|
145
148
|
- lib/booker/models/model.rb
|
146
149
|
- lib/booker/models/online_booking_settings.rb
|
147
150
|
- lib/booker/models/original_price.rb
|