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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 71383dc5b6693a8c6f671ba8e800e894258f53a369524f230643dc90f78f12c7
4
- data.tar.gz: 1b9635d739f1ff2fe0324bc86c9aae7798e50aebb251e27131883c25d2ae5fbc
3
+ metadata.gz: 499f618e750d46d238e01fa0c21a0bd85d53b463d93c14c837c3e529422c8ee0
4
+ data.tar.gz: ba477bf14b46fa1b3f9e6c164a3bb82a17f4f0a688b03f8d069ce1b78993d3af
5
5
  SHA512:
6
- metadata.gz: 8d10dacec07fa604af2932161f66316368e1c42b727bac6f3bba6542f6918f155c2b391973b175f989e5320a3dfa1f916ba52ebde29aaf03669a369410d44c70
7
- data.tar.gz: a73ffbe6d6fd8b667fe437f8ac2a84bbbd27680adbec2be091ab64de2b8e7981c6b0312e741a09d7e7568f573a0422e7d84f204f4fb27923a659912542be0379
6
+ metadata.gz: 190eddb9a556151c5c3c5852dfa0882d6e27864b0d7d75823414931b6cf2a49307dba95c5a352c4ef0d7d9787029e3f0c81bc20266de401e1a5762540f2ed4e2
7
+ data.tar.gz: 1fe3cb21fe62f02222e7b100df978ce914d10df39abee714d5ef0247b711c7cac6ea09f71d734fef9b0fd218a675f258859f5089ce20a5aed42d160a9c9a10bc
@@ -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 || endpoint == "authenticate"
21
- LeisureKing::Authentication.get_token
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.to_json, headers) do |response, request, res, &block|
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 "Body:\n#{body}" if body
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
- raise "Access denied. API Response:\n#{err}"
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
- # rescue
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.token
74
+ if LeisureKing::Authentication.has_valid_api_key
70
75
  h["Authorization"] = "Token #{LeisureKing::Authentication.token}"
71
76
  end
72
77
  return h
@@ -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
  }
@@ -1,3 +1,3 @@
1
1
  module LeisureKing
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: leisureking
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henk Meijer