metrifox-sdk 1.0.2 → 1.0.3
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/README.md +19 -5
- data/lib/metrifox_sdk/checkout/api.rb +8 -0
- data/lib/metrifox_sdk/checkout/module.rb +11 -15
- data/lib/metrifox_sdk/customers/api.rb +7 -1
- data/lib/metrifox_sdk/customers/module.rb +16 -1
- data/lib/metrifox_sdk/types.rb +3 -3
- data/lib/metrifox_sdk/version.rb +1 -1
- metadata +3 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 61978214945170e21af55446d8aa5606a14710fa5515cdd327d11227b5f95a22
|
|
4
|
+
data.tar.gz: cc96ae1ea46452d1d1221b936048bb9ad8931bd93317c727352272f08ad796a6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b31ffd58d394c50d65fd22b339f939dcbfa8ae31bb716cce31c759cd1ad9ab584746f1476e1e376541e6ac27539e4abed0b3aca665f6607136a594226881f2bf
|
|
7
|
+
data.tar.gz: b7e0c2167befb2befc63e50b4cef0b940c0a4f81890933f2100937fe458a3c3a626451d7b4fc103f1f649cc7b6cac83ff79ed74c5fee21b023a5692479256d59
|
data/README.md
CHANGED
|
@@ -90,9 +90,9 @@ response = METRIFOX_SDK.usages.record_usage(usage_request)
|
|
|
90
90
|
### Customer Management
|
|
91
91
|
|
|
92
92
|
```ruby
|
|
93
|
-
# Create customer
|
|
93
|
+
# Create customer (customer_key is REQUIRED)
|
|
94
94
|
customer_data = {
|
|
95
|
-
customer_key: "customer_123",
|
|
95
|
+
customer_key: "customer_123", # Required - unique identifier for the customer
|
|
96
96
|
customer_type: "BUSINESS",
|
|
97
97
|
primary_email: "customer@example.com",
|
|
98
98
|
legal_name: "Acme Corp",
|
|
@@ -101,10 +101,11 @@ customer_data = {
|
|
|
101
101
|
|
|
102
102
|
response = METRIFOX_SDK.customers.create(customer_data)
|
|
103
103
|
|
|
104
|
-
# Update customer
|
|
104
|
+
# Update customer (customer_key cannot be changed and is passed as a parameter)
|
|
105
105
|
update_data = {
|
|
106
106
|
display_name: "ACME Corporation",
|
|
107
107
|
website_url: "https://acme.com"
|
|
108
|
+
# Note: customer_key is NOT included here - it's immutable
|
|
108
109
|
}
|
|
109
110
|
|
|
110
111
|
response = METRIFOX_SDK.customers.update("customer_123", update_data)
|
|
@@ -115,6 +116,10 @@ response = METRIFOX_SDK.customers.get_customer({ customer_key: "customer_123" })
|
|
|
115
116
|
# Get customer details
|
|
116
117
|
response = METRIFOX_SDK.customers.get_details({ customer_key: "customer_123" })
|
|
117
118
|
|
|
119
|
+
# Check for an active subscription
|
|
120
|
+
has_active_subscription = MetrifoxSDK.customers.has_active_subscription?(customer_key: "customer_123")
|
|
121
|
+
puts has_active_subscription # true or false
|
|
122
|
+
|
|
118
123
|
# List customers
|
|
119
124
|
response = METRIFOX_SDK.customers.list
|
|
120
125
|
|
|
@@ -205,15 +210,24 @@ access_request = MetrifoxSDK::Types::AccessCheckRequest.new(
|
|
|
205
210
|
|
|
206
211
|
response = METRIFOX_SDK.usages.check_access(access_request)
|
|
207
212
|
|
|
208
|
-
# Customer creation with structured data
|
|
213
|
+
# Customer creation with structured data (customer_key is REQUIRED)
|
|
209
214
|
customer_request = MetrifoxSDK::Types::CustomerCreateRequest.new(
|
|
210
|
-
customer_key: "customer_123",
|
|
215
|
+
customer_key: "customer_123", # Required
|
|
211
216
|
customer_type: MetrifoxSDK::Types::CustomerType::BUSINESS,
|
|
212
217
|
primary_email: "customer@example.com",
|
|
213
218
|
legal_name: "Acme Corp"
|
|
214
219
|
)
|
|
215
220
|
|
|
216
221
|
response = METRIFOX_SDK.customers.create(customer_request)
|
|
222
|
+
|
|
223
|
+
# Customer update with structured data (customer_key is immutable)
|
|
224
|
+
customer_update = MetrifoxSDK::Types::CustomerUpdateRequest.new(
|
|
225
|
+
display_name: "Acme Corporation",
|
|
226
|
+
website_url: "https://acme.com"
|
|
227
|
+
# Note: customer_key is NOT a field in CustomerUpdateRequest
|
|
228
|
+
)
|
|
229
|
+
|
|
230
|
+
response = METRIFOX_SDK.customers.update("customer_123", customer_update)
|
|
217
231
|
```
|
|
218
232
|
|
|
219
233
|
## Error Handling
|
|
@@ -11,5 +11,13 @@ module MetrifoxSDK::Checkout
|
|
|
11
11
|
data = parse_response(response, "Failed to get tenant checkout settings")
|
|
12
12
|
data.dig("data", "checkout_username")
|
|
13
13
|
end
|
|
14
|
+
|
|
15
|
+
def generate_checkout_url(base_url, api_key, query_params)
|
|
16
|
+
uri = URI.join(base_url, "products/offerings/generate-checkout-url")
|
|
17
|
+
uri.query = URI.encode_www_form(query_params)
|
|
18
|
+
response = make_request(uri, "GET", api_key)
|
|
19
|
+
data = parse_response(response, "Failed to generate checkout URL")
|
|
20
|
+
data.dig("data", "checkout_url")
|
|
21
|
+
end
|
|
14
22
|
end
|
|
15
23
|
end
|
|
@@ -6,7 +6,7 @@ module MetrifoxSDK
|
|
|
6
6
|
class Module < BaseModule
|
|
7
7
|
def url(config)
|
|
8
8
|
validate_api_key!
|
|
9
|
-
|
|
9
|
+
|
|
10
10
|
# Handle both hash and struct access patterns
|
|
11
11
|
offering_key = get_value(config, :offering_key)
|
|
12
12
|
billing_interval = get_value(config, :billing_interval)
|
|
@@ -14,20 +14,16 @@ module MetrifoxSDK
|
|
|
14
14
|
|
|
15
15
|
raise ArgumentError, "offering_key is required" if offering_key.nil? || offering_key.empty?
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
uri.query = URI.encode_www_form(query_params) unless query_params.empty?
|
|
29
|
-
|
|
30
|
-
uri.to_s
|
|
17
|
+
# Build query parameters
|
|
18
|
+
query_params = { offering_key: offering_key }
|
|
19
|
+
query_params[:billing_interval] = billing_interval if billing_interval && !billing_interval.empty?
|
|
20
|
+
query_params[:customer_key] = customer_key if customer_key && !customer_key.empty?
|
|
21
|
+
|
|
22
|
+
# Call API to generate checkout URL
|
|
23
|
+
checkout_url = api.generate_checkout_url(base_url, api_key, query_params)
|
|
24
|
+
raise StandardError, "Checkout URL could not be generated" if checkout_url.nil? || checkout_url.empty?
|
|
25
|
+
|
|
26
|
+
checkout_url
|
|
31
27
|
end
|
|
32
28
|
|
|
33
29
|
private
|
|
@@ -41,6 +41,12 @@ module MetrifoxSDK::Customers
|
|
|
41
41
|
parse_response(response, "Failed to Fetch Customer Details")
|
|
42
42
|
end
|
|
43
43
|
|
|
44
|
+
def customer_active_subscription_request(base_url, api_key, customer_key)
|
|
45
|
+
uri = URI.join(base_url, "customers/#{customer_key}/check-active-subscription")
|
|
46
|
+
response = make_request(uri, "GET", api_key)
|
|
47
|
+
parse_response(response, "Failed to Check Active Subscription")
|
|
48
|
+
end
|
|
49
|
+
|
|
44
50
|
def customer_list_request(base_url, api_key, request_payload = {})
|
|
45
51
|
uri = URI.join(base_url, "customers")
|
|
46
52
|
|
|
@@ -110,4 +116,4 @@ module MetrifoxSDK::Customers
|
|
|
110
116
|
end
|
|
111
117
|
end
|
|
112
118
|
end
|
|
113
|
-
end
|
|
119
|
+
end
|
|
@@ -19,16 +19,31 @@ module MetrifoxSDK
|
|
|
19
19
|
api.customer_get_request(base_url, api_key, request_payload)
|
|
20
20
|
end
|
|
21
21
|
|
|
22
|
+
def get(request_payload)
|
|
23
|
+
get_customer(request_payload)
|
|
24
|
+
end
|
|
25
|
+
|
|
22
26
|
def get_details(request_payload)
|
|
23
27
|
validate_api_key!
|
|
24
28
|
api.customer_details_get_request(base_url, api_key, request_payload)
|
|
25
29
|
end
|
|
26
30
|
|
|
31
|
+
def has_active_subscription?(customer_key:)
|
|
32
|
+
validate_api_key!
|
|
33
|
+
result = api.customer_active_subscription_request(base_url, api_key, customer_key)
|
|
34
|
+
data = result["data"] || {}
|
|
35
|
+
data["has_active_subscription"]
|
|
36
|
+
end
|
|
37
|
+
|
|
27
38
|
def delete_customer(request_payload)
|
|
28
39
|
validate_api_key!
|
|
29
40
|
api.customer_delete_request(base_url, api_key, request_payload)
|
|
30
41
|
end
|
|
31
42
|
|
|
43
|
+
def delete(request_payload)
|
|
44
|
+
delete_customer(request_payload)
|
|
45
|
+
end
|
|
46
|
+
|
|
32
47
|
def list(request_payload = {})
|
|
33
48
|
validate_api_key!
|
|
34
49
|
api.customer_list_request(base_url, api_key, request_payload)
|
|
@@ -46,4 +61,4 @@ module MetrifoxSDK
|
|
|
46
61
|
end
|
|
47
62
|
end
|
|
48
63
|
end
|
|
49
|
-
end
|
|
64
|
+
end
|
data/lib/metrifox_sdk/types.rb
CHANGED
|
@@ -56,7 +56,7 @@ module MetrifoxSDK
|
|
|
56
56
|
UsageEventResponse = Struct.new(:message, :event_name, :customer_key, keyword_init: true)
|
|
57
57
|
|
|
58
58
|
CustomerCreateRequest = Struct.new(
|
|
59
|
-
# Core fields
|
|
59
|
+
# Core fields (customer_key is REQUIRED)
|
|
60
60
|
:customer_key, :customer_type, :primary_email, :primary_phone,
|
|
61
61
|
# Business fields
|
|
62
62
|
:legal_name, :display_name, :legal_number, :tax_identification_number,
|
|
@@ -76,8 +76,8 @@ module MetrifoxSDK
|
|
|
76
76
|
)
|
|
77
77
|
|
|
78
78
|
CustomerUpdateRequest = Struct.new(
|
|
79
|
-
# Core fields
|
|
80
|
-
:
|
|
79
|
+
# Core fields (customer_key is NOT included - it's immutable and passed as a parameter)
|
|
80
|
+
:customer_type, :primary_email, :primary_phone, :billing_email,
|
|
81
81
|
# Business fields
|
|
82
82
|
:legal_name, :display_name, :legal_number, :tax_identification_number,
|
|
83
83
|
:logo_url, :website_url, :account_manager,
|
data/lib/metrifox_sdk/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: metrifox-sdk
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.0.
|
|
4
|
+
version: 1.0.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Metrifox
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: exe
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date: 2025-
|
|
10
|
+
date: 2025-11-26 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: json
|
|
@@ -138,7 +137,6 @@ metadata:
|
|
|
138
137
|
homepage_uri: https://github.com/metrifox/metrifox-ruby
|
|
139
138
|
source_code_uri: https://github.com/metrifox/metrifox-ruby
|
|
140
139
|
changelog_uri: https://github.com/metrifox/metrifox-ruby/tree/main/CHANGELOG.md
|
|
141
|
-
post_install_message:
|
|
142
140
|
rdoc_options: []
|
|
143
141
|
require_paths:
|
|
144
142
|
- lib
|
|
@@ -153,8 +151,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
153
151
|
- !ruby/object:Gem::Version
|
|
154
152
|
version: '0'
|
|
155
153
|
requirements: []
|
|
156
|
-
rubygems_version: 3.
|
|
157
|
-
signing_key:
|
|
154
|
+
rubygems_version: 3.6.2
|
|
158
155
|
specification_version: 4
|
|
159
156
|
summary: Ruby SDK for Metrifox API
|
|
160
157
|
test_files: []
|