cru_lib 0.0.3 → 0.0.4

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
  SHA1:
3
- metadata.gz: a613a3c3c5d3fa1d8a2b331e0a5d56a437c49c14
4
- data.tar.gz: b1979b984158dbd5c9f74e4d0bd6b2e4be00c6c7
3
+ metadata.gz: 697695780ce2aabcab8f279e0a85ea13c912d569
4
+ data.tar.gz: e24780ec01f7cdd63897644bd0b50a360b7590d8
5
5
  SHA512:
6
- metadata.gz: bf2b90f0bf13e82182d39b5edf3a887aa85255fc62ca366830e0f32e36611b19647715014caf7dbe426fb6bd0a529619fcbea1357a067ae1bf9601686faf5797
7
- data.tar.gz: 4c89e114302da48e30b6a7e6d332f5664f6657dc2622a0808fe7e54a5decaa3d335ea87aa69d4e1aec3ba0477a50d84e637e9afff5a4b0b2ab29d3cca2387a27
6
+ metadata.gz: 52d1336f04fa09b958115c7667aec814439df2d86b5dfa5a5c1be2b04998dd75b939cb4209f6e2571f938bd657ad75322d040f9a1ff3a33668b68532d1e72026
7
+ data.tar.gz: 6a80cd362d2ca89ec0eb5cbda957a0b1e47f17505fecb87d50456bbc95334f83428c6c4803e32eddd3e29343a74697e33ed8ddc39aecdfc5f520ac2c37fed821
@@ -4,20 +4,17 @@ module CruLib
4
4
  class AccessToken < ActiveModelSerializers::Model
5
5
  attr_accessor :key_guid, :email, :first_name, :last_name, :token
6
6
 
7
+ def initialize(attributes = {})
8
+ super
9
+ generate_access_token unless attributes['token']
10
+ write
11
+ end
12
+
7
13
  class << self
8
- def redis_key(token)
9
- ['cru_lib:access_token', token].join(':')
10
- end
11
14
 
12
15
  def read(token)
13
16
  json = exist?(token)
14
- if json
15
- attributes = Oj.load(json)
16
- attributes['token'] = token
17
- access_token = new(attributes)
18
- access_token.write
19
- access_token
20
- end
17
+ new(Oj.load(json)) if json
21
18
  end
22
19
 
23
20
  def exist?(token)
@@ -27,23 +24,23 @@ module CruLib
27
24
  def redis_client
28
25
  @redis_client ||= CruLib.redis_client
29
26
  end
27
+
28
+ def redis_key(token)
29
+ ['cru_lib:access_token', token].join(':')
30
+ end
30
31
  end
31
32
 
33
+ private
32
34
 
33
35
  def generate_access_token
34
36
  loop do
35
37
  attributes[:token] = SecureRandom.uuid.gsub(/\-/, '')
36
38
  break unless self.class.exist?(attributes[:token])
37
39
  end
38
- write
39
-
40
- self
41
40
  end
42
41
 
43
-
44
42
  def write
45
- self.class.redis_client.setex(self.class.redis_key(token), 30.minutes.to_i, to_json)
43
+ self.class.redis_client.setex(self.class.redis_key(attributes[:token]), 30.minutes.to_i, to_json)
46
44
  end
47
- private
48
45
  end
49
- end
46
+ end
@@ -1,3 +1,3 @@
1
1
  module CruLib
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cru_lib
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josh Starcher
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-04 00:00:00.000000000 Z
11
+ date: 2015-11-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: global_registry