amazon-iap 0.1.0 → 0.1.1
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.
- data/README.md +62 -4
- data/lib/amazon/iap/result.rb +7 -2
- data/lib/amazon/iap/version.rb +1 -1
- metadata +2 -2
data/README.md
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# Amazon::Iap
|
2
2
|
|
3
|
-
|
3
|
+
This gem is a simple implementation of the Amazon receipt verfication service outlined
|
4
|
+
[here](https://developer.amazon.com/sdk/in-app-purchasing/documentation/rvs.html).
|
5
|
+
|
4
6
|
|
5
7
|
## Installation
|
6
8
|
|
@@ -18,12 +20,68 @@ Or install it yourself as:
|
|
18
20
|
|
19
21
|
## Usage
|
20
22
|
|
21
|
-
|
23
|
+
**NOTE:** Amazon does not deploy a sandbox environment for testing purposes. Rather,
|
24
|
+
they give you access to a deployable WAR file. You can use this WAR file to easily deploy your
|
25
|
+
own sandbox environment on Heroku. See [here](https://devcenter.heroku.com/articles/war-deployment#command-line)
|
26
|
+
for more details.
|
27
|
+
|
28
|
+
Initialize a client, passing in the developer secret and (optionally) the host. If a host is not
|
29
|
+
passed, it will use Amazon's production endpoint.
|
30
|
+
|
31
|
+
client = Amazon::Iap::Client.new 'my_developer_secret', 'http://iap-staging.domain.com'
|
32
|
+
|
33
|
+
From there, you can call either `verify` or `renew` on the client and pass in the user id and purchase token:
|
34
|
+
|
35
|
+
result = client.verify 'some-user-id', 'some-purchase-token'
|
36
|
+
result = client.renew 'some-user-id', 'some-purchase-token'
|
37
|
+
|
38
|
+
By default, the `verify` method will automatically try to renew expired tokens, and will recall `verify`
|
39
|
+
against the new token returned. If you do not want this behavior, simply pass in `false` as the third
|
40
|
+
attribute to the `verify` method:
|
41
|
+
|
42
|
+
result = client.verify 'some-user-id', 'some-purchase-token', false
|
43
|
+
|
44
|
+
## Returned Values
|
45
|
+
|
46
|
+
An instance of Amazon::Iap::Result is returned from both methods, the attributes being the underscored versions
|
47
|
+
of the hash keys returned in the JSON object. For convenience, we also add `start_time` and `end_time` attributes
|
48
|
+
which are `Time` representations of the milliseconds returned in `start_date` and `end_date` respectively. E.g.,
|
49
|
+
|
50
|
+
result = client.verify 'some-user-id', 'some-purchase-token'
|
51
|
+
|
52
|
+
result.class.name # "Amazon::Iap::Result"
|
53
|
+
result.item_type # "SUBSCRIPTION"
|
54
|
+
result.sku # "some-sku"
|
55
|
+
result.start_date # 1378751554943
|
56
|
+
result.start_time # 2013-09-09 14:32:34 -0400
|
57
|
+
result.end_date # nil
|
58
|
+
result.end_time # nil
|
59
|
+
result.purchase_token # "some-purchase-token"
|
60
|
+
|
61
|
+
<!-- -->
|
62
|
+
|
63
|
+
result = client.renew 'some-user-id', 'some-purchase-token'
|
64
|
+
|
65
|
+
result.class.name # "Amazon::Iap::Result"
|
66
|
+
result.purchase_token # "some-new-purchase-token"
|
67
|
+
|
68
|
+
## Exception Handling
|
69
|
+
|
70
|
+
Any non-200 status code will raise an exception. For convenience in internal controls, each status code raises
|
71
|
+
a distinct exception. Take a look at the [Amazon::Iap::Result class](lib/amazon/iap/result.rb) for specifics.
|
72
|
+
|
73
|
+
Example exception handling:
|
74
|
+
|
75
|
+
begin
|
76
|
+
result = client.verify 'some-user-id', 'some-purchase-token'
|
77
|
+
rescue Amazon::Iap::Exceptions::InternalError => e
|
78
|
+
# enqueue to try again later
|
79
|
+
end
|
22
80
|
|
23
81
|
## Contributing
|
24
82
|
|
25
83
|
1. Fork it
|
26
|
-
2. Create your feature branch (`git checkout -b
|
84
|
+
2. Create your feature branch (`git checkout -b some-new-feature`)
|
27
85
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
-
4. Push to the branch (`git push origin
|
86
|
+
4. Push to the branch (`git push origin some-new-feature`)
|
29
87
|
5. Create new Pull Request
|
data/lib/amazon/iap/result.rb
CHANGED
@@ -5,8 +5,13 @@ class Amazon::Iap::Result
|
|
5
5
|
case response.code.to_i
|
6
6
|
when 200
|
7
7
|
parsed = JSON.parse(response.body)
|
8
|
-
|
9
|
-
|
8
|
+
|
9
|
+
if parsed.has_key? 'startDate'
|
10
|
+
parsed['startTime'] = parsed['startDate'].nil? ? nil : Time.at(parsed['startDate'] / 1000)
|
11
|
+
end
|
12
|
+
if parsed.has_key? 'endDate'
|
13
|
+
parsed['endTime'] = parsed['endDate'].nil? ? nil : Time.at(parsed['endDate'] / 1000)
|
14
|
+
end
|
10
15
|
|
11
16
|
parsed.each do |key, value|
|
12
17
|
underscore = key.gsub(/::/, '/').gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').gsub(/([a-z\d])([A-Z])/, '\1_\2').tr('-', '_').downcase
|
data/lib/amazon/iap/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: amazon-iap
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-09-
|
12
|
+
date: 2013-09-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|