tarpon 0.1.1 → 0.3.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.
- checksums.yaml +4 -4
- data/lib/tarpon/entity/entitlement.rb +4 -0
- data/lib/tarpon/entity/offering.rb +18 -0
- data/lib/tarpon/entity/offerings.rb +28 -0
- data/lib/tarpon/errors.rb +2 -0
- data/lib/tarpon/request/base.rb +34 -17
- data/lib/tarpon/request/subscriber/entitlement.rb +33 -0
- data/lib/tarpon/request/subscriber/offering.rb +28 -0
- data/lib/tarpon/request/subscriber/subscription.rb +26 -0
- data/lib/tarpon/request/subscriber.rb +4 -45
- data/lib/tarpon/response.rb +4 -0
- data/lib/tarpon/version.rb +1 -1
- data/lib/tarpon.rb +3 -0
- metadata +14 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 26bbc91ee368037baee3d85fa6271832140444241e8569fb43b053aa9051a56a
|
4
|
+
data.tar.gz: b8d8565264058d8c01df8409264560d44f739f2560a0ecdc39539cea99dfd363
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 06d81dc83b4a9e21b88a8cd6ccb5740229724d0598cc00a0dd167058a2f14ceb9362ca730c6e0d178d79ac7c19b197da18e6c2406895b9b408c2f0a3368bfbee
|
7
|
+
data.tar.gz: 210bbeb7e75b62847d3444862a7a64b8cf81d9f3c47145a93fe71f609ebc3581bf37d160a233f64d054f1cbd15a814026492f74bdae787b99ea4a4a90c877fd1
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Tarpon
|
4
|
+
module Entity
|
5
|
+
Package = Struct.new(:identifier, :platform_identifier)
|
6
|
+
class Offering
|
7
|
+
attr_reader :identifier, :description, :packages
|
8
|
+
|
9
|
+
def initialize(identifier:, description:, packages:, **)
|
10
|
+
@identifier = identifier
|
11
|
+
@description = description
|
12
|
+
@packages = packages.map do |package|
|
13
|
+
Package.new(package[:identifier], package[:platform_product_identifier])
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'tarpon/entity/offering'
|
4
|
+
|
5
|
+
module Tarpon
|
6
|
+
module Entity
|
7
|
+
class Offerings
|
8
|
+
include Enumerable
|
9
|
+
|
10
|
+
attr_reader :current_offering_id, :offerings
|
11
|
+
|
12
|
+
def initialize(current_offering_id:, offerings:, **)
|
13
|
+
@current_offering_id = current_offering_id
|
14
|
+
@offerings = offerings.each_with_object({}) do |offering, map|
|
15
|
+
map[offering[:identifier].to_sym] = Tarpon::Entity::Offering.new(offering)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def each
|
20
|
+
@offerings.each { |o| yield o }
|
21
|
+
end
|
22
|
+
|
23
|
+
def [](identifier)
|
24
|
+
@offerings[identifier.to_sym]
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/tarpon/errors.rb
CHANGED
data/lib/tarpon/request/base.rb
CHANGED
@@ -14,36 +14,53 @@ module Tarpon
|
|
14
14
|
|
15
15
|
def perform(method:, path:, key:, headers: {}, body: nil)
|
16
16
|
HTTP
|
17
|
-
.auth("Bearer #{translate_key(key)}")
|
18
|
-
.headers(headers.merge(DEFAULT_HEADERS))
|
19
17
|
.timeout(Client.timeout)
|
18
|
+
.auth("Bearer #{api_key(key)}")
|
19
|
+
.headers(headers.merge(DEFAULT_HEADERS))
|
20
20
|
.send(method, "#{Client.base_uri}#{path}", json: body&.compact)
|
21
|
-
.yield_self { |
|
21
|
+
.yield_self { |http_response| handle_response(http_response) }
|
22
22
|
rescue HTTP::TimeoutError => e
|
23
23
|
raise Tarpon::TimeoutError, e
|
24
24
|
end
|
25
25
|
|
26
|
-
|
27
|
-
|
26
|
+
private
|
27
|
+
|
28
|
+
def api_key(type)
|
29
|
+
Client.send("#{type}_api_key")
|
28
30
|
end
|
29
31
|
|
30
|
-
|
32
|
+
def parse_body(http_response)
|
33
|
+
return {} if http_response.body.empty?
|
31
34
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
35
|
+
JSON.parse(http_response.body.to_s, symbolize_names: true)
|
36
|
+
end
|
37
|
+
|
38
|
+
def create_response(http_response)
|
39
|
+
Tarpon::Response.new(http_response.status, parse_body(http_response))
|
40
|
+
end
|
41
|
+
|
42
|
+
def handle_response(http_response)
|
43
|
+
case http_response.code
|
44
|
+
when 200..299
|
45
|
+
create_response(http_response)
|
40
46
|
else
|
41
|
-
|
47
|
+
handle_error(http_response)
|
42
48
|
end
|
43
49
|
end
|
44
50
|
|
45
|
-
def
|
46
|
-
|
51
|
+
def handle_error(http_response)
|
52
|
+
case http_response.code
|
53
|
+
when 401
|
54
|
+
raise Tarpon::InvalidCredentialsError, 'Invalid credentials, fix your API keys'
|
55
|
+
when 500..599
|
56
|
+
raise Tarpon::ServerError, 'RevenueCat failed to fulfill the request'
|
57
|
+
when 404
|
58
|
+
raise Tarpon::NotFoundError
|
59
|
+
when 429
|
60
|
+
raise Tarpon::TooManyRequests
|
61
|
+
else
|
62
|
+
create_response(http_response)
|
63
|
+
end
|
47
64
|
end
|
48
65
|
end
|
49
66
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Tarpon
|
4
|
+
module Request
|
5
|
+
class Subscriber
|
6
|
+
class Entitlement < Base
|
7
|
+
def initialize(subscriber_path:, entitlement_identifier:)
|
8
|
+
@subscriber_path = subscriber_path
|
9
|
+
@entitlement_identifier = entitlement_identifier
|
10
|
+
end
|
11
|
+
|
12
|
+
def grant_promotional(duration:, start_time_ms: nil)
|
13
|
+
body = {
|
14
|
+
duration: duration,
|
15
|
+
start_time_ms: start_time_ms
|
16
|
+
}
|
17
|
+
|
18
|
+
perform(method: :post, path: "#{path}/promotional", key: :secret, body: body)
|
19
|
+
end
|
20
|
+
|
21
|
+
def revoke_promotional
|
22
|
+
perform(method: :post, path: "#{path}/revoke_promotionals", key: :secret)
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def path
|
28
|
+
"#{@subscriber_path}/entitlements/#{@entitlement_identifier}"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'tarpon/entity/offerings'
|
4
|
+
|
5
|
+
module Tarpon
|
6
|
+
module Request
|
7
|
+
class Subscriber
|
8
|
+
class Offering < Base
|
9
|
+
def initialize(subscriber_path:)
|
10
|
+
@subscriber_path = subscriber_path
|
11
|
+
end
|
12
|
+
|
13
|
+
def list(platform)
|
14
|
+
response = perform(method: :get, path: path.to_s, headers: { 'x-platform': platform.to_s }, key: :public)
|
15
|
+
return response unless response.success?
|
16
|
+
|
17
|
+
Tarpon::Entity::Offerings.new(response.raw)
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def path
|
23
|
+
"#{@subscriber_path}/offerings"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Tarpon
|
4
|
+
module Request
|
5
|
+
class Subscriber
|
6
|
+
class Subscription < Base
|
7
|
+
def initialize(subscriber_path:, product_id:)
|
8
|
+
@subscriber_path = subscriber_path
|
9
|
+
@product_id = product_id
|
10
|
+
end
|
11
|
+
|
12
|
+
def defer(expiry_time_ms:)
|
13
|
+
body = { expiry_time_ms: expiry_time_ms }
|
14
|
+
|
15
|
+
perform(method: :post, path: "#{path}/defer", key: :secret, body: body)
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def path
|
21
|
+
"#{@subscriber_path}/subscriptions/#{@product_id}"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -21,6 +21,10 @@ module Tarpon
|
|
21
21
|
self.class::Entitlement.new(subscriber_path: path, entitlement_identifier: entitlement_identifier)
|
22
22
|
end
|
23
23
|
|
24
|
+
def offerings
|
25
|
+
self.class::Offering.new(subscriber_path: path)
|
26
|
+
end
|
27
|
+
|
24
28
|
def subscriptions(product_id)
|
25
29
|
self.class::Subscription.new(subscriber_path: path, product_id: product_id)
|
26
30
|
end
|
@@ -30,51 +34,6 @@ module Tarpon
|
|
30
34
|
def path
|
31
35
|
"/subscribers/#{@app_user_id}"
|
32
36
|
end
|
33
|
-
|
34
|
-
class Entitlement < Base
|
35
|
-
def initialize(subscriber_path:, entitlement_identifier:)
|
36
|
-
@subscriber_path = subscriber_path
|
37
|
-
@entitlement_identifier = entitlement_identifier
|
38
|
-
end
|
39
|
-
|
40
|
-
def grant_promotional(duration:, start_time_ms: nil)
|
41
|
-
body = {
|
42
|
-
duration: duration,
|
43
|
-
start_time_ms: start_time_ms
|
44
|
-
}
|
45
|
-
|
46
|
-
perform(method: :post, path: "#{path}/promotional", key: :secret, body: body)
|
47
|
-
end
|
48
|
-
|
49
|
-
def revoke_promotional
|
50
|
-
perform(method: :post, path: "#{path}/revoke_promotionals", key: :secret)
|
51
|
-
end
|
52
|
-
|
53
|
-
private
|
54
|
-
|
55
|
-
def path
|
56
|
-
"#{@subscriber_path}/entitlements/#{@entitlement_identifier}"
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
class Subscription < Base
|
61
|
-
def initialize(subscriber_path:, product_id:)
|
62
|
-
@subscriber_path = subscriber_path
|
63
|
-
@product_id = product_id
|
64
|
-
end
|
65
|
-
|
66
|
-
def defer(expiry_time_ms:)
|
67
|
-
body = { expiry_time_ms: expiry_time_ms }
|
68
|
-
|
69
|
-
perform(method: :post, path: "#{path}/defer", key: :secret, body: body)
|
70
|
-
end
|
71
|
-
|
72
|
-
private
|
73
|
-
|
74
|
-
def path
|
75
|
-
"#{@subscriber_path}/subscriptions/#{@product_id}"
|
76
|
-
end
|
77
|
-
end
|
78
37
|
end
|
79
38
|
end
|
80
39
|
end
|
data/lib/tarpon/response.rb
CHANGED
data/lib/tarpon/version.rb
CHANGED
data/lib/tarpon.rb
CHANGED
@@ -7,6 +7,9 @@ require 'tarpon/entity/subscriber'
|
|
7
7
|
require 'tarpon/errors'
|
8
8
|
require 'tarpon/request/base'
|
9
9
|
require 'tarpon/request/subscriber'
|
10
|
+
require 'tarpon/request/subscriber/entitlement'
|
11
|
+
require 'tarpon/request/subscriber/subscription'
|
12
|
+
require 'tarpon/request/subscriber/offering'
|
10
13
|
require 'tarpon/request/receipt'
|
11
14
|
require 'tarpon/response'
|
12
15
|
require 'tarpon/version'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tarpon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Igor Belo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-10-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: http
|
@@ -58,14 +58,14 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
61
|
+
version: '12.3'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
68
|
+
version: '12.3'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rspec
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -108,7 +108,7 @@ dependencies:
|
|
108
108
|
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '3.8'
|
111
|
-
description: A
|
111
|
+
description: A Ruby interface to RevenueCat REST API
|
112
112
|
email:
|
113
113
|
- igor.belo@fishbrain.com
|
114
114
|
executables: []
|
@@ -120,11 +120,16 @@ files:
|
|
120
120
|
- lib/tarpon/configuration.rb
|
121
121
|
- lib/tarpon/entity/entitlement.rb
|
122
122
|
- lib/tarpon/entity/entitlement_list.rb
|
123
|
+
- lib/tarpon/entity/offering.rb
|
124
|
+
- lib/tarpon/entity/offerings.rb
|
123
125
|
- lib/tarpon/entity/subscriber.rb
|
124
126
|
- lib/tarpon/errors.rb
|
125
127
|
- lib/tarpon/request/base.rb
|
126
128
|
- lib/tarpon/request/receipt.rb
|
127
129
|
- lib/tarpon/request/subscriber.rb
|
130
|
+
- lib/tarpon/request/subscriber/entitlement.rb
|
131
|
+
- lib/tarpon/request/subscriber/offering.rb
|
132
|
+
- lib/tarpon/request/subscriber/subscription.rb
|
128
133
|
- lib/tarpon/response.rb
|
129
134
|
- lib/tarpon/version.rb
|
130
135
|
homepage: https://github.com/fishbrain/tarpon
|
@@ -132,8 +137,8 @@ licenses:
|
|
132
137
|
- MIT
|
133
138
|
metadata:
|
134
139
|
homepage_uri: https://github.com/fishbrain/tarpon
|
135
|
-
source_code_uri: https://github.com/fishbrain/tarpon
|
136
|
-
changelog_uri: https://github.com/fishbrain/tarpon/CHANGELOG.md
|
140
|
+
source_code_uri: https://github.com/fishbrain/tarpon.git
|
141
|
+
changelog_uri: https://github.com/fishbrain/tarpon/blob/master/CHANGELOG.md
|
137
142
|
post_install_message:
|
138
143
|
rdoc_options: []
|
139
144
|
require_paths:
|
@@ -149,8 +154,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
149
154
|
- !ruby/object:Gem::Version
|
150
155
|
version: '0'
|
151
156
|
requirements: []
|
152
|
-
rubygems_version: 3.
|
157
|
+
rubygems_version: 3.1.6
|
153
158
|
signing_key:
|
154
159
|
specification_version: 4
|
155
|
-
summary: A
|
160
|
+
summary: A Ruby interface to RevenueCat REST API
|
156
161
|
test_files: []
|