tarpon 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9ca9c5d848e253fa9a464b757e8c8bd6457402233a87ef3c0fad624deb51323d
4
- data.tar.gz: e4a58e820eafd48096f00aee5954187427fea273374d8abeb550185c6f95784e
3
+ metadata.gz: 8d6acb3ebc1ea690eba860bd056c0de1e1bd225d82d27996c281415e82e8deca
4
+ data.tar.gz: e350303887989f6dd361e6d8a4517dc421be6ca29589120f677980b4ba046b20
5
5
  SHA512:
6
- metadata.gz: 07c5e934acf193a1811f6b2491381e5a6728756a00f46c2f899ecb0a975a39156f3d9df6ee76ba720b91a1a76a0a3eb7a22314af59e2f9d7fd96e33b7d782314
7
- data.tar.gz: ba78c1e53736671041b5768d44c624747ed598d06745589c2449c0d5c18566669b3bf9d271f050ea737a55d095b1444f43ff06511d2137061c6dfb3813a9a360
6
+ metadata.gz: 542d5d0781ff979ce7c51c5df96e54afe89830aa8f1570dc76b6326c7cd07519764d4d95b197cc66a6c9de1504093dcfe6819a89c3c97a3c011f3341da42d6e1
7
+ data.tar.gz: 79d50fa993c8d48c648bc81a7d9ef793278459445095b6703019d97dc8269d956afd073e15e7b8553303fe297672ec8b0e4cd3053fd5ec1993fce29e6bc3c754
data/lib/tarpon/client.rb CHANGED
@@ -1,19 +1,33 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'forwardable'
3
4
  require 'tarpon/configuration'
4
5
 
5
6
  module Tarpon
6
7
  class Client
7
- extend Configuration
8
+ include Configuration
9
+
10
+ def self.default
11
+ @default ||= new
12
+ end
13
+
14
+ def initialize(**config, &block)
15
+ config.each { |key, val| public_send("#{key}=", val) }
16
+ yield self if block
17
+ end
8
18
 
9
19
  class << self
10
- def subscriber(app_user_id)
11
- Request::Subscriber.new(app_user_id: app_user_id)
12
- end
20
+ extend Forwardable
21
+ def_delegators :default, *Configuration.public_instance_methods(true)
22
+ def_delegators :default, :subscriber, :receipt
23
+ end
24
+
25
+ def subscriber(app_user_id)
26
+ Request::Subscriber.new(app_user_id: app_user_id, client: self)
27
+ end
13
28
 
14
- def receipt
15
- Request::Receipt.new
16
- end
29
+ def receipt
30
+ Request::Receipt.new(client: self)
17
31
  end
18
32
  end
19
33
  end
@@ -3,7 +3,7 @@
3
3
  module Tarpon
4
4
  module Configuration
5
5
  attr_accessor :public_api_key, :secret_api_key
6
- attr_writer :base_uri, :timeout
6
+ attr_writer :base_uri, :timeout, :http_middleware
7
7
 
8
8
  def configure
9
9
  yield self
@@ -16,5 +16,9 @@ module Tarpon
16
16
  def timeout
17
17
  @timeout || 5
18
18
  end
19
+
20
+ def http_middleware
21
+ @http_middleware ||= ->(http_client) { http_client }
22
+ end
19
23
  end
20
24
  end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'http'
4
+ require 'tarpon/client'
4
5
 
5
6
  module Tarpon
6
7
  module Request
@@ -10,14 +11,19 @@ module Tarpon
10
11
  content_type: 'application/json'
11
12
  }.freeze
12
13
 
14
+ def initialize(client: Client.default)
15
+ @client = client
16
+ end
17
+
13
18
  protected
14
19
 
15
20
  def perform(method:, path:, key:, headers: {}, body: nil)
16
21
  HTTP
17
- .timeout(Client.timeout)
22
+ .timeout(@client.timeout)
23
+ .then { |http_client| @client.http_middleware.call(http_client) }
18
24
  .auth("Bearer #{api_key(key)}")
19
25
  .headers(headers.merge(DEFAULT_HEADERS))
20
- .send(method, "#{Client.base_uri}#{path}", json: body&.compact)
26
+ .send(method, "#{@client.base_uri}#{path}", json: body&.compact)
21
27
  .then { |http_response| handle_response(http_response) }
22
28
  rescue HTTP::TimeoutError => e
23
29
  raise Tarpon::TimeoutError, e
@@ -26,7 +32,7 @@ module Tarpon
26
32
  private
27
33
 
28
34
  def api_key(type)
29
- Client.send("#{type}_api_key")
35
+ @client.send("#{type}_api_key")
30
36
  end
31
37
 
32
38
  def parse_body(http_response)
@@ -4,8 +4,8 @@ module Tarpon
4
4
  module Request
5
5
  class Subscriber
6
6
  class Entitlement < Base
7
- def initialize(subscriber_path:, entitlement_identifier:)
8
- super()
7
+ def initialize(subscriber_path:, entitlement_identifier:, **opts)
8
+ super(**opts)
9
9
  @subscriber_path = subscriber_path
10
10
  @entitlement_identifier = entitlement_identifier
11
11
  end
@@ -6,8 +6,8 @@ module Tarpon
6
6
  module Request
7
7
  class Subscriber
8
8
  class Offering < Base
9
- def initialize(subscriber_path:)
10
- super()
9
+ def initialize(subscriber_path:, **opts)
10
+ super(**opts)
11
11
  @subscriber_path = subscriber_path
12
12
  end
13
13
 
@@ -4,8 +4,8 @@ module Tarpon
4
4
  module Request
5
5
  class Subscriber
6
6
  class Subscription < Base
7
- def initialize(subscriber_path:, product_id:)
8
- super()
7
+ def initialize(subscriber_path:, product_id:, **opts)
8
+ super(**opts)
9
9
  @subscriber_path = subscriber_path
10
10
  @product_id = product_id
11
11
  end
@@ -3,8 +3,8 @@
3
3
  module Tarpon
4
4
  module Request
5
5
  class Subscriber < Base
6
- def initialize(app_user_id:)
7
- super()
6
+ def initialize(app_user_id:, **opts)
7
+ super(**opts)
8
8
  @app_user_id = app_user_id
9
9
  end
10
10
 
@@ -17,15 +17,19 @@ module Tarpon
17
17
  end
18
18
 
19
19
  def entitlements(entitlement_identifier)
20
- self.class::Entitlement.new(subscriber_path: path, entitlement_identifier: entitlement_identifier)
20
+ self.class::Entitlement.new(
21
+ subscriber_path: path,
22
+ entitlement_identifier: entitlement_identifier,
23
+ client: @client
24
+ )
21
25
  end
22
26
 
23
27
  def offerings
24
- self.class::Offering.new(subscriber_path: path)
28
+ self.class::Offering.new(subscriber_path: path, client: @client)
25
29
  end
26
30
 
27
31
  def subscriptions(product_id)
28
- self.class::Subscription.new(subscriber_path: path, product_id: product_id)
32
+ self.class::Subscription.new(subscriber_path: path, product_id: product_id, client: @client)
29
33
  end
30
34
 
31
35
  private
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Tarpon
4
- VERSION = '0.4.0'
4
+ VERSION = '0.5.0'
5
5
  end
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.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Igor Belo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-06-02 00:00:00.000000000 Z
11
+ date: 2022-12-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: http
@@ -141,7 +141,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
141
141
  - !ruby/object:Gem::Version
142
142
  version: '0'
143
143
  requirements: []
144
- rubygems_version: 3.3.12
144
+ rubygems_version: 3.3.7
145
145
  signing_key:
146
146
  specification_version: 4
147
147
  summary: A Ruby interface to RevenueCat REST API