iap_verifier 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +14 -0
- data/README.md +0 -1
- data/iap_verifier.gemspec +0 -3
- data/lib/iap_verifier.rb +0 -1
- data/lib/iap_verifier/error.rb +3 -3
- data/lib/iap_verifier/receipt.rb +0 -4
- data/lib/iap_verifier/request.rb +18 -14
- data/lib/iap_verifier/response_data.rb +11 -5
- data/lib/iap_verifier/version.rb +1 -1
- data/test/response_data_test.rb +13 -8
- metadata +2 -33
- data/lib/iap_verifier/request_data.rb +0 -17
- data/test/request_data_test.rb +0 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 12b8929ff939efa3791342dea19cb317a0a7fc85
|
4
|
+
data.tar.gz: 106416c9890832238e63870e29561eed5a451a3c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3e5ed21ace584601597c4446e9a559af34ea8b24cd907024ed0fb2f475d792e39b55424f7d5147c779cca2b261fd373de8496f70146125288001513477a3aba1
|
7
|
+
data.tar.gz: 6556e1ab3f7397dc8fbf8e796ae58f7c273b120f5755d50abc993d8c836b1c53f7f9266b104ad07326023e7c623a81407e03d560a338cc9e72049cdb8c5f343a
|
data/CHANGELOG.md
CHANGED
@@ -2,13 +2,27 @@
|
|
2
2
|
|
3
3
|
## master
|
4
4
|
|
5
|
+
## v0.3.0
|
6
|
+
|
7
|
+
Improvement
|
8
|
+
|
9
|
+
* Handle malformed response from Apple's server.
|
10
|
+
* Remove external dependencies (Oj and HTTPClient).
|
11
|
+
|
5
12
|
## v0.2.0
|
6
13
|
|
14
|
+
Fix
|
15
|
+
|
7
16
|
* Fixes OpenSSL::SSL::SSLError [#1](https://github.com/linjunpop/iap_verifier/pull/1)
|
17
|
+
|
18
|
+
Improvement
|
19
|
+
|
8
20
|
* curb is not thread-safe, [httpclient](https://github.com/nahi/httpclient) does.
|
9
21
|
|
10
22
|
## v0.1.0
|
11
23
|
|
24
|
+
Improvement
|
25
|
+
|
12
26
|
* Use [oj](https://github.com/ohler55/oj) to load JSON.
|
13
27
|
* Use [curb](https://github.com/taf2/curb) as http client.
|
14
28
|
* Support ruby 1.9 & 2.0.
|
data/README.md
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
# IAPVerifier
|
2
2
|
|
3
3
|
[![Build Status](https://travis-ci.org/linjunpop/iap_verifier.svg)](https://travis-ci.org/linjunpop/iap_verifier)
|
4
|
-
[![Dependency Status](http://img.shields.io/gemnasium/linjunpop/iap_verifier.svg)](https://gemnasium.com/linjunpop/iap_verifier)
|
5
4
|
[![Code Climate](http://img.shields.io/codeclimate/github/linjunpop/iap_verifier.svg)](https://codeclimate.com/github/linjunpop/iap_verifier)
|
6
5
|
[![Gem Version](http://img.shields.io/gem/v/iap_verifier.svg)](https://rubygems.org/gems/iap_verifier)
|
7
6
|
[![License](http://img.shields.io/:license-mit-blue.svg)](http://linjunpop.mit-license.org)
|
data/iap_verifier.gemspec
CHANGED
@@ -18,9 +18,6 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
spec.add_runtime_dependency 'httpclient'
|
22
|
-
spec.add_runtime_dependency 'oj'
|
23
|
-
|
24
21
|
spec.add_development_dependency "bundler", "~> 1.6"
|
25
22
|
spec.add_development_dependency "rake"
|
26
23
|
spec.add_development_dependency "pry"
|
data/lib/iap_verifier.rb
CHANGED
data/lib/iap_verifier/error.rb
CHANGED
@@ -18,17 +18,17 @@ module IAPVerifier
|
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
|
-
class
|
21
|
+
class MalformedResponseData < Standard
|
22
22
|
def initialize(data)
|
23
23
|
@data = data
|
24
24
|
end
|
25
25
|
|
26
26
|
def message
|
27
|
-
"Malformed
|
27
|
+
"Malformed response from Apple Server: #{data}"
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
|
-
class
|
31
|
+
class InvalidReceiptData < Standard
|
32
32
|
MESSAGES = {
|
33
33
|
21000 => "App store could not read",
|
34
34
|
21002 => "Data was malformed",
|
data/lib/iap_verifier/receipt.rb
CHANGED
@@ -3,10 +3,6 @@ module IAPVerifier
|
|
3
3
|
def initialize(response_data)
|
4
4
|
@receipt_data = response_data['receipt']
|
5
5
|
|
6
|
-
unless @receipt_data.is_a?(Hash)
|
7
|
-
raise Error::MalformedReceiptData
|
8
|
-
end
|
9
|
-
|
10
6
|
@receipt_data.each do |key, value|
|
11
7
|
define_singleton_method key.to_s, -> { value }
|
12
8
|
end
|
data/lib/iap_verifier/request.rb
CHANGED
@@ -1,7 +1,3 @@
|
|
1
|
-
require 'json'
|
2
|
-
require 'httpclient'
|
3
|
-
require 'oj'
|
4
|
-
|
5
1
|
module IAPVerifier
|
6
2
|
class Request
|
7
3
|
PRODUCTION_URL = "https://buy.itunes.apple.com/verifyReceipt"
|
@@ -12,7 +8,9 @@ module IAPVerifier
|
|
12
8
|
raise Error::EmptyReceipt.new
|
13
9
|
end
|
14
10
|
|
15
|
-
@request_data =
|
11
|
+
@request_data = {
|
12
|
+
'receipt-data' => receipt
|
13
|
+
}
|
16
14
|
end
|
17
15
|
|
18
16
|
def response
|
@@ -32,15 +30,21 @@ module IAPVerifier
|
|
32
30
|
end
|
33
31
|
|
34
32
|
def verify(request_data, url)
|
35
|
-
|
36
|
-
http.
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
33
|
+
uri = URI(url)
|
34
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
35
|
+
http.use_ssl = true
|
36
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
37
|
+
|
38
|
+
request = Net::HTTP::Post.new(uri.request_uri)
|
39
|
+
|
40
|
+
request['Accept'] = "application/json"
|
41
|
+
request['Content-Type'] = "application/json"
|
42
|
+
|
43
|
+
request.body = request_data.to_json
|
44
|
+
|
45
|
+
response = http.request(request)
|
46
|
+
|
47
|
+
ResponseData.new(response.body)
|
44
48
|
end
|
45
49
|
end
|
46
50
|
end
|
@@ -1,10 +1,16 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
1
3
|
module IAPVerifier
|
2
4
|
class ResponseData
|
3
|
-
SUCCESS_RESPONSE_CODE = 0
|
4
|
-
SANDBOX_RECEIPT_CODE = 21007
|
5
|
+
SUCCESS_RESPONSE_CODE = 0.freeze
|
6
|
+
SANDBOX_RECEIPT_CODE = 21007.freeze
|
7
|
+
|
8
|
+
def initialize(json)
|
9
|
+
@response_data = JSON.parse(json)
|
5
10
|
|
6
|
-
|
7
|
-
|
11
|
+
raise Error::MalformedResponseData.new(json) unless @response_data.is_a?(Hash)
|
12
|
+
rescue JSON::ParserError
|
13
|
+
raise Error::MalformedResponseData.new(json)
|
8
14
|
end
|
9
15
|
|
10
16
|
def valid?
|
@@ -19,7 +25,7 @@ module IAPVerifier
|
|
19
25
|
if valid?
|
20
26
|
Receipt.new(@response_data)
|
21
27
|
else
|
22
|
-
raise Error::
|
28
|
+
raise Error::InvalidReceiptData.new(status_code)
|
23
29
|
end
|
24
30
|
end
|
25
31
|
|
data/lib/iap_verifier/version.rb
CHANGED
data/test/response_data_test.rb
CHANGED
@@ -5,14 +5,14 @@ require 'iap_verifier/error'
|
|
5
5
|
|
6
6
|
class ResponseDataTest < MiniTest::Test
|
7
7
|
def test_success_response_json
|
8
|
-
success_response_json = { 'status' => 0, 'receipt' => { } }
|
8
|
+
success_response_json = { 'status' => 0, 'receipt' => { } }.to_json
|
9
9
|
response_data = IAPVerifier::ResponseData.new(success_response_json)
|
10
10
|
|
11
11
|
assert_equal true, response_data.valid?
|
12
12
|
end
|
13
13
|
|
14
14
|
def test_error_response_json
|
15
|
-
error_response_json = { 'status' => 21002 }
|
15
|
+
error_response_json = { 'status' => 21002 }.to_json
|
16
16
|
response_data = IAPVerifier::ResponseData.new(error_response_json)
|
17
17
|
|
18
18
|
assert_equal false, response_data.valid?
|
@@ -20,7 +20,7 @@ class ResponseDataTest < MiniTest::Test
|
|
20
20
|
|
21
21
|
def test_sandbox_response_json
|
22
22
|
# sandbox receipt sent to production server
|
23
|
-
sandbox_response_json = { 'status' => 21007 }
|
23
|
+
sandbox_response_json = { 'status' => 21007 }.to_json
|
24
24
|
response_data = IAPVerifier::ResponseData.new(sandbox_response_json)
|
25
25
|
|
26
26
|
assert_equal false, response_data.valid?
|
@@ -28,17 +28,22 @@ class ResponseDataTest < MiniTest::Test
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def test_receipt
|
31
|
-
response_data = IAPVerifier::ResponseData.new({ 'receipt' => { } })
|
31
|
+
response_data = IAPVerifier::ResponseData.new({ 'receipt' => { } }.to_json)
|
32
32
|
response_data.stubs(:valid?).returns(true)
|
33
33
|
|
34
34
|
assert_equal true, response_data.receipt.instance_of?(IAPVerifier::Receipt)
|
35
35
|
end
|
36
36
|
|
37
|
-
def
|
38
|
-
assert_raises(IAPVerifier::Error::
|
39
|
-
|
40
|
-
|
37
|
+
def test_malformed_response_data
|
38
|
+
assert_raises(IAPVerifier::Error::MalformedResponseData) do
|
39
|
+
IAPVerifier::ResponseData.new('')
|
40
|
+
end
|
41
|
+
end
|
41
42
|
|
43
|
+
def text_invalid_receipt_data
|
44
|
+
assert_raises(IAPVerifier::Error::InvalidReceiptData) do
|
45
|
+
IAPVerifier::ResponseData.new({ 'receipt' => { } }.to_json)
|
46
|
+
response_data.stubs(:valid?).returns(false)
|
42
47
|
response_data.receipt
|
43
48
|
end
|
44
49
|
end
|
metadata
CHANGED
@@ -1,43 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: iap_verifier
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jun Lin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-01-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: httpclient
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - ">="
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '0'
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - ">="
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '0'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: oj
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ">="
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
34
|
-
type: :runtime
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - ">="
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
41
13
|
- !ruby/object:Gem::Dependency
|
42
14
|
name: bundler
|
43
15
|
requirement: !ruby/object:Gem::Requirement
|
@@ -155,13 +127,11 @@ files:
|
|
155
127
|
- lib/iap_verifier/error.rb
|
156
128
|
- lib/iap_verifier/receipt.rb
|
157
129
|
- lib/iap_verifier/request.rb
|
158
|
-
- lib/iap_verifier/request_data.rb
|
159
130
|
- lib/iap_verifier/response_data.rb
|
160
131
|
- lib/iap_verifier/version.rb
|
161
132
|
- test/fixtures/base64_receipt
|
162
133
|
- test/fixtures/vcr_cassettes/valid_receipt.yml
|
163
134
|
- test/receipt_test.rb
|
164
|
-
- test/request_data_test.rb
|
165
135
|
- test/request_test.rb
|
166
136
|
- test/response_data_test.rb
|
167
137
|
- test/test_helper.rb
|
@@ -193,7 +163,6 @@ test_files:
|
|
193
163
|
- test/fixtures/base64_receipt
|
194
164
|
- test/fixtures/vcr_cassettes/valid_receipt.yml
|
195
165
|
- test/receipt_test.rb
|
196
|
-
- test/request_data_test.rb
|
197
166
|
- test/request_test.rb
|
198
167
|
- test/response_data_test.rb
|
199
168
|
- test/test_helper.rb
|
data/test/request_data_test.rb
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'iap_verifier/request_data'
|
3
|
-
|
4
|
-
class RequestDataTest < MiniTest::Test
|
5
|
-
def test_base64_receipt
|
6
|
-
receipt = File.read(File.expand_path("../fixtures/base64_receipt", __FILE__))
|
7
|
-
|
8
|
-
expected = {
|
9
|
-
'receipt-data' => receipt
|
10
|
-
}
|
11
|
-
assert_equal expected, IAPVerifier::RequestData.new(receipt).to_h
|
12
|
-
end
|
13
|
-
end
|