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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b8e5a49cefe2bedd26a02e959b6c8eb24aebb37ff5b434cc9ab2491449d2db68
4
- data.tar.gz: ab2217bc86dbbf8277dc66f73368e9e6cde96c435e82c37a681dd93708c2aa34
3
+ metadata.gz: 26bbc91ee368037baee3d85fa6271832140444241e8569fb43b053aa9051a56a
4
+ data.tar.gz: b8d8565264058d8c01df8409264560d44f739f2560a0ecdc39539cea99dfd363
5
5
  SHA512:
6
- metadata.gz: d6da4a1ee4c6f89cb585db622ab2a79be2fbea74b365a9f7967d197adbfbd116b555936b010a22064d1c50b99f9912e7b03dda6c3285680f9018407cfe226a66
7
- data.tar.gz: fcf05f255081a6754289c3c459b0b86f5b83578681a786391cdf5229b108b926caa202f5663972c8b2c36fdbd74cbc9b2ad2069fbce515af249fa7c806aaea7d
6
+ metadata.gz: 06d81dc83b4a9e21b88a8cd6ccb5740229724d0598cc00a0dd167058a2f14ceb9362ca730c6e0d178d79ac7c19b197da18e6c2406895b9b408c2f0a3368bfbee
7
+ data.tar.gz: 210bbeb7e75b62847d3444862a7a64b8cf81d9f3c47145a93fe71f609ebc3581bf37d160a233f64d054f1cbd15a814026492f74bdae787b99ea4a4a90c877fd1
@@ -17,6 +17,10 @@ module Tarpon
17
17
  def expires_date
18
18
  Time.iso8601(@raw[:expires_date])
19
19
  end
20
+
21
+ def purchase_date
22
+ Time.iso8601(@raw[:purchase_date])
23
+ end
20
24
  end
21
25
  end
22
26
  end
@@ -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
@@ -5,4 +5,6 @@ module Tarpon
5
5
  class TimeoutError < Error; end
6
6
  class InvalidCredentialsError < Error; end
7
7
  class ServerError < Error; end
8
+ class NotFoundError < Error; end
9
+ class TooManyRequests < Error; end
8
10
  end
@@ -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 { |response| handle_response(response) }
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
- def translate_key(key)
27
- Client.send("#{key}_api_key")
26
+ private
27
+
28
+ def api_key(type)
29
+ Client.send("#{type}_api_key")
28
30
  end
29
31
 
30
- private
32
+ def parse_body(http_response)
33
+ return {} if http_response.body.empty?
31
34
 
32
- def handle_response(response)
33
- case response.code
34
- when 401
35
- raise Tarpon::InvalidCredentialsError,
36
- 'Invalid credentials, fix your API keys'
37
- when 500..505
38
- raise Tarpon::ServerError,
39
- 'RevenueCat failed to fulfill the request'
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
- Tarpon::Response.new(response.status, parse_body(response.body))
47
+ handle_error(http_response)
42
48
  end
43
49
  end
44
50
 
45
- def parse_body(body)
46
- JSON.parse(body, symbolize_names: true)
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
@@ -10,6 +10,10 @@ module Tarpon
10
10
  @subscriber = @raw[:subscriber].nil? ? nil : Entity::Subscriber.new(@raw[:subscriber])
11
11
  end
12
12
 
13
+ def message
14
+ @raw[:message]
15
+ end
16
+
13
17
  def success?
14
18
  @status.success?
15
19
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Tarpon
4
- VERSION = '0.1.1'
4
+ VERSION = '0.3.1'
5
5
  end
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.1.1
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: 2020-02-19 00:00:00.000000000 Z
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: '10.0'
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: '10.0'
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 ruby interface to RevenueCat REST API
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.0.3
157
+ rubygems_version: 3.1.6
153
158
  signing_key:
154
159
  specification_version: 4
155
- summary: A ruby interface to RevenueCat REST API
160
+ summary: A Ruby interface to RevenueCat REST API
156
161
  test_files: []