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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1b7f2c80c08f7de11508489e93a4136088d7453d
4
- data.tar.gz: 6f1437985f5049051c63c8616576c7777738123a
3
+ metadata.gz: 39c7ed707d25df05266ff128708fd11ceeb1813a
4
+ data.tar.gz: 686752397a5ce83bf6a58e900f3522bc577f4be1
5
5
  SHA512:
6
- metadata.gz: b91c9cf5e114edc8ed8905e890b9e7d6c8ed69d5ffaeee38840dd612f57f7fa3e50f53907880593476cc1ce71abba342af5f25df803999f6d880bd92abbf184c
7
- data.tar.gz: 4fde4fdfcd1b86e1f90fe8613153a4f9856e038b3f8905aa07700ddfe87a4a7c97982730632e54d577fa010cce5531041a98ee9c0befe600956173877ca91924
6
+ metadata.gz: f51b952280d74e0a918fbc88505b524a535162a0a8c37e75659ed74e68954887611cd52062d0b3d7b46e27025939744f25379df43122d16abadbeac4147b4b23
7
+ data.tar.gz: f0b11d289e4b124219424c5c0c12b7fa666a5d645b811545d0253cc721a06ada1e01ee156c88387dfd57bfda5d812c42a21c30978d1368496e71db530e200898
@@ -17,6 +17,9 @@ module GrowViral
17
17
  module Keystore
18
18
  end
19
19
 
20
+ class NoAccountError < RuntimeError
21
+ end
22
+
20
23
  class HandleNotUidError < RuntimeError
21
24
  end
22
25
  end
@@ -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
- Account.new JSON.parse(response.body)
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
@@ -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
@@ -1,5 +1,5 @@
1
1
  module GrowViral
2
2
  module Keystore
3
- VERSION = "0.0.6"
3
+ VERSION = "0.0.7"
4
4
  end
5
5
  end
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: growviral-keystore
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Walker