flexops 1.0.2 → 2.0.0
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 +235 -61
- data/lib/flexops/client.rb +6 -7
- data/lib/flexops/errors.rb +9 -0
- data/lib/flexops/hazmat_classification.rb +34 -0
- data/lib/flexops/http.rb +78 -45
- data/lib/flexops/resources/auth.rb +8 -29
- data/lib/flexops/resources/carbon_offsets.rb +60 -0
- data/lib/flexops/resources/carriers.rb +95 -8
- data/lib/flexops/resources/email_templates.rb +27 -17
- data/lib/flexops/resources/hs_codes.rb +10 -11
- data/lib/flexops/resources/insurance.rb +19 -9
- data/lib/flexops/resources/inventory.rb +0 -8
- data/lib/flexops/resources/orders.rb +0 -8
- data/lib/flexops/resources/pickups.rb +14 -5
- data/lib/flexops/resources/recurring_shipments.rb +30 -15
- data/lib/flexops/resources/report_schedules.rb +63 -0
- data/lib/flexops/resources/returns.rb +37 -23
- data/lib/flexops/resources/rules.rb +18 -2
- data/lib/flexops/resources/shipping.rb +51 -10
- data/lib/flexops/resources/wallet.rb +4 -20
- data/lib/flexops/resources/webhooks.rb +132 -9
- data/lib/flexops/resources/workspaces.rb +8 -13
- data/lib/flexops/version.rb +1 -1
- data/lib/flexops/webhook_event_type.rb +25 -0
- data/lib/flexops/workspace_role.rb +32 -0
- data/lib/flexops.rb +5 -3
- metadata +7 -5
- data/lib/flexops/resources/api_keys.rb +0 -40
- data/lib/flexops/resources/offsets.rb +0 -38
- data/lib/flexops/resources/reports.rb +0 -46
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 99bb604e4e35131d7525633fbfad7103b380170556b47250599192256636eec1
|
|
4
|
+
data.tar.gz: b9fb3ccd224541332bd03fd9e8510937fbed4d093c6ab3443dfd41fee0565229
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 12823e90e21cd1eeefcf883ab5c7ed9a4e9d008b2e26bd80ac6014a05e3b6e6b57e4054a3757574173886b2c8ed6a08e6c8d3a2863f6034eb592e6e8d03da5c1
|
|
7
|
+
data.tar.gz: fb7a48fb211dfb1af4ddd9a0be588eb58318b8ffd445578a09dcacdef625ff9dc8e3dbc593b59a21da18acf678d67d9ca0bd76aef55a22843be9748bfddcf5fa
|
data/README.md
CHANGED
|
@@ -40,23 +40,51 @@ rates = client.shipping.get_rates(
|
|
|
40
40
|
package: {weight: 16, weightUnit: "oz"}
|
|
41
41
|
)
|
|
42
42
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
puts
|
|
54
|
-
|
|
43
|
+
request = {
|
|
44
|
+
carrierCode: "USPS", serviceCode: "GROUND_ADVANTAGE",
|
|
45
|
+
origin: {name: "Warehouse", addressLine1: "123 Main St", city: "New York", stateProvince: "NY", postalCode: "10001", countryCode: "US"},
|
|
46
|
+
destination: {name: "Customer", addressLine1: "456 Oak Ave", city: "Los Angeles", stateProvince: "CA", postalCode: "90210", countryCode: "US"},
|
|
47
|
+
package: {weight: 16, weightUnit: "oz"},
|
|
48
|
+
maximumPostageAmount: 10.25, # Caller-approved ceiling in USD.
|
|
49
|
+
# Required without an orderId. The SDK never fills it in; NONE (0) = not hazardous.
|
|
50
|
+
hazmatClassification: FlexOps::HazmatClassification::NONE
|
|
51
|
+
}
|
|
52
|
+
preview = client.shipping.create_label(request)
|
|
53
|
+
puts preview["quotedPostageAmount"]
|
|
54
|
+
|
|
55
|
+
# Call only after explicit caller approval, within five minutes.
|
|
56
|
+
purchase_approved_label = lambda do |purchase_key|
|
|
57
|
+
client.shipping.create_label(
|
|
58
|
+
request.merge(confirmationToken: preview["confirmationToken"]),
|
|
59
|
+
idempotency_key: purchase_key # Persist per purchase; reuse on retries.
|
|
60
|
+
)
|
|
61
|
+
end
|
|
55
62
|
|
|
56
63
|
# Track a shipment
|
|
57
64
|
info = client.shipping.track("9400111899223456789012")
|
|
58
65
|
```
|
|
59
66
|
|
|
67
|
+
### Live label approval (1.1.0+)
|
|
68
|
+
|
|
69
|
+
The example below requires SDK 1.1.0 or later. Version 1.0.2 does not
|
|
70
|
+
include the per-call idempotency argument.
|
|
71
|
+
|
|
72
|
+
For live domestic single-label requests, `maximumPostageAmount` is required: positive
|
|
73
|
+
USD, at most two decimal places, up to 1,000,000. Missing or invalid values return
|
|
74
|
+
400 `ApprovalRequired`. Omitting `confirmationToken` returns a raw 200 preview
|
|
75
|
+
(`status`, `quotedPostageAmount`, `maximumPostageAmount`, `currency`, `expiresAt`,
|
|
76
|
+
`confirmationToken`). After explicit approval, resubmit the same shipment and ceiling
|
|
77
|
+
with the token and a unique per-purchase `Idempotency-Key` header. The token expires
|
|
78
|
+
after five minutes. A successful purchase returns the raw 201 label, including
|
|
79
|
+
`labelId`, `trackingNumber`, `carrierCode`, and `labelData`, without a `data` wrapper.
|
|
80
|
+
|
|
81
|
+
Keep the same key and request across retries. An uncertain outcome needs reconciliation;
|
|
82
|
+
do not start another purchase with a new key. An expired approval returns 409
|
|
83
|
+
`ApprovalExpired`; obtain and explicitly approve a fresh preview when no purchase is
|
|
84
|
+
unresolved. The ceiling bounds postage authorization, not later adjustments or separate
|
|
85
|
+
fees. Sandbox execution bypasses approval; batch, return, and raw carrier routes have
|
|
86
|
+
separate contracts. The SDK never automatically confirms a preview.
|
|
87
|
+
|
|
60
88
|
## Authentication
|
|
61
89
|
|
|
62
90
|
### API key (recommended)
|
|
@@ -69,7 +97,8 @@ client = FlexOps::Client.new(api_key: "fxk_live_...", workspace_id: "ws_abc123")
|
|
|
69
97
|
|
|
70
98
|
```ruby
|
|
71
99
|
client = FlexOps::Client.new(base_url: "https://gateway.flexops.io")
|
|
72
|
-
client.auth.login(email: "user@example.com", password: "password")
|
|
100
|
+
session = client.auth.login(email: "user@example.com", password: "password")
|
|
101
|
+
client.set_access_token(session["data"]["token"])
|
|
73
102
|
client.workspace_id = "ws_abc123"
|
|
74
103
|
```
|
|
75
104
|
|
|
@@ -81,38 +110,176 @@ Use `fxk_test_...` (instead of `fxk_live_...`) to route to the sandbox environme
|
|
|
81
110
|
client = FlexOps::Client.new(api_key: "fxk_test_...", workspace_id: "ws_abc123")
|
|
82
111
|
```
|
|
83
112
|
|
|
84
|
-
##
|
|
113
|
+
## Carrier-specific calls
|
|
114
|
+
|
|
115
|
+
`client.carriers.usps`, `.ups`, `.fedex` and `.dhl` call carrier routes through the legacy
|
|
116
|
+
`/api/ApiProxy` passthrough, which the Gateway retires on 2027-06-30.
|
|
117
|
+
|
|
118
|
+
- Lookups (GET), such as address checks, tracking and DHL rates, work with an API key or a user
|
|
119
|
+
token.
|
|
120
|
+
- The writes (POST, PUT and DELETE, such as `usps.get_domestic_rates`, `fedex.cancel_shipment`
|
|
121
|
+
or `ups.create_pickup`) are deprecated. They need a user token from `auth.login`: API keys get
|
|
122
|
+
403 `API_KEY_SCOPE_REQUIRED`, and no API-key scope will be added for them. They stop working when
|
|
123
|
+
the proxy is retired.
|
|
124
|
+
- Label generation through the proxy is closed (410 Gone), so the SDK has no carrier label
|
|
125
|
+
method.
|
|
126
|
+
|
|
127
|
+
Use the native routes instead where they cover the call:
|
|
128
|
+
|
|
129
|
+
| Instead of | Use |
|
|
130
|
+
|---|---|
|
|
131
|
+
| Carrier rate calls | `client.shipping.get_rates` |
|
|
132
|
+
| Carrier labels | `client.shipping.create_label` (`client.returns.generate_label` for returns) |
|
|
133
|
+
| Label cancels | `client.shipping.cancel_label` |
|
|
134
|
+
| Carrier pickups | `client.pickups.schedule`, `list`, `get`, `cancel` |
|
|
135
|
+
| USPS scan forms | `client.scan_forms.create` |
|
|
136
|
+
| Address validation | `client.shipping.validate_address` |
|
|
137
|
+
| Tracking | `client.shipping.track` |
|
|
138
|
+
|
|
139
|
+
```ruby
|
|
140
|
+
# USPS city and state for a ZIP code (works with an API key)
|
|
141
|
+
place = client.carriers.usps.city_state_lookup("10001")
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
## Retries and idempotency
|
|
145
|
+
|
|
146
|
+
The client retries a request up to three times with exponential backoff:
|
|
147
|
+
|
|
148
|
+
- GET: after a dropped connection or timeout, and on 429, 500, 502, 503 and 504.
|
|
149
|
+
- POST, PUT and PATCH: after a dropped connection or timeout, and on 429, 502, 503, 504 and
|
|
150
|
+
409 `IDEMPOTENCY_CONFLICT` (the first request with that key is still running). Never on 500:
|
|
151
|
+
the Gateway does not replay a 5xx, so a retry could run the write (and charge the wallet)
|
|
152
|
+
again.
|
|
153
|
+
- DELETE: only on 429.
|
|
154
|
+
|
|
155
|
+
A key reused with a different request body gets 422 `IDEMPOTENCY_KEY_REUSED`; it is not retried
|
|
156
|
+
and raises `FlexOps::Error` with that `code`. Error codes are matched exactly, so a label
|
|
157
|
+
purchase's own 409 `IdempotencyConflict` (altered inputs under a used key) is not retried either.
|
|
158
|
+
|
|
159
|
+
Every POST, PUT and PATCH carries an `Idempotency-Key` header. Pass your own to
|
|
160
|
+
`shipping.create_label(request, idempotency_key: ...)`, `insurance.purchase(..., idempotency_key: ...)`
|
|
161
|
+
or `carbon_offsets.purchase(..., idempotency_key: ...)`, and store it so a retry your app makes after
|
|
162
|
+
an error or a timeout reuses it; otherwise the client generates one UUID
|
|
163
|
+
per call and sends it on every retry of that call, so the Gateway replays a write it already
|
|
164
|
+
finished instead of running it twice. A 2xx response with no body returns `nil`.
|
|
165
|
+
|
|
166
|
+
## Workspace members
|
|
167
|
+
|
|
168
|
+
Roles are the Gateway `WorkspaceRole` numbers (Owner 0, Admin 1, Member 2, Merchant 3). Pass a
|
|
169
|
+
`FlexOps::WorkspaceRole` constant or a name; the SDK sends the number.
|
|
170
|
+
|
|
171
|
+
```ruby
|
|
172
|
+
client.workspaces.invite_member(email: "ops@example.com", role: :member)
|
|
173
|
+
client.workspaces.update_member_role(user_id, FlexOps::WorkspaceRole::ADMIN)
|
|
174
|
+
|
|
175
|
+
result = client.workspaces.list_members
|
|
176
|
+
members = result["data"]["members"] # also "pendingInvites", "userLimit", "canInviteMore"
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
## Recurring shipments, report schedules and email templates
|
|
85
180
|
|
|
86
|
-
|
|
181
|
+
Reads work with any API key or a user token. Writes (every POST, PUT and DELETE, including the
|
|
182
|
+
email template preview) need a user token from `auth.login` or an API key granted the
|
|
183
|
+
resource's opt-in scope: `recurring-shipments:write`, `report-schedules:write` or
|
|
184
|
+
`email-templates:write`. Older keys do not have these scopes; a key without one gets 403
|
|
185
|
+
`API_KEY_SCOPE_REQUIRED` with `requiredScopes`. Enums are sent as numbers and ids are GUID
|
|
186
|
+
strings.
|
|
87
187
|
|
|
88
188
|
```ruby
|
|
89
|
-
#
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
weight_in_ounces: 16
|
|
189
|
+
# Recurring shipments (bare JSON). interval: Daily 0, Weekly 1, Biweekly 2, Monthly 3, Custom 4
|
|
190
|
+
schedule = client.recurring_shipments.create(
|
|
191
|
+
name: "Weekly restock", addressId: address_id, presetId: preset_id,
|
|
192
|
+
interval: 1, firstRunUtc: "2026-11-02T14:00:00Z"
|
|
94
193
|
)
|
|
194
|
+
client.recurring_shipments.pause(schedule["id"]) # nil (204); also resume, delete
|
|
195
|
+
client.recurring_shipments.trigger(schedule["id"], idempotency_key: run_key) # creates an order now
|
|
196
|
+
|
|
197
|
+
# Report schedules ({ success, data, message } envelope).
|
|
198
|
+
# format: Csv 0, Json 1; frequencyType: Daily 0, Weekly 1, Monthly 2
|
|
199
|
+
report = client.report_schedules.create(
|
|
200
|
+
reportType: "shipments", format: 0, frequencyType: 1, dayOfWeek: 1,
|
|
201
|
+
timeOfDayUtc: "08:00:00", recipientEmails: "ops@example.com"
|
|
202
|
+
)["data"]
|
|
203
|
+
client.report_schedules.toggle(report["id"]) # flips isEnabled
|
|
204
|
+
|
|
205
|
+
# Tracking email templates (bare JSON), one per event. eventType: LabelCreated 0, InTransit 1,
|
|
206
|
+
# OutForDelivery 2, Delivered 3, Exception 4, ReturnToSender 5
|
|
207
|
+
client.email_templates.upsert(eventType: 3, subjectTemplate: "Delivered: {{tracking_number}}",
|
|
208
|
+
htmlBodyTemplate: "<p>Your package arrived.</p>")
|
|
209
|
+
client.email_templates.preview(subject_template: "Hi {{recipient_name}}", html_body_template: "<p>{{status}}</p>")
|
|
210
|
+
```
|
|
95
211
|
|
|
96
|
-
|
|
97
|
-
rates = client.carriers.fedex.get_rates(...)
|
|
212
|
+
## Wallet balance
|
|
98
213
|
|
|
99
|
-
|
|
100
|
-
|
|
214
|
+
```ruby
|
|
215
|
+
balance = client.wallet.get_balance # {"hasWallet" => true, "balanceCents" => 1250, "balance" => 12.5}
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
The request carries `X-Workspace-Id` set to the client's `workspace_id`. Funding and
|
|
219
|
+
transaction history are managed in the FlexOps portal.
|
|
220
|
+
|
|
221
|
+
## Webhook subscriptions
|
|
101
222
|
|
|
102
|
-
|
|
103
|
-
|
|
223
|
+
```ruby
|
|
224
|
+
# Leave events out to receive every event.
|
|
225
|
+
webhook = client.webhooks.create(
|
|
226
|
+
url: "https://your-app.com/webhooks/flexops",
|
|
227
|
+
events: [FlexOps::WebhookEventType::LABEL_CREATED,
|
|
228
|
+
FlexOps::WebhookEventType::LABEL_CANCELED,
|
|
229
|
+
FlexOps::WebhookEventType::BATCH_COMPLETED]
|
|
230
|
+
)
|
|
231
|
+
signing_secret = webhook["secret"] # "whsec_...", returned only on create; store it
|
|
232
|
+
|
|
233
|
+
# Change the events (or url, description, status: "Active", "Paused", "Disabled").
|
|
234
|
+
client.webhooks.update(webhook["id"], events: [FlexOps::WebhookEventType::LABEL_CREATED])
|
|
104
235
|
```
|
|
105
236
|
|
|
237
|
+
`create` returns the subscription itself (`"id"`, `"url"`, `"eventTypes"`, `"status"`, `"secret"`, ...), because the Gateway answers it with the bare subscription. The other webhook methods return the usual `{"success" => true, "data" => ...}` envelope.
|
|
238
|
+
|
|
239
|
+
`events` is sent as the Gateway's comma-separated `eventTypes`. FlexOps sends these events, named exactly as below (`FlexOps::WebhookEventType::ALL` lists them). Names are PascalCase and matched exactly, so a name like `label.created` would never match; `create` and `update` raise `ArgumentError`, before any request, for an unknown name, an empty list or a non-array.
|
|
240
|
+
|
|
241
|
+
| Event | Sent when |
|
|
242
|
+
|---|---|
|
|
243
|
+
| `LabelCreated` | A live label is purchased (sandbox labels send nothing) |
|
|
244
|
+
| `LabelCanceled` | A live label is voided |
|
|
245
|
+
| `BatchCompleted` | A batch label job finishes |
|
|
246
|
+
| `TrackingUpdated` | A USPS tracking scan arrives (USPS push-tracking pilot workspaces only) |
|
|
247
|
+
| `TrackingDelivered` | A USPS package is delivered (USPS push-tracking pilot workspaces only) |
|
|
248
|
+
|
|
249
|
+
You can send a raw `eventTypes:` string (`"*"` or names joined by commas with no spaces) instead of `events:`; it is passed through unchecked, for example to subscribe to an event newer than your SDK version.
|
|
250
|
+
|
|
106
251
|
## Webhook verification
|
|
107
252
|
|
|
253
|
+
FlexOps signs each delivery with HMAC-SHA256 over `{X-FlexOps-Timestamp}.{raw body}`, keyed with your subscription secret (`whsec_...`, used as-is), and sends it as `X-FlexOps-Signature: sha256=<hex>`. Verify the raw body before you parse it.
|
|
254
|
+
|
|
108
255
|
```ruby
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
256
|
+
# Rails controller action
|
|
257
|
+
def flexops_webhook
|
|
258
|
+
payload = request.raw_post
|
|
259
|
+
|
|
260
|
+
valid = FlexOps::Resources::Webhooks.verify_signature(
|
|
261
|
+
payload: payload,
|
|
262
|
+
signature: request.headers["X-FlexOps-Signature"], # "sha256=..."
|
|
263
|
+
timestamp: request.headers["X-FlexOps-Timestamp"], # Unix seconds
|
|
264
|
+
secret: ENV.fetch("FLEXOPS_WEBHOOK_SECRET") # "whsec_..."
|
|
265
|
+
)
|
|
266
|
+
return head :unauthorized unless valid
|
|
267
|
+
|
|
268
|
+
# The body is the event data itself (no type/data envelope).
|
|
269
|
+
# The event name is in a header; test events send "test".
|
|
270
|
+
data = JSON.parse(payload)
|
|
271
|
+
case request.headers["X-FlexOps-Event"]
|
|
272
|
+
when "test"
|
|
273
|
+
# data: {"type"=>"test", "message"=>"...", "timestamp"=>"...", "subscriptionId"=>"..."}
|
|
274
|
+
when "TrackingUpdated"
|
|
275
|
+
# data["trackingNumber"], data["status"], ...
|
|
276
|
+
end
|
|
277
|
+
head :ok
|
|
278
|
+
end
|
|
114
279
|
```
|
|
115
280
|
|
|
281
|
+
Deliveries whose timestamp is more than 300 seconds from your clock (either way) are rejected to limit replays; pass `tolerance:` (seconds) to change that. `verify_signature!` takes the same arguments and raises `FlexOps::WebhookSignatureError` instead of returning `false`; its `code` says why (`WEBHOOK_SIGNATURE_MISMATCH`, `WEBHOOK_TIMESTAMP_OUTSIDE_TOLERANCE`, `WEBHOOK_INVALID_TIMESTAMP`, `WEBHOOK_MISSING_SIGNATURE`, `WEBHOOK_MISSING_SECRET`).
|
|
282
|
+
|
|
116
283
|
## Curl quickstart
|
|
117
284
|
|
|
118
285
|
Every SDK method is a thin wrapper around the FlexOps REST API. If you want to verify the API before committing to the SDK — or you're integrating from a language we don't ship a SDK for — these curl invocations hit the same endpoints:
|
|
@@ -128,24 +295,30 @@ curl -X POST https://gateway.flexops.io/api/shipping/rates \
|
|
|
128
295
|
"package": {"weight": 16, "weightUnit": "oz"}
|
|
129
296
|
}'
|
|
130
297
|
|
|
131
|
-
#
|
|
132
|
-
|
|
298
|
+
# Preview a live label; this does not purchase it.
|
|
299
|
+
# hazmatClassification 0 = not hazardous; required when there is no orderId.
|
|
300
|
+
curl -X POST https://gateway.flexops.io/api/shipping/labels \
|
|
133
301
|
-H "X-API-Key: fxk_live_..." \
|
|
134
302
|
-H "Content-Type: application/json" \
|
|
135
303
|
-d '{
|
|
136
|
-
"
|
|
137
|
-
"
|
|
138
|
-
"
|
|
139
|
-
"
|
|
140
|
-
"
|
|
304
|
+
"carrierCode": "USPS", "serviceCode": "GROUND_ADVANTAGE",
|
|
305
|
+
"origin": {"name": "Warehouse", "addressLine1": "123 Main St", "city": "New York", "stateProvince": "NY", "postalCode": "10001", "countryCode": "US"},
|
|
306
|
+
"destination": {"name": "Customer", "addressLine1": "456 Oak Ave", "city": "Los Angeles", "stateProvince": "CA", "postalCode": "90210", "countryCode": "US"},
|
|
307
|
+
"package": {"weight": 16, "weightUnit": "oz"},
|
|
308
|
+
"maximumPostageAmount": 10.25,
|
|
309
|
+
"hazmatClassification": 0
|
|
141
310
|
}'
|
|
142
311
|
|
|
312
|
+
# After explicit approval, resend the same body with confirmationToken from
|
|
313
|
+
# the preview and an Idempotency-Key header unique to this purchase.
|
|
314
|
+
# See the SDK example above; retain that key for retries.
|
|
315
|
+
|
|
143
316
|
# Track a shipment
|
|
144
|
-
curl https://gateway.flexops.io/api/
|
|
317
|
+
curl https://gateway.flexops.io/api/shipping/track/9400111899223456789012 \
|
|
145
318
|
-H "X-API-Key: fxk_live_..."
|
|
146
319
|
|
|
147
|
-
# Cancel a label
|
|
148
|
-
curl -X DELETE https://gateway.flexops.io/api/
|
|
320
|
+
# Cancel a label
|
|
321
|
+
curl -X DELETE "https://gateway.flexops.io/api/shipping/labels/lbl_123?carrierCode=USPS" \
|
|
149
322
|
-H "X-API-Key: fxk_live_..."
|
|
150
323
|
```
|
|
151
324
|
|
|
@@ -155,26 +328,27 @@ Use an `fxk_test_...` key instead of `fxk_live_...` to hit the sandbox environme
|
|
|
155
328
|
|
|
156
329
|
| Resource | Description |
|
|
157
330
|
|----------|-------------|
|
|
158
|
-
| `client.auth` | Login,
|
|
159
|
-
| `client.workspaces` |
|
|
160
|
-
| `client.shipping` | Rate shopping, labels, tracking, batch, cancel |
|
|
161
|
-
| `client.carriers` | USPS, UPS, FedEx
|
|
162
|
-
| `client.webhooks` | Subscription
|
|
163
|
-
| `client.wallet` |
|
|
164
|
-
| `client.insurance` |
|
|
165
|
-
| `client.returns` |
|
|
166
|
-
| `client.
|
|
167
|
-
| `client.
|
|
168
|
-
| `client.
|
|
169
|
-
| `client.
|
|
170
|
-
| `client.pickups` | Carrier pickup scheduling |
|
|
331
|
+
| `client.auth` | Login, token refresh, logout |
|
|
332
|
+
| `client.workspaces` | List and read workspaces; list, invite and remove members, change roles |
|
|
333
|
+
| `client.shipping` | Rate shopping, labels, tracking, address validation, batch, cancel |
|
|
334
|
+
| `client.carriers` | USPS, UPS, FedEx and DHL calls through the legacy proxy; writes are deprecated and need a user token |
|
|
335
|
+
| `client.webhooks` | Subscription create/update/delete, secret rotation, test events, delivery logs, signature verification |
|
|
336
|
+
| `client.wallet` | Workspace balance |
|
|
337
|
+
| `client.insurance` | Providers, quotes, policies, void, claims |
|
|
338
|
+
| `client.returns` | List and read returns; create RMAs, return labels, receive |
|
|
339
|
+
| `client.analytics` | Shipments, orders, carrier performance (legacy proxy reads) |
|
|
340
|
+
| `client.orders` | Order reads (legacy proxy) |
|
|
341
|
+
| `client.inventory` | Inventory reads (legacy proxy) |
|
|
342
|
+
| `client.pickups` | Schedule, list, read and cancel carrier pickups |
|
|
171
343
|
| `client.scan_forms` | USPS scan forms |
|
|
172
|
-
| `client.rules` | Shipping
|
|
173
|
-
| `client.
|
|
174
|
-
| `client.
|
|
175
|
-
| `client.recurring_shipments` |
|
|
176
|
-
| `client.
|
|
177
|
-
| `client.
|
|
344
|
+
| `client.rules` | Shipping rules: create, read, update, delete, reorder, test |
|
|
345
|
+
| `client.hs_codes` | HS code search and lookup, landed cost |
|
|
346
|
+
| `client.carbon_offsets` | Carbon offset quotes, purchases, summary and settings |
|
|
347
|
+
| `client.recurring_shipments` | Recurring shipment schedules: create, update, pause, resume, trigger, delete |
|
|
348
|
+
| `client.report_schedules` | Scheduled report emails: create, update, toggle, delete |
|
|
349
|
+
| `client.email_templates` | Tracking email templates: upsert, preview, delete |
|
|
350
|
+
|
|
351
|
+
API keys, workspace settings and account management are managed in the FlexOps portals.
|
|
178
352
|
|
|
179
353
|
## Configuration
|
|
180
354
|
|
|
@@ -189,7 +363,7 @@ client = FlexOps::Client.new(
|
|
|
189
363
|
|
|
190
364
|
## Requirements
|
|
191
365
|
|
|
192
|
-
- Ruby 3.
|
|
366
|
+
- Ruby 3.1+
|
|
193
367
|
|
|
194
368
|
## License
|
|
195
369
|
|
data/lib/flexops/client.rb
CHANGED
|
@@ -10,9 +10,9 @@ module FlexOps
|
|
|
10
10
|
class Client
|
|
11
11
|
attr_accessor :workspace_id
|
|
12
12
|
attr_reader :auth, :workspaces, :shipping, :carriers, :webhooks, :wallet,
|
|
13
|
-
:insurance, :returns, :
|
|
14
|
-
:pickups, :scan_forms, :rules, :
|
|
15
|
-
:recurring_shipments, :
|
|
13
|
+
:insurance, :returns, :analytics, :orders, :inventory,
|
|
14
|
+
:pickups, :scan_forms, :rules, :hs_codes, :carbon_offsets,
|
|
15
|
+
:recurring_shipments, :report_schedules, :email_templates
|
|
16
16
|
|
|
17
17
|
def initialize(api_key: nil, access_token: nil, base_url: "https://gateway.flexops.io", workspace_id: nil, timeout: 30)
|
|
18
18
|
@http = HttpClient.new(base_url: base_url, api_key: api_key, access_token: access_token, timeout: timeout)
|
|
@@ -28,18 +28,17 @@ module FlexOps
|
|
|
28
28
|
@wallet = Resources::Wallet.new(@http, ws_id_proc)
|
|
29
29
|
@insurance = Resources::Insurance.new(@http, ws_id_proc)
|
|
30
30
|
@returns = Resources::Returns.new(@http, ws_id_proc)
|
|
31
|
-
@api_keys = Resources::ApiKeys.new(@http, ws_id_proc)
|
|
32
31
|
@analytics = Resources::Analytics.new(@http)
|
|
33
32
|
@orders = Resources::Orders.new(@http)
|
|
34
33
|
@inventory = Resources::Inventory.new(@http)
|
|
35
34
|
@pickups = Resources::Pickups.new(@http, ws_id_proc)
|
|
36
35
|
@scan_forms = Resources::ScanForms.new(@http, ws_id_proc)
|
|
37
36
|
@rules = Resources::Rules.new(@http, ws_id_proc)
|
|
38
|
-
@
|
|
39
|
-
@
|
|
37
|
+
@hs_codes = Resources::HsCodes.new(@http)
|
|
38
|
+
@carbon_offsets = Resources::CarbonOffsets.new(@http, ws_id_proc)
|
|
40
39
|
@recurring_shipments = Resources::RecurringShipments.new(@http, ws_id_proc)
|
|
40
|
+
@report_schedules = Resources::ReportSchedules.new(@http, ws_id_proc)
|
|
41
41
|
@email_templates = Resources::EmailTemplates.new(@http, ws_id_proc)
|
|
42
|
-
@reports = Resources::Reports.new(@http, ws_id_proc)
|
|
43
42
|
end
|
|
44
43
|
|
|
45
44
|
def set_access_token(token)
|
data/lib/flexops/errors.rb
CHANGED
|
@@ -32,4 +32,13 @@ module FlexOps
|
|
|
32
32
|
@retry_after = retry_after
|
|
33
33
|
end
|
|
34
34
|
end
|
|
35
|
+
|
|
36
|
+
# Raised by Resources::Webhooks.verify_signature! when a webhook delivery
|
|
37
|
+
# is not authentic or not fresh. +code+ says why, for example
|
|
38
|
+
# "WEBHOOK_SIGNATURE_MISMATCH" or "WEBHOOK_TIMESTAMP_OUTSIDE_TOLERANCE".
|
|
39
|
+
class WebhookSignatureError < Error
|
|
40
|
+
def initialize(message, code:)
|
|
41
|
+
super(message, code: code)
|
|
42
|
+
end
|
|
43
|
+
end
|
|
35
44
|
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# ***********************************************************************
|
|
2
|
+
# Package : flexops
|
|
3
|
+
# Author : FlexOps, LLC
|
|
4
|
+
# Created : 2026-10-12
|
|
5
|
+
#
|
|
6
|
+
# Copyright (c) 2021-2026 by FlexOps, LLC. All rights reserved.
|
|
7
|
+
# ***********************************************************************
|
|
8
|
+
|
|
9
|
+
module FlexOps
|
|
10
|
+
# USPS HAZMAT classification, sent as the Gateway HazmatClassification number.
|
|
11
|
+
#
|
|
12
|
+
# There is no default: leave hazmatClassification out when you have no answer, or send
|
|
13
|
+
# HazmatClassification::NONE (0) to declare that the parcel holds no dangerous goods.
|
|
14
|
+
# A label without an orderId must declare one.
|
|
15
|
+
module HazmatClassification
|
|
16
|
+
NONE = 0
|
|
17
|
+
LIMITED_QUANTITY = 1
|
|
18
|
+
LITHIUM_BATTERY_CONTAINED_IN_EQUIPMENT = 2
|
|
19
|
+
LITHIUM_BATTERY_PACKED_WITH_EQUIPMENT = 3
|
|
20
|
+
LITHIUM_BATTERY_STANDALONE = 4
|
|
21
|
+
OTHER_RESTRICTED = 5
|
|
22
|
+
LITHIUM_BATTERY_USED_DEVICE = 6
|
|
23
|
+
|
|
24
|
+
ALL = {
|
|
25
|
+
NONE: NONE,
|
|
26
|
+
LIMITED_QUANTITY: LIMITED_QUANTITY,
|
|
27
|
+
LITHIUM_BATTERY_CONTAINED_IN_EQUIPMENT: LITHIUM_BATTERY_CONTAINED_IN_EQUIPMENT,
|
|
28
|
+
LITHIUM_BATTERY_PACKED_WITH_EQUIPMENT: LITHIUM_BATTERY_PACKED_WITH_EQUIPMENT,
|
|
29
|
+
LITHIUM_BATTERY_STANDALONE: LITHIUM_BATTERY_STANDALONE,
|
|
30
|
+
OTHER_RESTRICTED: OTHER_RESTRICTED,
|
|
31
|
+
LITHIUM_BATTERY_USED_DEVICE: LITHIUM_BATTERY_USED_DEVICE
|
|
32
|
+
}.freeze
|
|
33
|
+
end
|
|
34
|
+
end
|