candy_check 0.1.0.pre → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. checksums.yaml +5 -5
  2. data/.rubocop.yml +23 -0
  3. data/.ruby-version +1 -1
  4. data/.travis.yml +7 -8
  5. data/Guardfile +42 -0
  6. data/MIGRATION_GUIDE_0_2_0.md +141 -0
  7. data/README.md +86 -26
  8. data/Rakefile +1 -1
  9. data/candy_check.gemspec +33 -25
  10. data/lib/candy_check/app_store/receipt_collection.rb +5 -3
  11. data/lib/candy_check/app_store/subscription_verification.rb +25 -1
  12. data/lib/candy_check/app_store/verification.rb +1 -1
  13. data/lib/candy_check/app_store/verifier.rb +11 -11
  14. data/lib/candy_check/cli/app.rb +16 -33
  15. data/lib/candy_check/cli/commands/play_store.rb +12 -13
  16. data/lib/candy_check/play_store.rb +20 -10
  17. data/lib/candy_check/play_store/acknowledger.rb +19 -0
  18. data/lib/candy_check/play_store/android_publisher_service.rb +6 -0
  19. data/lib/candy_check/play_store/product_acknowledgements/acknowledgement.rb +45 -0
  20. data/lib/candy_check/play_store/product_acknowledgements/response.rb +24 -0
  21. data/lib/candy_check/play_store/product_purchases/product_purchase.rb +90 -0
  22. data/lib/candy_check/play_store/product_purchases/product_verification.rb +53 -0
  23. data/lib/candy_check/play_store/subscription_purchases/subscription_purchase.rb +154 -0
  24. data/lib/candy_check/play_store/subscription_purchases/subscription_verification.rb +55 -0
  25. data/lib/candy_check/play_store/verification_failure.rb +8 -6
  26. data/lib/candy_check/play_store/verifier.rb +24 -49
  27. data/lib/candy_check/utils/config.rb +5 -3
  28. data/lib/candy_check/version.rb +1 -1
  29. data/spec/app_store/receipt_collection_spec.rb +33 -0
  30. data/spec/app_store/subscription_verification_spec.rb +35 -2
  31. data/spec/app_store/verifier_spec.rb +24 -5
  32. data/spec/candy_check_spec.rb +2 -2
  33. data/spec/cli/commands/play_store_spec.rb +10 -43
  34. data/spec/fixtures/play_store/random_dummy_key.json +12 -0
  35. data/spec/fixtures/vcr_cassettes/play_store/product_acknowledgements/acknowledged.yml +105 -0
  36. data/spec/fixtures/vcr_cassettes/play_store/product_acknowledgements/already_acknowledged.yml +124 -0
  37. data/spec/fixtures/vcr_cassettes/play_store/product_acknowledgements/refunded.yml +122 -0
  38. data/spec/fixtures/vcr_cassettes/play_store/product_purchases/permission_denied.yml +196 -0
  39. data/spec/fixtures/vcr_cassettes/play_store/product_purchases/response_with_empty_body.yml +183 -0
  40. data/spec/fixtures/vcr_cassettes/play_store/product_purchases/valid_but_not_consumed.yml +122 -0
  41. data/spec/fixtures/vcr_cassettes/play_store/subscription_purchases/permission_denied.yml +196 -0
  42. data/spec/fixtures/vcr_cassettes/play_store/subscription_purchases/valid_but_expired.yml +127 -0
  43. data/spec/play_store/acknowledger_spec.rb +48 -0
  44. data/spec/play_store/product_acknowledgements/acknowledgement_spec.rb +54 -0
  45. data/spec/play_store/product_acknowledgements/response_spec.rb +66 -0
  46. data/spec/play_store/product_purchases/product_purchase_spec.rb +110 -0
  47. data/spec/play_store/product_purchases/product_verification_spec.rb +49 -0
  48. data/spec/play_store/subscription_purchases/subscription_purchase_spec.rb +237 -0
  49. data/spec/play_store/subscription_purchases/subscription_verification_spec.rb +65 -0
  50. data/spec/play_store/verification_failure_spec.rb +18 -18
  51. data/spec/play_store/verifier_spec.rb +32 -96
  52. data/spec/spec_helper.rb +32 -10
  53. metadata +175 -75
  54. data/lib/candy_check/play_store/client.rb +0 -126
  55. data/lib/candy_check/play_store/config.rb +0 -51
  56. data/lib/candy_check/play_store/discovery_repository.rb +0 -33
  57. data/lib/candy_check/play_store/receipt.rb +0 -81
  58. data/lib/candy_check/play_store/subscription.rb +0 -138
  59. data/lib/candy_check/play_store/subscription_verification.rb +0 -30
  60. data/lib/candy_check/play_store/verification.rb +0 -48
  61. data/spec/fixtures/api_cache.dump +0 -1
  62. data/spec/fixtures/play_store/api_cache.dump +0 -1
  63. data/spec/fixtures/play_store/auth_failure.txt +0 -18
  64. data/spec/fixtures/play_store/auth_success.txt +0 -20
  65. data/spec/fixtures/play_store/discovery.txt +0 -2841
  66. data/spec/fixtures/play_store/dummy.p12 +0 -0
  67. data/spec/fixtures/play_store/empty.txt +0 -17
  68. data/spec/fixtures/play_store/products_failure.txt +0 -29
  69. data/spec/fixtures/play_store/products_success.txt +0 -22
  70. data/spec/play_store/client_spec.rb +0 -125
  71. data/spec/play_store/config_spec.rb +0 -96
  72. data/spec/play_store/discovery_respository_spec.rb +0 -31
  73. data/spec/play_store/receipt_spec.rb +0 -88
  74. data/spec/play_store/subscription_spec.rb +0 -138
  75. data/spec/play_store/subscription_verification_spec.rb +0 -98
  76. data/spec/play_store/verification_spec.rb +0 -82
@@ -1,98 +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!
89
- end
90
-
91
- def verify_subscription(package, product_id, token)
92
- @package = package
93
- @product_id = product_id
94
- @token = token
95
- response
96
- end
97
- end
98
- end
@@ -1,82 +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!
73
- end
74
-
75
- def verify(package, product_id, token)
76
- @package = package
77
- @product_id = product_id
78
- @token = token
79
- response
80
- end
81
- end
82
- end