candy_check 0.1.2 → 0.2.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.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +5 -12
  3. data/Guardfile +42 -0
  4. data/MIGRATION_GUIDE_0_2_0.md +141 -0
  5. data/README.md +49 -26
  6. data/candy_check.gemspec +32 -26
  7. data/lib/candy_check/cli/app.rb +16 -33
  8. data/lib/candy_check/cli/commands/play_store.rb +12 -13
  9. data/lib/candy_check/play_store.rb +17 -10
  10. data/lib/candy_check/play_store/android_publisher_service.rb +6 -0
  11. data/lib/candy_check/play_store/product_purchases/product_purchase.rb +90 -0
  12. data/lib/candy_check/play_store/product_purchases/product_verification.rb +53 -0
  13. data/lib/candy_check/play_store/subscription_purchases/subscription_purchase.rb +141 -0
  14. data/lib/candy_check/play_store/subscription_purchases/subscription_verification.rb +55 -0
  15. data/lib/candy_check/play_store/verification_failure.rb +8 -6
  16. data/lib/candy_check/play_store/verifier.rb +24 -49
  17. data/lib/candy_check/version.rb +1 -1
  18. data/spec/candy_check_spec.rb +2 -2
  19. data/spec/cli/commands/play_store_spec.rb +10 -43
  20. data/spec/fixtures/play_store/random_dummy_key.json +12 -0
  21. data/spec/fixtures/vcr_cassettes/play_store/product_purchases/permission_denied.yml +196 -0
  22. data/spec/fixtures/vcr_cassettes/play_store/product_purchases/response_with_empty_body.yml +183 -0
  23. data/spec/fixtures/vcr_cassettes/play_store/product_purchases/valid_but_not_consumed.yml +122 -0
  24. data/spec/fixtures/vcr_cassettes/play_store/subscription_purchases/permission_denied.yml +196 -0
  25. data/spec/fixtures/vcr_cassettes/play_store/subscription_purchases/valid_but_expired.yml +127 -0
  26. data/spec/play_store/product_purchases/product_purchase_spec.rb +110 -0
  27. data/spec/play_store/product_purchases/product_verification_spec.rb +49 -0
  28. data/spec/play_store/subscription_purchases/subscription_purchase_spec.rb +181 -0
  29. data/spec/play_store/subscription_purchases/subscription_verification_spec.rb +65 -0
  30. data/spec/play_store/verification_failure_spec.rb +18 -18
  31. data/spec/play_store/verifier_spec.rb +32 -96
  32. data/spec/spec_helper.rb +24 -11
  33. metadata +120 -47
  34. data/lib/candy_check/play_store/client.rb +0 -139
  35. data/lib/candy_check/play_store/config.rb +0 -51
  36. data/lib/candy_check/play_store/discovery_repository.rb +0 -33
  37. data/lib/candy_check/play_store/receipt.rb +0 -81
  38. data/lib/candy_check/play_store/subscription.rb +0 -139
  39. data/lib/candy_check/play_store/subscription_verification.rb +0 -30
  40. data/lib/candy_check/play_store/verification.rb +0 -48
  41. data/spec/fixtures/api_cache.dump +0 -1
  42. data/spec/fixtures/play_store/api_cache.dump +0 -1
  43. data/spec/fixtures/play_store/auth_failure.txt +0 -18
  44. data/spec/fixtures/play_store/auth_success.txt +0 -20
  45. data/spec/fixtures/play_store/discovery.txt +0 -2841
  46. data/spec/fixtures/play_store/dummy.p12 +0 -0
  47. data/spec/fixtures/play_store/empty.txt +0 -17
  48. data/spec/fixtures/play_store/products_failure.txt +0 -29
  49. data/spec/fixtures/play_store/products_success.txt +0 -22
  50. data/spec/play_store/client_spec.rb +0 -125
  51. data/spec/play_store/config_spec.rb +0 -96
  52. data/spec/play_store/discovery_respository_spec.rb +0 -31
  53. data/spec/play_store/receipt_spec.rb +0 -88
  54. data/spec/play_store/subscription_spec.rb +0 -138
  55. data/spec/play_store/subscription_verification_spec.rb +0 -97
  56. data/spec/play_store/verification_spec.rb +0 -81
@@ -1,97 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe CandyCheck::PlayStore::SubscriptionVerification do
4
- subject do
5
- CandyCheck::PlayStore::SubscriptionVerification.new(
6
- client, package, product_id, token
7
- )
8
- end
9
- let(:client) { DummyGoogleSubsClient.new(response) }
10
- let(:package) { 'the_package' }
11
- let(:product_id) { 'the_product' }
12
- let(:token) { 'the_token' }
13
-
14
- describe 'valid' do
15
- let(:response) do
16
- {
17
- 'kind' => 'androidpublisher#subscriptionPurchase',
18
- 'startTimeMillis' => '1459540113244',
19
- 'expiryTimeMillis' => '1462132088610',
20
- 'autoRenewing' => false,
21
- 'developerPayload' => 'payload that gets stored and returned',
22
- 'cancelReason' => 0,
23
- 'paymentState' => '1'
24
- }
25
- end
26
-
27
- it 'calls the client with the correct paramters' do
28
- subject.call!
29
- client.package.must_equal package
30
- client.product_id.must_equal product_id
31
- client.token.must_equal token
32
- end
33
-
34
- it 'returns a subscription' do
35
- result = subject.call!
36
- result.must_be_instance_of CandyCheck::PlayStore::Subscription
37
- result.expired?.must_be_true
38
- end
39
- end
40
-
41
- describe 'failure' do
42
- let(:response) do
43
- {
44
- 'error' => {
45
- 'code' => 401,
46
- 'message' => 'The current user has insufficient permissions'
47
- }
48
- }
49
- end
50
-
51
- it 'returns a verification failure' do
52
- result = subject.call!
53
- result.must_be_instance_of CandyCheck::PlayStore::VerificationFailure
54
- result.code.must_equal 401
55
- end
56
- end
57
-
58
- describe 'empty' do
59
- let(:response) do
60
- {}
61
- end
62
-
63
- it 'returns a verification failure' do
64
- result = subject.call!
65
- result.must_be_instance_of CandyCheck::PlayStore::VerificationFailure
66
- result.code.must_equal(-1)
67
- end
68
- end
69
-
70
- describe 'invalid response kind' do
71
- let(:response) do
72
- {
73
- 'kind' => 'something weird'
74
- }
75
- end
76
-
77
- it 'returns a verification failure' do
78
- result = subject.call!
79
- result.must_be_instance_of CandyCheck::PlayStore::VerificationFailure
80
- end
81
- end
82
-
83
- private
84
-
85
- DummyGoogleSubsClient = Struct.new(:response) do
86
- attr_reader :package, :product_id, :token
87
-
88
- def boot!; end
89
-
90
- def verify_subscription(package, product_id, token)
91
- @package = package
92
- @product_id = product_id
93
- @token = token
94
- response
95
- end
96
- end
97
- end
@@ -1,81 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe CandyCheck::PlayStore::Verification do
4
- subject do
5
- CandyCheck::PlayStore::Verification.new(client, package, product_id, token)
6
- end
7
- let(:client) { DummyGoogleClient.new(response) }
8
- let(:package) { 'the_package' }
9
- let(:product_id) { 'the_product' }
10
- let(:token) { 'the_token' }
11
-
12
- describe 'valid' do
13
- let(:response) do
14
- {
15
- 'kind' => 'androidpublisher#productPurchase',
16
- 'purchaseTimeMillis' => '1421676237413',
17
- 'purchaseState' => 0,
18
- 'consumptionState' => 0,
19
- 'developerPayload' => 'payload that gets stored and returned'
20
- }
21
- end
22
-
23
- it 'calls the client with the correct paramters' do
24
- subject.call!
25
- client.package.must_equal package
26
- client.product_id.must_equal product_id
27
- client.token.must_equal token
28
- end
29
-
30
- it 'returns a receipt' do
31
- result = subject.call!
32
- result.must_be_instance_of CandyCheck::PlayStore::Receipt
33
- result.valid?.must_be_true
34
- result.consumed?.must_be_false
35
- end
36
- end
37
-
38
- describe 'failure' do
39
- let(:response) do
40
- {
41
- 'error' => {
42
- 'code' => 401,
43
- 'message' => 'The current user has insufficient permissions'
44
- }
45
- }
46
- end
47
-
48
- it 'returns a verification failure' do
49
- result = subject.call!
50
- result.must_be_instance_of CandyCheck::PlayStore::VerificationFailure
51
- result.code.must_equal 401
52
- end
53
- end
54
-
55
- describe 'empty' do
56
- let(:response) do
57
- {}
58
- end
59
-
60
- it 'returns a verification failure' do
61
- result = subject.call!
62
- result.must_be_instance_of CandyCheck::PlayStore::VerificationFailure
63
- result.code.must_equal(-1)
64
- end
65
- end
66
-
67
- private
68
-
69
- DummyGoogleClient = Struct.new(:response) do
70
- attr_reader :package, :product_id, :token
71
-
72
- def boot!; end
73
-
74
- def verify(package, product_id, token)
75
- @package = package
76
- @product_id = product_id
77
- @token = token
78
- response
79
- end
80
- end
81
- end