booker_ruby 1.0.1 → 1.0.2
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.
- checksums.yaml +4 -4
- data/lib/booker/business_client.rb +11 -21
- data/lib/booker/client.rb +37 -18
- data/lib/booker/customer_client.rb +5 -19
- data/lib/booker/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 41e10ed27065b0384388bc2534403a150f85b241
|
4
|
+
data.tar.gz: d4d0cb86460f39b8b1672b82ded24c7b46b17831
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 45ff3bbbf13e5f33c60fd33510806c90f8d4a83097b28f6f484e48f4d089b2e475b6cf064f0efac703d62c3cb2e8299e896102819257b12e9ae1410d01fba447
|
7
|
+
data.tar.gz: 4c141bb19dc240ad23c118fc7f2d4f2d7a5b063911c3615feabb9d6942f592b8c84fca3b856a959d90786d5ecd300f355347d2c63688c9cb7cdbbbad0578f2f6
|
@@ -2,31 +2,21 @@ module Booker
|
|
2
2
|
class BusinessClient < Client
|
3
3
|
include Booker::BusinessREST
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
def initialize(options={})
|
8
|
-
self.base_url = ENV['BOOKER_BUSINESS_SERVICE_URL'] || 'https://apicurrent-app.booker.ninja/webservice4/json/BusinessService.svc'
|
9
|
-
super
|
10
|
-
end
|
5
|
+
ACCESS_TOKEN_HTTP_METHOD = :post
|
6
|
+
ACCESS_TOKEN_ENDPOINT = '/accountlogin'.freeze
|
11
7
|
|
12
|
-
|
13
|
-
http_options = {
|
14
|
-
client_id: self.client_id,
|
15
|
-
client_secret: self.client_secret,
|
16
|
-
'AccountName' => self.booker_account_name,
|
17
|
-
'UserName' => self.booker_username,
|
18
|
-
'Password' => self.booker_password
|
19
|
-
}
|
20
|
-
response = post('/accountlogin', http_options, nil).parsed_response
|
21
|
-
|
22
|
-
raise Booker::InvalidApiCredentials.new(http_options, response) unless response.present?
|
8
|
+
attr_accessor :booker_account_name, :booker_username, :booker_password
|
23
9
|
|
24
|
-
|
25
|
-
self.temp_access_token = response['access_token']
|
10
|
+
def env_base_url_key; 'BOOKER_BUSINESS_SERVICE_URL'; end
|
26
11
|
|
27
|
-
|
12
|
+
def default_base_url; 'https://apicurrent-app.booker.ninja/webservice4/json/BusinessService.svc'; end
|
28
13
|
|
29
|
-
|
14
|
+
def access_token_options
|
15
|
+
super.merge!(
|
16
|
+
'AccountName' => self.booker_account_name,
|
17
|
+
'UserName' => self.booker_username,
|
18
|
+
'Password' => self.booker_password
|
19
|
+
)
|
30
20
|
end
|
31
21
|
end
|
32
22
|
end
|
data/lib/booker/client.rb
CHANGED
@@ -1,15 +1,19 @@
|
|
1
1
|
module Booker
|
2
2
|
class Client
|
3
|
-
attr_accessor :base_url, :client_id, :client_secret, :temp_access_token, :temp_access_token_expires_at,
|
3
|
+
attr_accessor :base_url, :client_id, :client_secret, :temp_access_token, :temp_access_token_expires_at,
|
4
|
+
:token_store, :token_store_callback_method
|
4
5
|
|
6
|
+
ACCESS_TOKEN_HTTP_METHOD = :get
|
7
|
+
ACCESS_TOKEN_ENDPOINT = '/access_token'.freeze
|
5
8
|
TimeZone = 'Eastern Time (US & Canada)'.freeze
|
6
9
|
|
7
10
|
def initialize(options = {})
|
8
|
-
options.each
|
9
|
-
|
10
|
-
end
|
11
|
+
options.each { |key, value| send(:"#{key}=", value) }
|
12
|
+
self.base_url ||= get_base_url
|
11
13
|
end
|
12
14
|
|
15
|
+
def get_base_url; ENV[try(:env_base_url_key).to_s] || try(:default_base_url); end
|
16
|
+
|
13
17
|
def get(path, params, booker_model=nil)
|
14
18
|
booker_resources = get_booker_resources(:get, path, params, nil, booker_model)
|
15
19
|
|
@@ -123,6 +127,33 @@ module Booker
|
|
123
127
|
end
|
124
128
|
end
|
125
129
|
|
130
|
+
def access_token_options
|
131
|
+
{
|
132
|
+
client_id: self.client_id,
|
133
|
+
client_secret: self.client_secret
|
134
|
+
}
|
135
|
+
end
|
136
|
+
|
137
|
+
def update_token_store
|
138
|
+
if self.token_store.present? && self.token_store_callback_method.present?
|
139
|
+
self.token_store.send(self.token_store_callback_method, self.temp_access_token, self.temp_access_token_expires_at)
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
def get_access_token
|
144
|
+
http_options = access_token_options
|
145
|
+
response = send(self.class::ACCESS_TOKEN_HTTP_METHOD, self.class::ACCESS_TOKEN_ENDPOINT, http_options, nil).parsed_response
|
146
|
+
|
147
|
+
raise Booker::InvalidApiCredentials.new(http_options, response) unless response.present?
|
148
|
+
|
149
|
+
self.temp_access_token_expires_at = Time.now + response['expires_in'].to_i.seconds
|
150
|
+
self.temp_access_token = response['access_token']
|
151
|
+
|
152
|
+
update_token_store
|
153
|
+
|
154
|
+
self.temp_access_token
|
155
|
+
end
|
156
|
+
|
126
157
|
private
|
127
158
|
def request_options(query=nil, body=nil)
|
128
159
|
options = {
|
@@ -132,14 +163,8 @@ module Booker
|
|
132
163
|
timeout: 120
|
133
164
|
}
|
134
165
|
|
135
|
-
if body.present?
|
136
|
-
|
137
|
-
end
|
138
|
-
|
139
|
-
if query.present?
|
140
|
-
options[:query] = query
|
141
|
-
end
|
142
|
-
|
166
|
+
options[:body] = body if body.present?
|
167
|
+
options[:query] = query if query.present?
|
143
168
|
options
|
144
169
|
end
|
145
170
|
|
@@ -159,12 +184,6 @@ module Booker
|
|
159
184
|
self.temp_access_token_expires_at.nil? || self.temp_access_token_expires_at <= Time.now
|
160
185
|
end
|
161
186
|
|
162
|
-
def update_token_store
|
163
|
-
if self.token_store && self.token_store_callback_method
|
164
|
-
token_store.send(token_store_callback_method, self.temp_access_token, self.temp_access_token_expires_at)
|
165
|
-
end
|
166
|
-
end
|
167
|
-
|
168
187
|
def results_from_response(response, booker_model=nil)
|
169
188
|
return response['Results'] unless response['Results'].nil?
|
170
189
|
|
@@ -3,29 +3,15 @@ module Booker
|
|
3
3
|
include Booker::CustomerREST
|
4
4
|
|
5
5
|
def initialize(options={})
|
6
|
-
self.base_url = ENV['BOOKER_CUSTOMER_SERVICE_URL'] || 'https://apicurrent-app.booker.ninja/webservice4/json/CustomerService.svc'
|
7
|
-
self.token_store = GenericTokenStore
|
8
|
-
self.token_store_callback_method = :update_booker_access_token!
|
9
6
|
super
|
7
|
+
self.token_store ||= GenericTokenStore
|
8
|
+
self.token_store_callback_method ||= :update_booker_access_token!
|
10
9
|
end
|
11
10
|
|
12
|
-
def
|
13
|
-
http_options = {
|
14
|
-
client_id: self.client_id,
|
15
|
-
client_secret: self.client_secret,
|
16
|
-
grant_type: 'client_credentials'
|
17
|
-
}
|
11
|
+
def env_base_url_key; 'BOOKER_CUSTOMER_SERVICE_URL'; end
|
18
12
|
|
19
|
-
|
13
|
+
def default_base_url; 'https://apicurrent-app.booker.ninja/webservice4/json/CustomerService.svc'; end
|
20
14
|
|
21
|
-
|
22
|
-
|
23
|
-
self.temp_access_token_expires_at = Time.now + response['expires_in'].to_i.seconds
|
24
|
-
self.temp_access_token = response['access_token']
|
25
|
-
|
26
|
-
update_token_store
|
27
|
-
|
28
|
-
self.temp_access_token
|
29
|
-
end
|
15
|
+
def access_token_options; super.merge!(grant_type: 'client_credentials'); end
|
30
16
|
end
|
31
17
|
end
|
data/lib/booker/version.rb
CHANGED
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.0.
|
4
|
+
version: 1.0.2
|
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-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|