growviral-keystore 0.0.6 → 0.0.7
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/lib/growviral/keystore.rb +3 -0
- data/lib/keystore/account_fetcher.rb +15 -1
- data/lib/keystore/client.rb +4 -0
- data/lib/keystore/version.rb +1 -1
- data/test/account_fetcher_test.rb +33 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 39c7ed707d25df05266ff128708fd11ceeb1813a
|
4
|
+
data.tar.gz: 686752397a5ce83bf6a58e900f3522bc577f4be1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f51b952280d74e0a918fbc88505b524a535162a0a8c37e75659ed74e68954887611cd52062d0b3d7b46e27025939744f25379df43122d16abadbeac4147b4b23
|
7
|
+
data.tar.gz: f0b11d289e4b124219424c5c0c12b7fa666a5d645b811545d0253cc721a06ada1e01ee156c88387dfd57bfda5d812c42a21c30978d1368496e71db530e200898
|
data/lib/growviral/keystore.rb
CHANGED
@@ -5,6 +5,10 @@ module GrowViral
|
|
5
5
|
new(*args).fetch
|
6
6
|
end
|
7
7
|
|
8
|
+
def self.exists?(*args)
|
9
|
+
new(*args).exists?
|
10
|
+
end
|
11
|
+
|
8
12
|
attr_reader :application_id, :uid, :config
|
9
13
|
def initialize(application_id, uid, deps)
|
10
14
|
raise HandleNotUidError unless uid.is_a? Numeric
|
@@ -14,9 +18,19 @@ module GrowViral
|
|
14
18
|
@config = deps[:config]
|
15
19
|
end
|
16
20
|
|
21
|
+
def exists?
|
22
|
+
fetch
|
23
|
+
rescue GrowViral::NoAccountError
|
24
|
+
false
|
25
|
+
end
|
26
|
+
|
17
27
|
def fetch
|
18
28
|
response = Net::HTTP.get_response(uri)
|
19
|
-
|
29
|
+
if response.code.to_i == 200
|
30
|
+
Account.new JSON.parse(response.body)
|
31
|
+
else
|
32
|
+
raise GrowViral::NoAccountError.new(uid)
|
33
|
+
end
|
20
34
|
end
|
21
35
|
|
22
36
|
def uri
|
data/lib/keystore/client.rb
CHANGED
@@ -11,6 +11,10 @@ module GrowViral
|
|
11
11
|
ApplicationFetcher.fetch(provider, name, config: config)
|
12
12
|
end
|
13
13
|
|
14
|
+
def account_exists?(app_id, handle)
|
15
|
+
AccountFetcher.exists?(app_id, handle, config: config)
|
16
|
+
end
|
17
|
+
|
14
18
|
def fetch_account(app_id, handle)
|
15
19
|
AccountFetcher.fetch(app_id, handle, config: config)
|
16
20
|
end
|
data/lib/keystore/version.rb
CHANGED
@@ -22,7 +22,7 @@ class AccountFetcherTest < Minitest::Test
|
|
22
22
|
}
|
23
23
|
|
24
24
|
uri = URI.parse("http://localhost:3000/applications/#{application_id}/accounts/#{uid}")
|
25
|
-
Net::HTTP.expects(:get_response).with(uri).returns(mock(body: output.to_json))
|
25
|
+
Net::HTTP.expects(:get_response).with(uri).returns(mock(code: '200', body: output.to_json))
|
26
26
|
|
27
27
|
client = GrowViral::Keystore::Client.new(:development)
|
28
28
|
account = client.fetch_account(application_id, uid)
|
@@ -33,4 +33,36 @@ class AccountFetcherTest < Minitest::Test
|
|
33
33
|
assert_equal token, account.token
|
34
34
|
assert_equal secret, account.secret
|
35
35
|
end
|
36
|
+
|
37
|
+
def test_raises_if_404
|
38
|
+
uid = 123
|
39
|
+
application_id = 43
|
40
|
+
uri = URI.parse("http://localhost:3000/applications/#{application_id}/accounts/#{uid}")
|
41
|
+
Net::HTTP.expects(:get_response).with(uri).returns(mock(code: '404'))
|
42
|
+
|
43
|
+
|
44
|
+
client = GrowViral::Keystore::Client.new(:development)
|
45
|
+
assert_raises(GrowViral::NoAccountError) { client.fetch_account(application_id, uid) }
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_exists_for_truth
|
49
|
+
uid = 123
|
50
|
+
application_id = 43
|
51
|
+
uri = URI.parse("http://localhost:3000/applications/#{application_id}/accounts/#{uid}")
|
52
|
+
Net::HTTP.expects(:get_response).with(uri).returns(mock(code: '200', body: {}.to_json))
|
53
|
+
|
54
|
+
client = GrowViral::Keystore::Client.new(:development)
|
55
|
+
assert client.account_exists?(application_id, uid)
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_exists_for_false
|
59
|
+
uid = 123
|
60
|
+
application_id = 43
|
61
|
+
uri = URI.parse("http://localhost:3000/applications/#{application_id}/accounts/#{uid}")
|
62
|
+
Net::HTTP.expects(:get_response).with(uri).returns(mock(code: '404'))
|
63
|
+
|
64
|
+
client = GrowViral::Keystore::Client.new(:development)
|
65
|
+
refute client.account_exists?(application_id, uid)
|
66
|
+
end
|
67
|
+
|
36
68
|
end
|