leisureking 0.1.1 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/leisureking/api.rb +16 -11
- data/lib/leisureking/config.rb +2 -0
- data/lib/leisureking/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 499f618e750d46d238e01fa0c21a0bd85d53b463d93c14c837c3e529422c8ee0
|
4
|
+
data.tar.gz: ba477bf14b46fa1b3f9e6c164a3bb82a17f4f0a688b03f8d069ce1b78993d3af
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 190eddb9a556151c5c3c5852dfa0882d6e27864b0d7d75823414931b6cf2a49307dba95c5a352c4ef0d7d9787029e3f0c81bc20266de401e1a5762540f2ed4e2
|
7
|
+
data.tar.gz: 1fe3cb21fe62f02222e7b100df978ce914d10df39abee714d5ef0247b711c7cac6ea09f71d734fef9b0fd218a675f258859f5089ce20a5aed42d160a9c9a10bc
|
data/lib/leisureking/api.rb
CHANGED
@@ -17,22 +17,26 @@ module LeisureKing::API
|
|
17
17
|
body[:environment] = LeisureKing::Config.environment
|
18
18
|
begin
|
19
19
|
|
20
|
-
unless LeisureKing::Authentication.has_valid_api_key
|
21
|
-
|
20
|
+
unless LeisureKing::Authentication.has_valid_api_key
|
21
|
+
unless endpoint == "authenticate"
|
22
|
+
puts "Requesting new API Token" if LeisureKing::Config.verbose
|
23
|
+
LeisureKing::Authentication.get_token
|
24
|
+
end
|
22
25
|
end
|
23
26
|
|
24
27
|
if LeisureKing::Config.verbose
|
25
28
|
puts "Sending request to #{url}"
|
26
|
-
puts "Body:\n#{body}" if body
|
29
|
+
puts "Body:\n#{body.to_json}" if body
|
27
30
|
end
|
28
31
|
|
29
32
|
begin
|
30
|
-
result = RestClient.post(url, body
|
33
|
+
result = RestClient.post(url, body, headers) do |response, request, res, &block|
|
31
34
|
if [301, 302, 307].include? response.code
|
32
35
|
redirected_url = response.headers[:location]
|
33
36
|
if LeisureKing::Config.verbose
|
34
37
|
puts "Redirecting request to #{redirected_url}"
|
35
|
-
puts "
|
38
|
+
puts "Headers:\n#{headers.to_json}" if headers
|
39
|
+
puts "Body:\n#{body.to_json}" if body
|
36
40
|
end
|
37
41
|
RestClient.post(redirected_url, body.to_json, headers)
|
38
42
|
else
|
@@ -40,15 +44,16 @@ module LeisureKing::API
|
|
40
44
|
end
|
41
45
|
end
|
42
46
|
rescue RestClient::Unauthorized, RestClient::Forbidden => err
|
43
|
-
|
47
|
+
if LeisureKing::Config.verbose
|
48
|
+
puts "Backtrace:"
|
49
|
+
puts err.backtrace
|
50
|
+
end
|
51
|
+
raise "Access denied. API Response:\n#{err}."
|
44
52
|
end
|
45
53
|
|
46
54
|
puts "Result:\n#{result}" if LeisureKing::Config.verbose
|
47
|
-
# begin
|
48
55
|
return JSON.parse(result)
|
49
|
-
|
50
|
-
# return result
|
51
|
-
# end
|
56
|
+
|
52
57
|
rescue RestClient::BadRequest => err
|
53
58
|
raise "Bad Request. API Response:\n#{err.response}"
|
54
59
|
end
|
@@ -66,7 +71,7 @@ module LeisureKing::API
|
|
66
71
|
if LeisureKing::Config.client_email && LeisureKing::Config.client_email != ''
|
67
72
|
h[:from] = LeisureKing::Config.client_email # email address for human communication
|
68
73
|
end
|
69
|
-
if LeisureKing::Authentication.
|
74
|
+
if LeisureKing::Authentication.has_valid_api_key
|
70
75
|
h["Authorization"] = "Token #{LeisureKing::Authentication.token}"
|
71
76
|
end
|
72
77
|
return h
|
data/lib/leisureking/config.rb
CHANGED
@@ -8,6 +8,7 @@ module ::LeisureKing::Config
|
|
8
8
|
attr_accessor :api_secret
|
9
9
|
attr_accessor :verbose
|
10
10
|
attr_accessor :api_version
|
11
|
+
attr_accessor :api_base_url
|
11
12
|
attr_accessor :environment
|
12
13
|
attr_accessor :client_email # Who is making the request? For optional HTTP Header
|
13
14
|
|
@@ -21,6 +22,7 @@ module ::LeisureKing::Config
|
|
21
22
|
:@api_secret => nil,
|
22
23
|
:@verbose => false,
|
23
24
|
:@environment => :test,
|
25
|
+
:@api_base_url => 'https://api.leisureking.eu',
|
24
26
|
:@client_email => '',
|
25
27
|
:@api_version => '1l'
|
26
28
|
}
|
data/lib/leisureking/version.rb
CHANGED