verona 0.0.1 → 0.0.2

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: a4e61f2037f343a773bb7dc01c3ea24ac04ebb79
4
- data.tar.gz: d7fdbae52c02fb72c9cd733308fbdcbbdaa273a9
3
+ metadata.gz: b8c564fdf5f2e92ba547ef8745ab219f6ac6b7f9
4
+ data.tar.gz: 2c8d5822f4db98bdd26381956995faf050a861a3
5
5
  SHA512:
6
- metadata.gz: d8e2cda02adc454441cd4c4bbd08987040bd0f98b1ce2a2063ee6262d873b036c04e55ed21b373954c6462feb814ec3fcfbb765f2b82fd4d6e6968ea72c1e0ad
7
- data.tar.gz: 25b256850eab9e4976c55765293433a1fb5bc365e1018ab1266f524727bed133e9c80b1a941cb5e94842f37e3ef253287903fc9ffbe52f121f44820082dfc5e0
6
+ metadata.gz: ce377640a3b89c515a8de69c3f2d8d1872212849d6cea9e38af931c0333b751503efaacb809b49483312a9b48f3340524a3272b85e133ad0df2eba437636e3e6
7
+ data.tar.gz: 4abc69a091b0a03339c5fa5901a155f8b48b2ef751028617c19ad03725ec3d9e621830b9d3ca3cd1ba4ab68ae9c18e71a02db4aa4d52a6d75e1869e99131a01b
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- verona (0.0.1)
4
+ verona (0.0.2)
5
5
  json
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -2,7 +2,7 @@ Verona is a simple gem for verifying Google Play In-App Purchase tokens, and ret
2
2
 
3
3
  There are two reasons why you should verify in-app purchase receipts on the server: First, it allows you to keep your own records of past purchases, which is useful for up-to-the-minute metrics and historical analysis. Second, server-side verification over SSL is the most reliable way to determine the authenticity of purchasing records.
4
4
 
5
- Verona is based on @mattt's ![Venice](https://github.com/nomad/venice) gem for iOS In-App Purchase verification.
5
+ Verona is based on [@mattt's](http://twitter.com/mattt) [Venice](https://github.com/nomad/venice) gem for iOS In-App Purchase verification.
6
6
 
7
7
  ## Installation
8
8
 
@@ -10,6 +10,14 @@ Verona is based on @mattt's ![Venice](https://github.com/nomad/venice) gem for i
10
10
 
11
11
  ## Usage
12
12
 
13
+ First, ensure that you have a valid the following environment variables set up:
14
+
15
+ - `GOOGLE_PLAY_CLIENT_ID`
16
+ - `GOOGLE_PLAY_CLIENT_SECRET`
17
+ - `GOOGLE_PLAY_REFRESH_TOKEN`
18
+
19
+ You can get these from The [Google Developer Website](https://developers.google.com/android-publisher/authorization).
20
+
13
21
  ```ruby
14
22
  require 'verona'
15
23
 
@@ -28,7 +36,7 @@ Simon Maddox
28
36
 
29
37
  - http://github.com/simonmaddox
30
38
  - http://twitter.com/simonmaddox
31
- simon@simonmaddox.com
39
+ - simon@simonmaddox.com
32
40
 
33
41
  ## License
34
42
 
data/lib/verona/client.rb CHANGED
@@ -4,6 +4,11 @@ require 'uri'
4
4
 
5
5
  module Verona
6
6
  class Client
7
+
8
+ def initialize
9
+ refresh_access_token
10
+ end
11
+
7
12
  def verify!(attributes = {}, options)
8
13
  json = json_response_from_verifying_token(attributes)
9
14
  error = json['error'] if json['error']
@@ -25,11 +30,37 @@ module Verona
25
30
  request = Net::HTTP::Get.new(uri.request_uri)
26
31
  request['Accept'] = "application/json"
27
32
  request['Content-Type'] = "application/json"
28
- request['Authorization'] = "Bearer #{ENV['GOOGLE_PLAY_ACCESS_TOKEN']}"
33
+ request['Authorization'] = "Bearer #{@current_access_token}"
29
34
 
30
35
  response = http.request(request)
31
36
 
32
- JSON.parse(response.body)
37
+ if response.class.eql? Net::HTTPUnauthorized
38
+ refresh_access_token
39
+ json_response_from_verifying_token(attributes)
40
+ else
41
+ JSON.parse(response.body)
42
+ end
33
43
  end
44
+
45
+ def refresh_access_token
46
+ uri = URI("https://accounts.google.com/o/oauth2/token")
47
+ http = Net::HTTP.new(uri.host, uri.port)
48
+ http.use_ssl = true
49
+ http.verify_mode = OpenSSL::SSL::VERIFY_PEER
50
+
51
+ request = Net::HTTP::Post.new(uri.request_uri)
52
+ request.set_form_data(
53
+ {
54
+ "grant_type" => "refresh_token",
55
+ "refresh_token" => ENV['GOOGLE_PLAY_REFRESH_TOKEN'],
56
+ "client_id" => ENV['GOOGLE_PLAY_CLIENT_ID'],
57
+ "client_secret" => ENV['GOOGLE_PLAY_CLIENT_SECRET'],
58
+ })
59
+ response = http.request(request)
60
+ json = JSON.parse(response.body)
61
+
62
+ @current_access_token = json['access_token'] if json['access_token']
63
+ end
64
+
34
65
  end
35
66
  end
@@ -1,3 +1,3 @@
1
1
  module Verona
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/verona-0.0.1.gem ADDED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: verona
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Simon Maddox
@@ -39,6 +39,7 @@ files:
39
39
  - ./LICENSE
40
40
  - ./Rakefile
41
41
  - ./README.md
42
+ - ./verona-0.0.1.gem
42
43
  - ./verona.gemspec
43
44
  homepage: http://simonmaddox.com
44
45
  licenses: