tarpon 0.4.0 → 0.5.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/client.rb +21 -7
- data/lib/tarpon/configuration.rb +5 -1
- data/lib/tarpon/request/base.rb +9 -3
- data/lib/tarpon/request/subscriber/attribute.rb +27 -0
- data/lib/tarpon/request/subscriber/entitlement.rb +2 -2
- data/lib/tarpon/request/subscriber/offering.rb +2 -2
- data/lib/tarpon/request/subscriber/subscription.rb +2 -2
- data/lib/tarpon/request/subscriber.rb +13 -5
- data/lib/tarpon/version.rb +1 -1
- data/lib/tarpon.rb +1 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2ad61cd6fc041273c6649f617d1f2402ff2534e455ee632663f288b94dd63598
|
4
|
+
data.tar.gz: 6238cf84ca22ea839b16dc5313fc59e0358dc2fbeecec35790d0a078e9ec1d01
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 378a679fecc9419bc9b7fd59be636c0d71484a23a6461ceee93610a9070943a084e7e29db6ddb719d569a3545a2e3d9e71a7ba99e8ec70ccf3a58951116a29e2
|
7
|
+
data.tar.gz: f91a37b4d5da486e197872982fe5696402de5da34df5eff55b3b411997fcb8c03a7407f023f28d3763787e38305b5233a0c3e1f4ea3e730249f39c7385d85bc9
|
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
|
-
|
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
|
-
|
11
|
-
|
12
|
-
|
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
|
-
|
15
|
-
|
16
|
-
end
|
29
|
+
def receipt
|
30
|
+
Request::Receipt.new(client: self)
|
17
31
|
end
|
18
32
|
end
|
19
33
|
end
|
data/lib/tarpon/configuration.rb
CHANGED
@@ -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
|
data/lib/tarpon/request/base.rb
CHANGED
@@ -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(
|
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, "#{
|
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
|
-
|
35
|
+
@client.send("#{type}_api_key")
|
30
36
|
end
|
31
37
|
|
32
38
|
def parse_body(http_response)
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Tarpon
|
4
|
+
module Request
|
5
|
+
class Subscriber
|
6
|
+
class Attribute < Base
|
7
|
+
def initialize(subscriber_path:, **opts)
|
8
|
+
super(**opts)
|
9
|
+
@subscriber_path = subscriber_path
|
10
|
+
end
|
11
|
+
|
12
|
+
def update(**data)
|
13
|
+
body = {
|
14
|
+
attributes: data
|
15
|
+
}
|
16
|
+
perform(method: :post, path: path, key: :public, body: body)
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def path
|
22
|
+
"#{@subscriber_path}/attributes"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -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
|
@@ -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,23 @@ module Tarpon
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def entitlements(entitlement_identifier)
|
20
|
-
self.class::Entitlement.new(
|
20
|
+
self.class::Entitlement.new(
|
21
|
+
subscriber_path: path,
|
22
|
+
entitlement_identifier: entitlement_identifier,
|
23
|
+
client: @client
|
24
|
+
)
|
25
|
+
end
|
26
|
+
|
27
|
+
def attributes
|
28
|
+
self.class::Attribute.new(subscriber_path: path, client: @client)
|
21
29
|
end
|
22
30
|
|
23
31
|
def offerings
|
24
|
-
self.class::Offering.new(subscriber_path: path)
|
32
|
+
self.class::Offering.new(subscriber_path: path, client: @client)
|
25
33
|
end
|
26
34
|
|
27
35
|
def subscriptions(product_id)
|
28
|
-
self.class::Subscription.new(subscriber_path: path, product_id: product_id)
|
36
|
+
self.class::Subscription.new(subscriber_path: path, product_id: product_id, client: @client)
|
29
37
|
end
|
30
38
|
|
31
39
|
private
|
data/lib/tarpon/version.rb
CHANGED
data/lib/tarpon.rb
CHANGED
@@ -7,6 +7,7 @@ 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/attribute'
|
10
11
|
require 'tarpon/request/subscriber/entitlement'
|
11
12
|
require 'tarpon/request/subscriber/subscription'
|
12
13
|
require 'tarpon/request/subscriber/offering'
|
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.5.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: 2022-
|
11
|
+
date: 2022-12-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: http
|
@@ -113,6 +113,7 @@ files:
|
|
113
113
|
- lib/tarpon/request/base.rb
|
114
114
|
- lib/tarpon/request/receipt.rb
|
115
115
|
- lib/tarpon/request/subscriber.rb
|
116
|
+
- lib/tarpon/request/subscriber/attribute.rb
|
116
117
|
- lib/tarpon/request/subscriber/entitlement.rb
|
117
118
|
- lib/tarpon/request/subscriber/offering.rb
|
118
119
|
- lib/tarpon/request/subscriber/subscription.rb
|
@@ -141,7 +142,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
141
142
|
- !ruby/object:Gem::Version
|
142
143
|
version: '0'
|
143
144
|
requirements: []
|
144
|
-
rubygems_version: 3.3.
|
145
|
+
rubygems_version: 3.3.7
|
145
146
|
signing_key:
|
146
147
|
specification_version: 4
|
147
148
|
summary: A Ruby interface to RevenueCat REST API
|