lightrail_client 1.0.1 → 1.1.0
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/README.md +8 -0
- data/lib/lightrail_client/shopper_token_factory.rb +27 -7
- data/lib/lightrail_client/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: d4b03b92b6056752123712d93bc1e574be852468
|
4
|
+
data.tar.gz: 7bf40af48e0fdf721dc0507e8636ac392f200a33
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 72a74728a92d19ae2236e7ded5ad73ba364351d7dcbe99e6baccf885413cb6b48ce5f875b4d26c458bef912fea4dd56dfb1fa86730daff7e6ed084028a803205
|
7
|
+
data.tar.gz: 16874d6fb03e23c298996710ad3c0aa6a949f0a9b50d0ec77927a47f0e4725dec6adce72aad4aaca2bdf80b25d97435339c1aa14204422408b6e5d6285f49682
|
data/README.md
CHANGED
@@ -295,6 +295,14 @@ After checking out the repo, run `bin/setup` to install dependencies, then run `
|
|
295
295
|
|
296
296
|
To install this gem onto your local machine, run `bundle exec rake install`.
|
297
297
|
|
298
|
+
### Publishing
|
299
|
+
|
300
|
+
Make sure to bump the version number before publishing changes.
|
301
|
+
|
302
|
+
Run `gem build lightrail_client` to build the gem locally. The output will contain the gem name, version, and filename of the built `.gem`.
|
303
|
+
|
304
|
+
Run `gem push {{filename}}` to publish to RubyGems.
|
305
|
+
|
298
306
|
## License
|
299
307
|
|
300
308
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module Lightrail
|
2
2
|
class ShopperTokenFactory
|
3
|
-
def self.generate (contact,
|
3
|
+
def self.generate (contact, options=nil)
|
4
4
|
raise Lightrail::BadParameterError.new("Lightrail::api_key is not set") unless Lightrail::api_key
|
5
5
|
raise Lightrail::BadParameterError.new("Lightrail::shared_secret is not set") unless Lightrail::shared_secret
|
6
6
|
|
@@ -9,14 +9,33 @@ module Lightrail
|
|
9
9
|
Lightrail::Validator.has_valid_user_supplied_id?(contact))
|
10
10
|
|
11
11
|
g = {}
|
12
|
-
if
|
12
|
+
if Lightrail::Validator.has_valid_or_empty_shopper_id?(contact)
|
13
13
|
g['shi'] = Lightrail::Validator.get_shopper_id(contact)
|
14
|
-
elsif
|
14
|
+
elsif Lightrail::Validator.has_valid_contact_id?(contact)
|
15
15
|
g['coi'] = Lightrail::Validator.get_contact_id(contact)
|
16
|
-
elsif
|
16
|
+
elsif Lightrail::Validator.has_valid_user_supplied_id?(contact)
|
17
17
|
g['cui'] = Lightrail::Validator.get_user_supplied_id(contact)
|
18
18
|
end
|
19
19
|
|
20
|
+
validity_in_seconds = 43200
|
21
|
+
metadata = nil
|
22
|
+
if !options
|
23
|
+
# no-op
|
24
|
+
elsif options.is_a?(Numeric)
|
25
|
+
# support for legacy code when options was validity_in_seconds
|
26
|
+
validity_in_seconds = options
|
27
|
+
elsif options.is_a?(Hash)
|
28
|
+
if options.has_key?(:validity_in_seconds)
|
29
|
+
validity_in_seconds = options[:validity_in_seconds]
|
30
|
+
end
|
31
|
+
if options.has_key?(:metadata)
|
32
|
+
metadata = options[:metadata]
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
if validity_in_seconds <= 0
|
37
|
+
raise Lightrail::LightrailArgumentError.new("validity_in_seconds must be > 0")
|
38
|
+
end
|
20
39
|
|
21
40
|
payload = Lightrail::api_key.split('.')
|
22
41
|
payload = JSON.parse(Base64.decode64(payload[1]))
|
@@ -28,14 +47,15 @@ module Lightrail
|
|
28
47
|
payload = {
|
29
48
|
g: g,
|
30
49
|
iat: iat,
|
50
|
+
exp: iat + validity_in_seconds,
|
31
51
|
iss: "MERCHANT"
|
32
52
|
}
|
33
53
|
|
34
|
-
if
|
35
|
-
payload[
|
54
|
+
if metadata
|
55
|
+
payload["metadata"] = metadata
|
36
56
|
end
|
37
57
|
|
38
58
|
JWT.encode(payload, Lightrail::shared_secret, 'HS256')
|
39
59
|
end
|
40
60
|
end
|
41
|
-
end
|
61
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lightrail_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lightrail
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-03-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|