Skip to content

Commit 49c2406

Browse files
committed
Merge pull request #8 from RadiusNetworks/json-api
Merge downstream API changes
2 parents 35838ec + 78b98a0 commit 49c2406

21 files changed

+679
-145
lines changed

Gemfile.lock

Lines changed: 56 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -10,43 +10,43 @@ PATH
1010
GEM
1111
remote: https://rubygems.org/
1212
specs:
13-
actionmailer (4.2.1)
14-
actionpack (= 4.2.1)
15-
actionview (= 4.2.1)
16-
activejob (= 4.2.1)
13+
actionmailer (4.2.3)
14+
actionpack (= 4.2.3)
15+
actionview (= 4.2.3)
16+
activejob (= 4.2.3)
1717
mail (~> 2.5, >= 2.5.4)
1818
rails-dom-testing (~> 1.0, >= 1.0.5)
19-
actionpack (4.2.1)
20-
actionview (= 4.2.1)
21-
activesupport (= 4.2.1)
19+
actionpack (4.2.3)
20+
actionview (= 4.2.3)
21+
activesupport (= 4.2.3)
2222
rack (~> 1.6)
2323
rack-test (~> 0.6.2)
2424
rails-dom-testing (~> 1.0, >= 1.0.5)
25-
rails-html-sanitizer (~> 1.0, >= 1.0.1)
26-
actionview (4.2.1)
27-
activesupport (= 4.2.1)
25+
rails-html-sanitizer (~> 1.0, >= 1.0.2)
26+
actionview (4.2.3)
27+
activesupport (= 4.2.3)
2828
builder (~> 3.1)
2929
erubis (~> 2.7.0)
3030
rails-dom-testing (~> 1.0, >= 1.0.5)
31-
rails-html-sanitizer (~> 1.0, >= 1.0.1)
32-
activejob (4.2.1)
33-
activesupport (= 4.2.1)
31+
rails-html-sanitizer (~> 1.0, >= 1.0.2)
32+
activejob (4.2.3)
33+
activesupport (= 4.2.3)
3434
globalid (>= 0.3.0)
35-
activemodel (4.2.1)
36-
activesupport (= 4.2.1)
35+
activemodel (4.2.3)
36+
activesupport (= 4.2.3)
3737
builder (~> 3.1)
38-
activerecord (4.2.1)
39-
activemodel (= 4.2.1)
40-
activesupport (= 4.2.1)
38+
activerecord (4.2.3)
39+
activemodel (= 4.2.3)
40+
activesupport (= 4.2.3)
4141
arel (~> 6.0)
42-
activesupport (4.2.1)
42+
activesupport (4.2.3)
4343
i18n (~> 0.7)
4444
json (~> 1.7, >= 1.7.7)
4545
minitest (~> 5.1)
4646
thread_safe (~> 0.3, >= 0.3.4)
4747
tzinfo (~> 1.1)
48-
addressable (2.3.7)
49-
arel (6.0.0)
48+
addressable (2.3.8)
49+
arel (6.0.2)
5050
builder (3.2.2)
5151
coderay (1.1.0)
5252
crack (0.4.2)
@@ -57,19 +57,19 @@ GEM
5757
multipart-post (>= 1.2, < 3)
5858
globalid (0.3.5)
5959
activesupport (>= 4.1.0)
60-
hashie (3.4.1)
60+
hashie (3.4.2)
6161
i18n (0.7.0)
62-
json (1.8.2)
63-
jwt (1.4.1)
62+
json (1.8.3)
63+
jwt (1.5.1)
6464
loofah (2.0.2)
6565
nokogiri (>= 1.5.9)
6666
mail (2.6.3)
6767
mime-types (>= 1.16, < 3)
6868
method_source (0.8.2)
69-
mime-types (2.5)
69+
mime-types (2.6.1)
7070
mini_portile (0.6.2)
71-
minitest (5.6.1)
72-
multi_json (1.11.0)
71+
minitest (5.7.0)
72+
multi_json (1.11.2)
7373
multi_xml (0.5.5)
7474
multipart-post (2.0.0)
7575
nokogiri (1.6.6.2)
@@ -83,7 +83,7 @@ GEM
8383
omniauth (1.2.2)
8484
hashie (>= 1.2, < 4)
8585
rack (~> 1.0)
86-
omniauth-oauth2 (1.3.0)
86+
omniauth-oauth2 (1.3.1)
8787
oauth2 (~> 1.0)
8888
omniauth (~> 1.2)
8989
pry (0.10.1)
@@ -92,19 +92,19 @@ GEM
9292
slop (~> 3.4)
9393
pry-nav (0.2.4)
9494
pry (>= 0.9.10, < 0.11.0)
95-
rack (1.6.1)
95+
rack (1.6.4)
9696
rack-test (0.6.3)
9797
rack (>= 1.0)
98-
rails (4.2.1)
99-
actionmailer (= 4.2.1)
100-
actionpack (= 4.2.1)
101-
actionview (= 4.2.1)
102-
activejob (= 4.2.1)
103-
activemodel (= 4.2.1)
104-
activerecord (= 4.2.1)
105-
activesupport (= 4.2.1)
98+
rails (4.2.3)
99+
actionmailer (= 4.2.3)
100+
actionpack (= 4.2.3)
101+
actionview (= 4.2.3)
102+
activejob (= 4.2.3)
103+
activemodel (= 4.2.3)
104+
activerecord (= 4.2.3)
105+
activesupport (= 4.2.3)
106106
bundler (>= 1.3.0, < 2.0)
107-
railties (= 4.2.1)
107+
railties (= 4.2.3)
108108
sprockets-rails
109109
rails-deprecated_sanitizer (1.0.3)
110110
activesupport (>= 4.2.0.alpha)
@@ -114,42 +114,42 @@ GEM
114114
rails-deprecated_sanitizer (>= 1.0.1)
115115
rails-html-sanitizer (1.0.2)
116116
loofah (~> 2.0)
117-
railties (4.2.1)
118-
actionpack (= 4.2.1)
119-
activesupport (= 4.2.1)
117+
railties (4.2.3)
118+
actionpack (= 4.2.3)
119+
activesupport (= 4.2.3)
120120
rake (>= 0.8.7)
121121
thor (>= 0.18.1, < 2.0)
122122
rake (10.4.2)
123-
rspec-core (3.2.2)
124-
rspec-support (~> 3.2.0)
125-
rspec-expectations (3.2.0)
123+
rspec-core (3.3.2)
124+
rspec-support (~> 3.3.0)
125+
rspec-expectations (3.3.1)
126126
diff-lcs (>= 1.2.0, < 2.0)
127-
rspec-support (~> 3.2.0)
128-
rspec-mocks (3.2.1)
127+
rspec-support (~> 3.3.0)
128+
rspec-mocks (3.3.2)
129129
diff-lcs (>= 1.2.0, < 2.0)
130-
rspec-support (~> 3.2.0)
131-
rspec-rails (3.2.1)
130+
rspec-support (~> 3.3.0)
131+
rspec-rails (3.3.3)
132132
actionpack (>= 3.0, < 4.3)
133133
activesupport (>= 3.0, < 4.3)
134134
railties (>= 3.0, < 4.3)
135-
rspec-core (~> 3.2.0)
136-
rspec-expectations (~> 3.2.0)
137-
rspec-mocks (~> 3.2.0)
138-
rspec-support (~> 3.2.0)
139-
rspec-support (3.2.2)
135+
rspec-core (~> 3.3.0)
136+
rspec-expectations (~> 3.3.0)
137+
rspec-mocks (~> 3.3.0)
138+
rspec-support (~> 3.3.0)
139+
rspec-support (3.3.0)
140140
safe_yaml (1.0.4)
141141
slop (3.6.0)
142-
sprockets (3.0.3)
142+
sprockets (3.2.0)
143143
rack (~> 1.0)
144-
sprockets-rails (2.2.4)
144+
sprockets-rails (2.3.2)
145145
actionpack (>= 3.0)
146146
activesupport (>= 3.0)
147147
sprockets (>= 2.8, < 4.0)
148148
thor (0.19.1)
149149
thread_safe (0.3.5)
150150
tzinfo (1.2.2)
151151
thread_safe (~> 0.1)
152-
webmock (1.20.4)
152+
webmock (1.21.0)
153153
addressable (>= 2.3.6)
154154
crack (>= 0.3.2)
155155

lib/kracken/authenticator.rb

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,33 @@
11
module Kracken
22
class Authenticator
3-
attr_reader :auth_hash, :user_class
3+
attr_reader :auth_hash
44

55
## Factory Methods
66

77
# Login the user with their credentails. Used for proxying the
88
# authentication to the auth server, normally from a mobile app
99
def self.user_with_credentials(email, password)
10-
response = Kracken::CredentialAuthenticator.new.fetch(email, password)
11-
response ? self.new(response).to_app_user : nil
10+
auth = Kracken::CredentialAuthenticator.new.fetch(email, password)
11+
self.new(auth.body).to_app_user
1212
end
1313

1414
# Login the user with an auth token. Used for API authentication for the
1515
# public APIs
1616
def self.user_with_token(token)
17-
response = Kracken::TokenAuthenticator.new.fetch(token)
18-
response ? self.new(response).to_app_user : nil
17+
auth = Kracken::TokenAuthenticator.new.fetch(token)
18+
19+
# Don't want stale user models being pulled from the cache. So only
20+
# cache the `user_id`.
21+
#
22+
# Don't want to query the database twice. So create a local variable
23+
# for the user, set it to nil, fetch from cache and only query if there
24+
# was a cache-hit (thus user is still nil).
25+
user = nil
26+
user_id = Rails.cache.fetch("auth/#{token}/#{auth.etag}") {
27+
user = self.new(auth.body).to_app_user
28+
user.id
29+
}
30+
user ||= Kracken.config.user_class.find(user_id)
1931
end
2032

2133
def initialize(response)

0 commit comments

Comments
 (0)