leisureking 0.1.0 → 0.1.1

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
- SHA1:
3
- metadata.gz: 6a84672304ff7a742ee55a6b41583033850ae46a
4
- data.tar.gz: 787ea92a3cfec080bc615e23941b80b11fb2d59a
2
+ SHA256:
3
+ metadata.gz: 71383dc5b6693a8c6f671ba8e800e894258f53a369524f230643dc90f78f12c7
4
+ data.tar.gz: 1b9635d739f1ff2fe0324bc86c9aae7798e50aebb251e27131883c25d2ae5fbc
5
5
  SHA512:
6
- metadata.gz: f7a45bf92772d70a4f339b0e1045f523cd33454cf100602e981f251c8a868098820c2d69bc68447ae17b29a63b8aa89323f0986d724cc76580738199d93eb7fc
7
- data.tar.gz: 2f7808cafed3ab98fe3a39b49bedab94037d251c8ece77a1d812388bbd9f31176c016a3d4a3dc0f8fdf858fd3e017ecbf35db89d7a193cb153276bd5f7d2b7a5
6
+ metadata.gz: 8d10dacec07fa604af2932161f66316368e1c42b727bac6f3bba6542f6918f155c2b391973b175f989e5320a3dfa1f916ba52ebde29aaf03669a369410d44c70
7
+ data.tar.gz: a73ffbe6d6fd8b667fe437f8ac2a84bbbd27680adbec2be091ab64de2b8e7981c6b0312e741a09d7e7568f573a0422e7d84f204f4fb27923a659912542be0379
data/Gemfile.lock CHANGED
@@ -2,6 +2,7 @@ PATH
2
2
  remote: .
3
3
  specs:
4
4
  leisureking (0.1.0)
5
+ jwt
5
6
  rest-client
6
7
 
7
8
  GEM
@@ -13,6 +14,7 @@ GEM
13
14
  http-accept (1.7.0)
14
15
  http-cookie (1.0.3)
15
16
  domain_name (~> 0.5)
17
+ jwt (2.2.1)
16
18
  mime-types (3.3)
17
19
  mime-types-data (~> 3.2015)
18
20
  mime-types-data (3.2019.1009)
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
- # Leisureking
1
+ # LeisureKing
2
2
 
3
3
 
4
- This gem works as a simple Ruby wrapper for the Leisureking API. The Leisureking API has a very straight forward REST API.
4
+ This gem works as a simple Ruby wrapper for the LeisureKing API. The LeisureKing API has a very straight forward REST API, this gem doesn't aim to replace it. It just acts as a 'ruby-esqe' interface to it.
5
5
 
6
6
  All this gem does, is make it a little bit simpler to use the API:
7
7
  - You can set your credentials via Rails config
@@ -40,6 +40,7 @@ To use this gem in a Rails project:
40
40
  # config/development.rb
41
41
  config.leisure_king.api_key = "MY-API-KEY"
42
42
  config.leisure_king.api_secret = "MY-API-SECRET"
43
+ config.leisure_king.verbose = false # set to true to show the inputs and outpts of each request
43
44
 
44
45
  ```
45
46
 
data/leisureking.gemspec CHANGED
@@ -29,7 +29,7 @@ Gem::Specification.new do |spec|
29
29
  spec.require_paths = ["lib"]
30
30
 
31
31
  spec.add_dependency "rest-client"
32
-
32
+ spec.add_dependency "jwt"
33
33
  spec.add_development_dependency "bundler", "~> 2.0"
34
34
  spec.add_development_dependency "rake", "~> 10.0"
35
35
  spec.add_development_dependency "rspec", "~> 3.0"
@@ -16,9 +16,11 @@ module LeisureKing::API
16
16
  url = "#{base_uri}/#{endpoint}"
17
17
  body[:environment] = LeisureKing::Config.environment
18
18
  begin
19
- unless endpoint == "authenticate"
19
+
20
+ unless LeisureKing::Authentication.has_valid_api_key || endpoint == "authenticate"
20
21
  LeisureKing::Authentication.get_token
21
22
  end
23
+
22
24
  if LeisureKing::Config.verbose
23
25
  puts "Sending request to #{url}"
24
26
  puts "Body:\n#{body}" if body
@@ -1,5 +1,6 @@
1
1
  module LeisureKing::Authentication
2
- require 'digest'
2
+ require 'digest'
3
+ require 'jwt'
3
4
  require 'base64'
4
5
  require 'openssl'
5
6
 
@@ -26,6 +27,18 @@ module LeisureKing::Authentication
26
27
  end
27
28
  return result
28
29
  end
30
+
31
+ # Parses the current API key and checks if the 'exp' attribute
32
+ # represents a date in the future.
33
+ def has_valid_api_key
34
+ return self.token != nil && api_key_valid_until > Time.now
35
+ end
36
+
37
+ def api_key_valid_until
38
+ decoded_token = JWT.decode self.token, nil, false
39
+ Time.at(decoded_token.first["exp"])
40
+ end
41
+
29
42
  end
30
43
  init!
31
44
  end
@@ -1,3 +1,3 @@
1
1
  module LeisureKing
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: leisureking
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henk Meijer
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-12-13 00:00:00.000000000 Z
11
+ date: 2019-12-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: jwt
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: bundler
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -111,7 +125,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
111
125
  version: '0'
112
126
  requirements: []
113
127
  rubyforge_project:
114
- rubygems_version: 2.6.14
128
+ rubygems_version: 2.7.6
115
129
  signing_key:
116
130
  specification_version: 4
117
131
  summary: Ruby wrapper for the Leisureking API