booker_ruby 3.3.5 → 3.3.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fe34d270528f43c6e9f7042e52acacd647ed41c03f128cb4ab006886bc48517e
4
- data.tar.gz: f24db743158b86adf93196b95477046afc6fe8d3e91bf16ebe2428dfb4d8660c
3
+ metadata.gz: 2c591cf33e4fcc339c3c5669f087b08f201af8ed51c5fa6720904a8e333306a7
4
+ data.tar.gz: 792f3c94f166f069a13738552171faf32e1227ed5e48a0da7d59e6f3b9d3f652
5
5
  SHA512:
6
- metadata.gz: f55fe8d9cc783ae561add8bf19c75dffb6f1d8401bef31e530c81f9dd8299f036281fc27256bc15c48620434512b17470ebf2667ab606a470663b83a5161fe31
7
- data.tar.gz: addafb0b13725dc1876f58b4233dca0095883e42d1b22c1bb816aa5e9208cf03fac70e49f0f10506056fb83f6597d32970924358e68ca54ea6fa89c152f652ea
6
+ metadata.gz: 7d02cde048331d194864cecbe0b04a3eb0231fc9a13b688727322e8db17e26d96dfa7bf6068fb2968b5affb7bec4112d2145665e089ca8b5eff746b3f810a967
7
+ data.tar.gz: 96973ce4f0f119092bf48dd1f19831f41538e41c4f6e28459f1c26ad034d3f6605b2de7627f825430fab59532031d9192e0c0a90435f8119492a24b3691b22a4
@@ -1,5 +1,7 @@
1
1
  module Booker
2
2
  class Client
3
+ include Booker::RequestHelper
4
+
3
5
  attr_accessor :base_url, :auth_base_url, :client_id, :client_secret, :temp_access_token,
4
6
  :temp_access_token_expires_at, :token_store, :token_store_callback_method, :api_subscription_key,
5
7
  :access_token_scope, :refresh_token, :location_id, :auth_with_client_credentials
@@ -70,6 +72,12 @@ module Booker
70
72
  build_resources(booker_resources, booker_model)
71
73
  end
72
74
 
75
+ def patch(path, data, booker_model=nil)
76
+ booker_resources = get_booker_resources(:patch, path, nil, data.to_json, booker_model)
77
+
78
+ build_resources(booker_resources, booker_model)
79
+ end
80
+
73
81
  def delete(path, params=nil, body=nil, booker_model=nil)
74
82
  booker_resources = get_booker_resources(:delete, path, params, body.to_json, booker_model)
75
83
 
@@ -0,0 +1,74 @@
1
+ module Booker
2
+ module Concerns
3
+ module DateTimeConcern
4
+ # Booker's API hands you back all time as if the business is in server time.
5
+ # First load the time in server time, then return the same hours and minutes in current time zone.
6
+ def time_from_booker_datetime(booker_datetime)
7
+ timestamp = booker_datetime[/\/Date\((.\d+)[\-\+]/, 1].to_i / 1000.to_f
8
+
9
+ original_tz = Time.zone
10
+ begin
11
+ # Booker's server is always EST
12
+ Time.zone = Booker::Client::BOOKER_SERVER_TIMEZONE
13
+
14
+ booker_time = Time.zone.at(timestamp)
15
+ ensure
16
+ Time.zone = original_tz
17
+ end
18
+
19
+ # Convert it back to location time without changing hours and minutes
20
+ Time.zone.parse(booker_time.strftime('%Y-%m-%d %H:%M:%S'))
21
+ end
22
+
23
+ # Booker's API requires times to be sent in as if the business is in Eastern Time!
24
+ def time_to_booker_datetime(time)
25
+ original_tz = Time.zone
26
+
27
+ begin
28
+ # Booker's server is always EST
29
+ Time.zone = Booker::Client::BOOKER_SERVER_TIMEZONE
30
+ timestamp = (Time.zone.parse(time.strftime("%Y-%m-%dT%H:%M:%S")).to_f * 1000).to_i
31
+ ensure
32
+ Time.zone = original_tz
33
+ end
34
+
35
+ "/Date(#{timestamp})/"
36
+ end
37
+
38
+ def timezone_from_booker_timezone(booker_timezone_name)
39
+ normalized_booker_timezone_name = Booker::Helpers::ActiveSupport.to_active_support(booker_timezone_name)
40
+ return normalized_booker_timezone_name if normalized_booker_timezone_name.present?
41
+
42
+ begin
43
+ Booker::Helpers::LoggingHelper.log_issue(
44
+ 'Unable to find time zone name using Booker::Helpers::ActiveSupport.to_active_support',
45
+ booker_timezone_name: booker_timezone_name
46
+ )
47
+ rescue
48
+ end
49
+
50
+ timezone_from_booker_offset!(booker_timezone_name)
51
+ end
52
+
53
+ def timezone_from_booker_offset!(booker_timezone_name)
54
+ booker_offset_match = booker_timezone_name.scan(/(\A)(.*)(?=\))/).first
55
+
56
+ if booker_offset_match.present?
57
+ booker_offset = booker_offset_match.delete_if { |match| match.blank? }.first
58
+
59
+ if booker_offset
60
+ booker_timezone_map_key = Booker::Helpers::ActiveSupport.booker_timezone_names.find do |key|
61
+ key.start_with?(booker_offset)
62
+ end
63
+
64
+ return Booker::Helpers::ActiveSupport.to_active_support(booker_timezone_map_key) if booker_timezone_map_key
65
+ end
66
+ end
67
+
68
+ raise Booker::Error
69
+ end
70
+
71
+ def to_wday(booker_wday); Date.parse(booker_wday).wday; end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,29 @@
1
+ module Booker
2
+ module RequestHelper
3
+ DEFAULT_PAGINATION_PARAMS = {
4
+ UsePaging: true,
5
+ PageSize: Integer(ENV['BOOKER_DEFAULT_PAGE_SIZE'] || 10),
6
+ PageNumber: 1
7
+ }
8
+
9
+ def build_params(default_params={}, overrides={}, paginated=false)
10
+ default_params.symbolize_keys!
11
+ overrides.symbolize_keys!
12
+ merged = {access_token: access_token}.merge(default_params.merge(overrides))
13
+
14
+ merged.each do |k, v|
15
+ if v.is_a?(Time) || v.is_a?(DateTime)
16
+ merged[k] = Booker::V4::Models::Model.time_to_booker_datetime(v)
17
+ elsif v.is_a?(Date)
18
+ merged[k] = Booker::V4::Models::Model.time_to_booker_datetime(v.in_time_zone)
19
+ end
20
+ end
21
+
22
+ if paginated
23
+ DEFAULT_PAGINATION_PARAMS.merge(merged)
24
+ else
25
+ merged
26
+ end
27
+ end
28
+ end
29
+ end
@@ -1,7 +1,7 @@
1
1
  module Booker
2
2
  module V41
3
3
  class Customer < Booker::Client
4
- include Booker::V4::RequestHelper
4
+ include ::Booker::RequestHelper
5
5
 
6
6
  V41_PREFIX = '/v4.1/customer'
7
7
  V41_APPOINTMENTS_PREFIX = "#{V41_PREFIX}/appointment"
@@ -1,7 +1,7 @@
1
1
  module Booker
2
2
  module V41
3
3
  class Merchant < Booker::Client
4
- include Booker::V4::RequestHelper
4
+ include ::Booker::RequestHelper
5
5
 
6
6
  V41_PREFIX = '/v4.1/merchant'
7
7
  V41_LOCATION_PREFIX = "#{V41_PREFIX}/location"
@@ -2,6 +2,7 @@ module Booker
2
2
  module V4
3
3
  module BusinessREST
4
4
  include Booker::V4::CommonREST
5
+ include ::Booker::RequestHelper
5
6
 
6
7
  def get_logged_in_user
7
8
  response = get('/user', build_params)
@@ -1,7 +1,7 @@
1
1
  module Booker
2
2
  module V4
3
3
  module CommonREST
4
- include Booker::V4::RequestHelper
4
+ include ::Booker::RequestHelper
5
5
 
6
6
  def get_online_booking_settings(booker_location_id:)
7
7
  response = get("/location/#{booker_location_id}/online_booking_settings", build_params)
@@ -2,76 +2,10 @@ module Booker
2
2
  module V4
3
3
  module Models
4
4
  class Model < Booker::Model
5
- CONSTANTIZE_MODULE = Booker::V4::Models
6
-
7
- # Booker's API hands you back all time as if the business is in server time.
8
- # First load the time in server time, then return the same hours and minutes in current time zone.
9
- def self.time_from_booker_datetime(booker_datetime)
10
- timestamp = booker_datetime[/\/Date\((.\d+)[\-\+]/, 1].to_i / 1000.to_f
11
-
12
- original_tz = Time.zone
13
- begin
14
- # Booker's server is always EST
15
- Time.zone = Booker::Client::BOOKER_SERVER_TIMEZONE
16
-
17
- booker_time = Time.zone.at(timestamp)
18
- ensure
19
- Time.zone = original_tz
20
- end
21
-
22
- # Convert it back to location time without changing hours and minutes
23
- Time.zone.parse(booker_time.strftime('%Y-%m-%d %H:%M:%S'))
24
- end
25
-
26
- # Booker's API requires times to be sent in as if the business is in Eastern Time!
27
- def self.time_to_booker_datetime(time)
28
- original_tz = Time.zone
29
-
30
- begin
31
- # Booker's server is always EST
32
- Time.zone = Booker::Client::BOOKER_SERVER_TIMEZONE
33
- timestamp = (Time.zone.parse(time.strftime("%Y-%m-%dT%H:%M:%S")).to_f * 1000).to_i
34
- ensure
35
- Time.zone = original_tz
36
- end
37
-
38
- "/Date(#{timestamp})/"
39
- end
5
+ extend ::Booker::Concerns::DateTimeConcern
40
6
 
41
- def self.timezone_from_booker_timezone(booker_timezone_name)
42
- normalized_booker_timezone_name = Booker::Helpers::ActiveSupport.to_active_support(booker_timezone_name)
43
- return normalized_booker_timezone_name if normalized_booker_timezone_name.present?
44
-
45
- begin
46
- Booker::Helpers::LoggingHelper.log_issue(
47
- 'Unable to find time zone name using Booker::Helpers::ActiveSupport.to_active_support',
48
- booker_timezone_name: booker_timezone_name
49
- )
50
- rescue
51
- end
52
-
53
- timezone_from_booker_offset!(booker_timezone_name)
54
- end
55
-
56
- def self.timezone_from_booker_offset!(booker_timezone_name)
57
- booker_offset_match = booker_timezone_name.scan(/(\A)(.*)(?=\))/).first
58
-
59
- if booker_offset_match.present?
60
- booker_offset = booker_offset_match.delete_if { |match| match.blank? }.first
61
-
62
- if booker_offset
63
- booker_timezone_map_key = Booker::Helpers::ActiveSupport.booker_timezone_names.find do |key|
64
- key.start_with?(booker_offset)
65
- end
66
-
67
- return Booker::Helpers::ActiveSupport.to_active_support(booker_timezone_map_key) if booker_timezone_map_key
68
- end
69
- end
70
-
71
- raise Booker::Error
72
- end
7
+ CONSTANTIZE_MODULE = Booker::V4::Models
73
8
 
74
- def self.to_wday(booker_wday); Date.parse(booker_wday).wday; end
75
9
  end
76
10
  end
77
11
  end
@@ -1,33 +1,7 @@
1
1
  module Booker
2
2
  module V4
3
3
  module RequestHelper
4
- DEFAULT_PAGINATION_PARAMS = {
5
- UsePaging: true,
6
- PageSize: Integer(ENV['BOOKER_DEFAULT_PAGE_SIZE'] || 10),
7
- PageNumber: 1
8
- }
9
-
10
- private
11
-
12
- def build_params(default_params={}, overrides={}, paginated=false)
13
- default_params.symbolize_keys!
14
- overrides.symbolize_keys!
15
- merged = {access_token: access_token}.merge(default_params.merge(overrides))
16
-
17
- merged.each do |k, v|
18
- if v.is_a?(Time) || v.is_a?(DateTime)
19
- merged[k] = Booker::V4::Models::Model.time_to_booker_datetime(v)
20
- elsif v.is_a?(Date)
21
- merged[k] = Booker::V4::Models::Model.time_to_booker_datetime(v.in_time_zone)
22
- end
23
- end
24
-
25
- if paginated
26
- DEFAULT_PAGINATION_PARAMS.merge(merged)
27
- else
28
- merged
29
- end
30
- end
4
+
31
5
  end
32
6
  end
33
7
  end
@@ -1,6 +1,8 @@
1
1
  module Booker
2
2
  module V5
3
3
  class Availability < Booker::Client
4
+ include ::Booker::RequestHelper
5
+
4
6
  API_METHODS = {
5
7
  availability: '/v5/availability/availability'.freeze,
6
8
  two_day_availability: '/v5/availability/2day'.freeze,
@@ -1,3 +1,3 @@
1
1
  module Booker
2
- VERSION = '3.3.5'
2
+ VERSION = '3.3.6'
3
3
  end
@@ -16,6 +16,10 @@ require 'booker/booker'
16
16
  # Errors
17
17
  require 'booker/errors'
18
18
 
19
+ # Concerns
20
+ require 'booker/concerns/date_time_concern'
21
+ require 'booker/request_helper'
22
+
19
23
  # Models
20
24
  require 'booker/model'
21
25
 
@@ -23,6 +27,7 @@ require 'booker/model'
23
27
  require 'booker/v4/models/model'
24
28
 
25
29
  # Types
30
+ require 'booker/v4/request_helper'
26
31
  require 'booker/v4/models/type'
27
32
  require 'booker/v4/models/country'
28
33
  require 'booker/v4/models/status'
@@ -95,7 +100,6 @@ require 'booker/v5/models/availability_result'
95
100
  require 'booker/client'
96
101
 
97
102
  # V4 Rest
98
- require 'booker/v4/request_helper'
99
103
  require 'booker/v4/common_rest'
100
104
  require 'booker/v4/business_rest'
101
105
  require 'booker/v4/customer_rest'
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: 3.3.5
4
+ version: 3.3.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Frederick
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-02-07 00:00:00.000000000 Z
11
+ date: 2019-03-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -145,12 +145,14 @@ extra_rdoc_files: []
145
145
  files:
146
146
  - lib/booker/booker.rb
147
147
  - lib/booker/client.rb
148
+ - lib/booker/concerns/date_time_concern.rb
148
149
  - lib/booker/config/booker_country_ids_to_iso_codes.yml
149
150
  - lib/booker/errors.rb
150
151
  - lib/booker/generic_token_store.rb
151
152
  - lib/booker/helpers/active_support_helper.rb
152
153
  - lib/booker/helpers/logging_helper.rb
153
154
  - lib/booker/model.rb
155
+ - lib/booker/request_helper.rb
154
156
  - lib/booker/v4.1/customer.rb
155
157
  - lib/booker/v4.1/merchant.rb
156
158
  - lib/booker/v4/business_client.rb