square.rb 45.0.2.20260122 → 46.0.1.20260715
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/.fern/metadata.json +3 -2
- data/.fern/replay.lock +16 -0
- data/.fernignore +7 -0
- data/README.md +54 -0
- data/lib/square/catalog/client.rb +14 -1
- data/lib/square/catalog/object/client.rb +4 -0
- data/lib/square/client.rb +6 -1
- data/lib/square/inventory/types/create_inventory_adjustment_reason_request.rb +12 -0
- data/lib/square/inventory/types/delete_inventory_adjustment_reason_request.rb +11 -0
- data/lib/square/inventory/types/list_inventory_adjustment_reasons_request.rb +12 -0
- data/lib/square/inventory/types/restore_inventory_adjustment_reason_request.rb +11 -0
- data/lib/square/inventory/types/retrieve_inventory_adjustment_reason_request.rb +11 -0
- data/lib/square/inventory/types/update_inventory_adjustment_reason_request.rb +12 -0
- data/lib/square/inventory/types/update_inventory_adjustment_request.rb +12 -0
- data/lib/square/payments/types/create_payment_request.rb +1 -0
- data/lib/square/refunds/types/refund_payment_request.rb +1 -0
- data/lib/square/reporting/client.rb +83 -0
- data/lib/square/reporting/types/load_request.rb +13 -0
- data/lib/square/reporting_helper.rb +147 -0
- data/lib/square/types/batch_retrieve_inventory_changes_request.rb +2 -0
- data/lib/square/types/batch_retrieve_inventory_changes_sort.rb +10 -0
- data/lib/square/types/batch_retrieve_inventory_changes_sort_field.rb +23 -0
- data/lib/square/types/cache_mode.rb +14 -0
- data/lib/square/types/card_payment_details.rb +2 -0
- data/lib/square/types/card_surcharge_details.rb +14 -0
- data/lib/square/types/catalog_item_variation.rb +1 -0
- data/lib/square/types/catalog_item_variation_vendor_information.rb +12 -0
- data/lib/square/types/create_inventory_adjustment_reason_response.rb +12 -0
- data/lib/square/types/cube.rb +20 -0
- data/lib/square/types/cube_join.rb +10 -0
- data/lib/square/types/cube_type.rb +12 -0
- data/lib/square/types/custom_numeric_format.rb +12 -0
- data/lib/square/types/custom_time_format.rb +11 -0
- data/lib/square/types/delete_inventory_adjustment_reason_response.rb +12 -0
- data/lib/square/types/digital_wallet_details.rb +1 -0
- data/lib/square/types/dimension.rb +21 -0
- data/lib/square/types/dimension_granularity.rb +14 -0
- data/lib/square/types/dimension_order.rb +12 -0
- data/lib/square/types/electronic_money_details.rb +10 -0
- data/lib/square/types/exclude_strategy.rb +1 -0
- data/lib/square/types/felica_details.rb +12 -0
- data/lib/square/types/felica_details_felica_brand.rb +14 -0
- data/lib/square/types/folder.rb +10 -0
- data/lib/square/types/format.rb +16 -0
- data/lib/square/types/format_description.rb +12 -0
- data/lib/square/types/fulfillment.rb +1 -0
- data/lib/square/types/fulfillment_in_store_details.rb +16 -0
- data/lib/square/types/fulfillment_type.rb +1 -0
- data/lib/square/types/get_inventory_transfer_response.rb +16 -3
- data/lib/square/types/hierarchy.rb +12 -0
- data/lib/square/types/inventory_adjustment.rb +6 -1
- data/lib/square/types/inventory_adjustment_reason.rb +15 -0
- data/lib/square/types/inventory_adjustment_reason_direction.rb +12 -0
- data/lib/square/types/inventory_adjustment_reason_id.rb +11 -0
- data/lib/square/types/inventory_adjustment_reason_id_type.rb +26 -0
- data/lib/square/types/inventory_change.rb +0 -1
- data/lib/square/types/inventory_change_type.rb +0 -1
- data/lib/square/types/inventory_count.rb +2 -1
- data/lib/square/types/inventory_physical_count.rb +1 -0
- data/lib/square/types/inventory_state.rb +1 -0
- data/lib/square/types/join_hint.rb +23 -0
- data/lib/square/types/join_subquery.rb +12 -0
- data/lib/square/types/lightning_details.rb +10 -0
- data/lib/square/types/link_format.rb +11 -0
- data/lib/square/types/list_inventory_adjustment_reasons_response.rb +12 -0
- data/lib/square/types/load_response.rb +19 -0
- data/lib/square/types/load_result_annotation.rb +12 -0
- data/lib/square/types/load_result_data.rb +15 -0
- data/lib/square/types/load_result_data_columnar.rb +12 -0
- data/lib/square/types/load_result_data_compact.rb +12 -0
- data/lib/square/types/load_result_data_row.rb +23 -0
- data/lib/square/types/loyalty_event.rb +2 -2
- data/lib/square/types/measure.rb +19 -0
- data/lib/square/types/metadata_response.rb +10 -0
- data/lib/square/types/nested_folder.rb +10 -0
- data/lib/square/types/order_line_item_modifier.rb +1 -0
- data/lib/square/types/payment.rb +3 -0
- data/lib/square/types/payment_refund.rb +1 -0
- data/lib/square/types/query.rb +20 -0
- data/lib/square/types/query_filter.rb +13 -0
- data/lib/square/types/query_filter_and.rb +9 -0
- data/lib/square/types/query_filter_condition.rb +11 -0
- data/lib/square/types/query_filter_or.rb +9 -0
- data/lib/square/types/reporting_error.rb +11 -0
- data/lib/square/types/restore_inventory_adjustment_reason_response.rb +12 -0
- data/lib/square/types/retrieve_inventory_adjustment_reason_response.rb +12 -0
- data/lib/square/types/search_orders_source_filter.rb +0 -2
- data/lib/square/types/segment.rb +13 -0
- data/lib/square/types/simple_format.rb +16 -0
- data/lib/square/types/time_dimension.rb +11 -0
- data/lib/square/types/time_dimension_date_range.rb +13 -0
- data/lib/square/types/update_inventory_adjustment_reason_response.rb +12 -0
- data/lib/square/types/update_inventory_adjustment_response.rb +10 -0
- data/lib/square/version.rb +1 -1
- data/lib/square.rb +67 -4
- data/reference.md +776 -65
- data/wiremock/wiremock-mappings.json +1 -1
- metadata +70 -4
- data/lib/square/types/inventory_transfer.rb +0 -23
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5aabb765f06b7f91a9943e2996d342aee7d7ebdc3132665984130674ad9832a7
|
|
4
|
+
data.tar.gz: aeeff982ae4a52da0c21a00c81a11ae51e0f18feb11bee280acd94410e66ec73
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: dd3ff2a54d789c933156f113bb6ff472352034d29af46051d0b633a0002cb513699ef25b644784cf63c7f7bf19c580ec9405f95f705188fba3ff6e6e6dcb67ba
|
|
7
|
+
data.tar.gz: 6ff2f9a734e0df1480c6da6d4d93cd19c8a55ebedb24cb6aa7bf84abfc6b28d34462527832a7196c3e7b3e498712e010eca6d20360fa2b2b8398d6a4fd8775eb
|
data/.fern/metadata.json
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
{
|
|
2
|
-
"cliVersion": "
|
|
2
|
+
"cliVersion": "5.56.0",
|
|
3
3
|
"generatorName": "fernapi/fern-ruby-sdk",
|
|
4
4
|
"generatorVersion": "1.0.0-rc84",
|
|
5
5
|
"generatorConfig": {
|
|
6
6
|
"enableWireTests": true
|
|
7
7
|
},
|
|
8
|
-
"
|
|
8
|
+
"originGitCommit": "b2dac8b2c1b9fe87c0e1fe3eb6257b259caa0715",
|
|
9
|
+
"sdkVersion": "46.0.1.20260715"
|
|
9
10
|
}
|
data/.fern/replay.lock
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# DO NOT EDIT MANUALLY - Managed by Fern Replay
|
|
2
|
+
version: "1.0"
|
|
3
|
+
generations:
|
|
4
|
+
- commit_sha: f631923c98d9161665156652789a58902009b805
|
|
5
|
+
tree_hash: 872074a659baa229a5564e34250e9b648d1751fd
|
|
6
|
+
timestamp: 2026-05-19T21:18:26.039Z
|
|
7
|
+
cli_version: unknown
|
|
8
|
+
generator_versions: {}
|
|
9
|
+
- commit_sha: 0df987cc98c660edfc8d9da6a8a62443df8d4754
|
|
10
|
+
tree_hash: 83a1da975e9400250bba4bf52a2ee62f320d33f5
|
|
11
|
+
timestamp: 2026-07-14T17:00:55.993Z
|
|
12
|
+
cli_version: unknown
|
|
13
|
+
generator_versions:
|
|
14
|
+
fernapi/fern-ruby-sdk: 1.0.0-rc84
|
|
15
|
+
current_generation: 0df987cc98c660edfc8d9da6a8a62443df8d4754
|
|
16
|
+
patches: []
|
data/.fernignore
CHANGED
|
@@ -7,6 +7,10 @@ test/custom
|
|
|
7
7
|
.github/workflows
|
|
8
8
|
README.md
|
|
9
9
|
lib/square/file_param.rb
|
|
10
|
+
|
|
11
|
+
# Custom polling helper for the Reporting API (load_and_wait + Continue-wait
|
|
12
|
+
# retry loop). Unit test lives under the already-ignored test/custom. FER-11257.
|
|
13
|
+
lib/square/reporting_helper.rb
|
|
10
14
|
Gemfile.custom
|
|
11
15
|
custom.gemspec.rb
|
|
12
16
|
|
|
@@ -18,3 +22,6 @@ lib/square/transfer_orders/client.rb
|
|
|
18
22
|
# Iterator does not handle nil item fields (when API returns nil instead of empty array for no items)
|
|
19
23
|
# Manually added nil checks to avoid calling .shift/.empty? on nil
|
|
20
24
|
lib/square/internal/iterators/item_iterator.rb
|
|
25
|
+
.fern/replay.lock
|
|
26
|
+
.fern/replay.yml
|
|
27
|
+
.gitattributes
|
data/README.md
CHANGED
|
@@ -255,6 +255,60 @@ response = client.payments.create(..., {
|
|
|
255
255
|
})
|
|
256
256
|
```
|
|
257
257
|
|
|
258
|
+
## Reporting API
|
|
259
|
+
|
|
260
|
+
The [Reporting API](https://developer.squareup.com/docs/reporting-api/overview) exposes two
|
|
261
|
+
polling endpoints under `client.reporting`:
|
|
262
|
+
|
|
263
|
+
- `get_metadata` — describes the data you can query (cubes, measures, dimensions, segments).
|
|
264
|
+
Call it first to discover the schema.
|
|
265
|
+
- `load` — runs a reporting query and returns the aggregated result rows in `data`.
|
|
266
|
+
|
|
267
|
+
`load` is asynchronous: while a query is still being computed it returns an HTTP 200 whose body
|
|
268
|
+
is `{ "error": "Continue wait" }` rather than the results. Callers are expected to re-send the
|
|
269
|
+
identical request, with backoff, until real results arrive.
|
|
270
|
+
|
|
271
|
+
The SDK ships a `.fernignore`-protected helper that owns that retry loop. Require it explicitly
|
|
272
|
+
to add `load_and_wait` to `client.reporting`:
|
|
273
|
+
|
|
274
|
+
```ruby
|
|
275
|
+
require "square"
|
|
276
|
+
require "square/reporting_helper"
|
|
277
|
+
|
|
278
|
+
client = Square::Client.new(token: ENV.fetch("SQUARE_TOKEN"))
|
|
279
|
+
|
|
280
|
+
# 1. Discover the schema.
|
|
281
|
+
metadata = client.reporting.get_metadata
|
|
282
|
+
|
|
283
|
+
# 2. Run a query and transparently poll until it resolves.
|
|
284
|
+
response = client.reporting.load_and_wait(
|
|
285
|
+
query: {
|
|
286
|
+
measures: ["orders.count"],
|
|
287
|
+
time_dimensions: [{ dimension: "orders.created_at", granularity: "day" }]
|
|
288
|
+
}
|
|
289
|
+
)
|
|
290
|
+
|
|
291
|
+
response.data.each { |row| puts row }
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
`load_and_wait` accepts optional polling parameters (defaults shown): `max_attempts: 20`,
|
|
295
|
+
`initial_delay: 2.0`, `max_delay: 20.0`, `backoff_factor: 2.0` (seconds). It raises
|
|
296
|
+
`Square::Reporting::ContinueWaitTimeoutError` if the query has not resolved within
|
|
297
|
+
`max_attempts`. Pass a `should_cancel` predicate to abort the loop early (the Ruby idiom for an
|
|
298
|
+
abort signal); it raises `Square::Reporting::PollingCancelledError` when the predicate returns a
|
|
299
|
+
truthy value:
|
|
300
|
+
|
|
301
|
+
```ruby
|
|
302
|
+
deadline = Time.now + 60
|
|
303
|
+
response = client.reporting.load_and_wait(
|
|
304
|
+
query: { measures: ["orders.count"] },
|
|
305
|
+
should_cancel: -> { Time.now > deadline }
|
|
306
|
+
)
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
> **Note:** The Reporting API is production-only — sandbox requests return 404, and a sandbox
|
|
310
|
+
> token against production returns 401. Use a production, reporting-provisioned token.
|
|
311
|
+
|
|
258
312
|
## Contributing
|
|
259
313
|
|
|
260
314
|
While we value open-source contributions to this SDK, this library is generated programmatically. Additions made directly to this library would have to be moved over to our generation code, otherwise they would be overwritten upon the next generated release. Feel free to open a PR as a proof of concept, but know that we will not be able to merge it as-is. We suggest opening an issue first to discuss with us!
|
|
@@ -106,9 +106,15 @@ module Square
|
|
|
106
106
|
# request (items, variations, modifier lists, discounts, and taxes) is no more
|
|
107
107
|
# than 10,000.
|
|
108
108
|
#
|
|
109
|
+
# This endpoint uses full-replacement semantics. The client must send the complete object, and any
|
|
110
|
+
# field absent from the request is interpreted as an intentional clear. This logic applies to
|
|
111
|
+
# nested objects as well. For example, omitting inlined children like variations will delete them.
|
|
112
|
+
#
|
|
109
113
|
# To ensure consistency, only one update request is processed at a time per seller account.
|
|
110
114
|
# While one (batch or non-batch) update request is being processed, other (batched and non-batched)
|
|
111
|
-
# update requests are rejected with the `429` error code.
|
|
115
|
+
# update requests are rejected with the `429` error code. Prefer batching related changes into a
|
|
116
|
+
# single call rather than issuing many small writes, since each write acquires the lock separately
|
|
117
|
+
# and parallel writes to the same seller will contend with each other, producing `429` errors.
|
|
112
118
|
#
|
|
113
119
|
# @param request_options [Hash]
|
|
114
120
|
# @param params [Square::Catalog::Types::BatchUpsertCatalogObjectsRequest]
|
|
@@ -181,6 +187,8 @@ module Square
|
|
|
181
187
|
# The `types` parameter is specified as a comma-separated list of the
|
|
182
188
|
# [CatalogObjectType](entity:CatalogObjectType) values,
|
|
183
189
|
# for example, "`ITEM`, `ITEM_VARIATION`, `MODIFIER`, `MODIFIER_LIST`, `CATEGORY`, `DISCOUNT`, `TAX`, `IMAGE`".
|
|
190
|
+
# Always specify `types` explicitly. When upgrading to a newer API version, omitting `types` may
|
|
191
|
+
# cause new object types to appear in results that were not returned under the previous version.
|
|
184
192
|
#
|
|
185
193
|
# __Important:__ ListCatalog does not return deleted catalog items. To retrieve
|
|
186
194
|
# deleted catalog items, use [SearchCatalogObjects](api-endpoint:Catalog-SearchCatalogObjects)
|
|
@@ -251,6 +259,11 @@ module Square
|
|
|
251
259
|
# variations, whereas `SearchCatalogObjects` does.
|
|
252
260
|
# - The both endpoints have different call conventions, including the query filter formats.
|
|
253
261
|
#
|
|
262
|
+
# The `object_types` parameter is specified as a list of [CatalogObjectType](entity:CatalogObjectType) values.
|
|
263
|
+
# Always specify `object_types` explicitly. When upgrading to a newer API version, omitting
|
|
264
|
+
# `object_types` may cause new object types to appear in results that were not returned under
|
|
265
|
+
# the previous version.
|
|
266
|
+
#
|
|
254
267
|
# @param request_options [Hash]
|
|
255
268
|
# @param params [Square::Catalog::Types::SearchCatalogObjectsRequest]
|
|
256
269
|
# @option request_options [String] :base_url
|
|
@@ -13,6 +13,10 @@ module Square
|
|
|
13
13
|
|
|
14
14
|
# Creates a new or updates the specified [CatalogObject](entity:CatalogObject).
|
|
15
15
|
#
|
|
16
|
+
# This endpoint uses full-replacement semantics. The client must send the complete object, and any
|
|
17
|
+
# field absent from the request is interpreted as an intentional clear. This logic applies to
|
|
18
|
+
# nested objects as well. For example, omitting inlined children like variations will delete them.
|
|
19
|
+
#
|
|
16
20
|
# To ensure consistency, only one update request is processed at a time per seller account.
|
|
17
21
|
# While one (batch or non-batch) update request is being processed, other (batched and non-batched)
|
|
18
22
|
# update requests are rejected with the `429` error code.
|
data/lib/square/client.rb
CHANGED
|
@@ -10,7 +10,7 @@ module Square
|
|
|
10
10
|
@raw_client = Square::Internal::Http::RawClient.new(
|
|
11
11
|
base_url: base_url || Square::Environment::PRODUCTION,
|
|
12
12
|
headers: {
|
|
13
|
-
"User-Agent" => "square.rb/
|
|
13
|
+
"User-Agent" => "square.rb/46.0.1.20260715",
|
|
14
14
|
"X-Fern-Language" => "Ruby",
|
|
15
15
|
Authorization: "Bearer #{token}"
|
|
16
16
|
}
|
|
@@ -182,6 +182,11 @@ module Square
|
|
|
182
182
|
@vendors ||= Square::Vendors::Client.new(client: @raw_client)
|
|
183
183
|
end
|
|
184
184
|
|
|
185
|
+
# @return [Square::Reporting::Client]
|
|
186
|
+
def reporting
|
|
187
|
+
@reporting ||= Square::Reporting::Client.new(client: @raw_client)
|
|
188
|
+
end
|
|
189
|
+
|
|
185
190
|
# @return [Square::CashDrawers::Client]
|
|
186
191
|
def cash_drawers
|
|
187
192
|
@cash_drawers ||= Square::CashDrawers::Client.new(client: @raw_client)
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Square
|
|
4
|
+
module Inventory
|
|
5
|
+
module Types
|
|
6
|
+
class CreateInventoryAdjustmentReasonRequest < Internal::Types::Model
|
|
7
|
+
field :idempotency_key, -> { String }, optional: false, nullable: false
|
|
8
|
+
field :adjustment_reason, -> { Square::Types::InventoryAdjustmentReason }, optional: false, nullable: false
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Square
|
|
4
|
+
module Inventory
|
|
5
|
+
module Types
|
|
6
|
+
class DeleteInventoryAdjustmentReasonRequest < Internal::Types::Model
|
|
7
|
+
field :reason_id, -> { Square::Types::InventoryAdjustmentReasonId }, optional: false, nullable: false
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Square
|
|
4
|
+
module Inventory
|
|
5
|
+
module Types
|
|
6
|
+
class ListInventoryAdjustmentReasonsRequest < Internal::Types::Model
|
|
7
|
+
field :include_deleted, -> { Internal::Types::Boolean }, optional: true, nullable: false
|
|
8
|
+
field :include_system_codes, -> { Internal::Types::Boolean }, optional: true, nullable: false
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Square
|
|
4
|
+
module Inventory
|
|
5
|
+
module Types
|
|
6
|
+
class RestoreInventoryAdjustmentReasonRequest < Internal::Types::Model
|
|
7
|
+
field :reason_id, -> { Square::Types::InventoryAdjustmentReasonId }, optional: false, nullable: false
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Square
|
|
4
|
+
module Inventory
|
|
5
|
+
module Types
|
|
6
|
+
class RetrieveInventoryAdjustmentReasonRequest < Internal::Types::Model
|
|
7
|
+
field :reason_id, -> { Square::Types::InventoryAdjustmentReasonId }, optional: false, nullable: false
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Square
|
|
4
|
+
module Inventory
|
|
5
|
+
module Types
|
|
6
|
+
class UpdateInventoryAdjustmentReasonRequest < Internal::Types::Model
|
|
7
|
+
field :reason_id, -> { Square::Types::InventoryAdjustmentReasonId }, optional: false, nullable: false
|
|
8
|
+
field :adjustment_reason, -> { Square::Types::InventoryAdjustmentReason }, optional: false, nullable: false
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Square
|
|
4
|
+
module Inventory
|
|
5
|
+
module Types
|
|
6
|
+
class UpdateInventoryAdjustmentRequest < Internal::Types::Model
|
|
7
|
+
field :idempotency_key, -> { String }, optional: false, nullable: false
|
|
8
|
+
field :adjustment, -> { Square::Types::InventoryAdjustment }, optional: false, nullable: false
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
@@ -9,6 +9,7 @@ module Square
|
|
|
9
9
|
field :amount_money, -> { Square::Types::Money }, optional: true, nullable: false
|
|
10
10
|
field :tip_money, -> { Square::Types::Money }, optional: true, nullable: false
|
|
11
11
|
field :app_fee_money, -> { Square::Types::Money }, optional: true, nullable: false
|
|
12
|
+
field :app_fee_allocations, -> { Internal::Types::Array[Object] }, optional: true, nullable: false
|
|
12
13
|
field :delay_duration, -> { String }, optional: true, nullable: false
|
|
13
14
|
field :delay_action, -> { String }, optional: true, nullable: false
|
|
14
15
|
field :autocomplete, -> { Internal::Types::Boolean }, optional: true, nullable: false
|
|
@@ -7,6 +7,7 @@ module Square
|
|
|
7
7
|
field :idempotency_key, -> { String }, optional: false, nullable: false
|
|
8
8
|
field :amount_money, -> { Square::Types::Money }, optional: false, nullable: false
|
|
9
9
|
field :app_fee_money, -> { Square::Types::Money }, optional: true, nullable: false
|
|
10
|
+
field :app_fee_allocations, -> { Internal::Types::Array[Object] }, optional: true, nullable: false
|
|
10
11
|
field :payment_id, -> { String }, optional: true, nullable: false
|
|
11
12
|
field :destination_id, -> { String }, optional: true, nullable: false
|
|
12
13
|
field :unlinked, -> { Internal::Types::Boolean }, optional: true, nullable: false
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Square
|
|
4
|
+
module Reporting
|
|
5
|
+
class Client
|
|
6
|
+
# @param client [Square::Internal::Http::RawClient]
|
|
7
|
+
#
|
|
8
|
+
# @return [void]
|
|
9
|
+
def initialize(client:)
|
|
10
|
+
@client = client
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
# Describes the data available to query: the cubes, views, measures, dimensions, and segments you can reference in
|
|
14
|
+
# a reporting query. Call this first to discover the schema, then pass the members you need to `load`.
|
|
15
|
+
#
|
|
16
|
+
# @param request_options [Hash]
|
|
17
|
+
# @param params [Hash]
|
|
18
|
+
# @option request_options [String] :base_url
|
|
19
|
+
# @option request_options [Hash{String => Object}] :additional_headers
|
|
20
|
+
# @option request_options [Hash{String => Object}] :additional_query_parameters
|
|
21
|
+
# @option request_options [Hash{String => Object}] :additional_body_parameters
|
|
22
|
+
# @option request_options [Integer] :timeout_in_seconds
|
|
23
|
+
#
|
|
24
|
+
# @return [Square::Types::MetadataResponse]
|
|
25
|
+
def get_metadata(request_options: {}, **params)
|
|
26
|
+
Square::Internal::Types::Utils.normalize_keys(params)
|
|
27
|
+
request = Square::Internal::JSON::Request.new(
|
|
28
|
+
base_url: request_options[:base_url],
|
|
29
|
+
method: "GET",
|
|
30
|
+
path: "reporting/v1/meta",
|
|
31
|
+
request_options: request_options
|
|
32
|
+
)
|
|
33
|
+
begin
|
|
34
|
+
response = @client.send(request)
|
|
35
|
+
rescue Net::HTTPRequestTimeout
|
|
36
|
+
raise Square::Errors::TimeoutError
|
|
37
|
+
end
|
|
38
|
+
code = response.code.to_i
|
|
39
|
+
if code.between?(200, 299)
|
|
40
|
+
Square::Types::MetadataResponse.load(response.body)
|
|
41
|
+
else
|
|
42
|
+
error_class = Square::Errors::ResponseError.subclass_for_code(code)
|
|
43
|
+
raise error_class.new(response.body, code: code)
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# Runs a reporting query against the discovered schema and returns the aggregated results. Long-running queries
|
|
48
|
+
# may return a "Continue wait" response while processing — retry the same request until results are ready.
|
|
49
|
+
#
|
|
50
|
+
# @param request_options [Hash]
|
|
51
|
+
# @param params [Square::Reporting::Types::LoadRequest]
|
|
52
|
+
# @option request_options [String] :base_url
|
|
53
|
+
# @option request_options [Hash{String => Object}] :additional_headers
|
|
54
|
+
# @option request_options [Hash{String => Object}] :additional_query_parameters
|
|
55
|
+
# @option request_options [Hash{String => Object}] :additional_body_parameters
|
|
56
|
+
# @option request_options [Integer] :timeout_in_seconds
|
|
57
|
+
#
|
|
58
|
+
# @return [Square::Types::LoadResponse]
|
|
59
|
+
def load(request_options: {}, **params)
|
|
60
|
+
params = Square::Internal::Types::Utils.normalize_keys(params)
|
|
61
|
+
request = Square::Internal::JSON::Request.new(
|
|
62
|
+
base_url: request_options[:base_url],
|
|
63
|
+
method: "POST",
|
|
64
|
+
path: "reporting/v1/load",
|
|
65
|
+
body: Square::Reporting::Types::LoadRequest.new(params).to_h,
|
|
66
|
+
request_options: request_options
|
|
67
|
+
)
|
|
68
|
+
begin
|
|
69
|
+
response = @client.send(request)
|
|
70
|
+
rescue Net::HTTPRequestTimeout
|
|
71
|
+
raise Square::Errors::TimeoutError
|
|
72
|
+
end
|
|
73
|
+
code = response.code.to_i
|
|
74
|
+
if code.between?(200, 299)
|
|
75
|
+
Square::Types::LoadResponse.load(response.body)
|
|
76
|
+
else
|
|
77
|
+
error_class = Square::Errors::ResponseError.subclass_for_code(code)
|
|
78
|
+
raise error_class.new(response.body, code: code)
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Square
|
|
4
|
+
module Reporting
|
|
5
|
+
module Types
|
|
6
|
+
class LoadRequest < Internal::Types::Model
|
|
7
|
+
field :query_type, -> { String }, optional: true, nullable: false, api_name: "queryType"
|
|
8
|
+
field :cache, -> { Square::Types::CacheMode }, optional: true, nullable: false
|
|
9
|
+
field :query, -> { Square::Types::Query }, optional: true, nullable: false
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "../square"
|
|
4
|
+
|
|
5
|
+
module Square
|
|
6
|
+
module Reporting
|
|
7
|
+
# Raised by {Client#load_and_wait} when a reporting query has not finished
|
|
8
|
+
# after the configured maximum number of attempts.
|
|
9
|
+
class ContinueWaitTimeoutError < StandardError; end
|
|
10
|
+
|
|
11
|
+
# Raised by {Client#load_and_wait} when the caller-supplied +should_cancel+
|
|
12
|
+
# predicate returns a truthy value, aborting the polling loop.
|
|
13
|
+
class PollingCancelledError < StandardError; end
|
|
14
|
+
|
|
15
|
+
# Custom, +.fernignore+-protected polling helper for the Reporting API.
|
|
16
|
+
#
|
|
17
|
+
# The +/reporting/v1/load+ endpoint is asynchronous: a query that is still
|
|
18
|
+
# being computed comes back as an HTTP 200 whose body is
|
|
19
|
+
# +{ "error": "Continue wait" }+ rather than the results. Callers are expected
|
|
20
|
+
# to re-send the identical request, with backoff, until real results arrive.
|
|
21
|
+
# This file reopens the generated {Square::Reporting::Client} to add
|
|
22
|
+
# +load_and_wait+, which owns that retry loop.
|
|
23
|
+
#
|
|
24
|
+
# @example
|
|
25
|
+
# require "square"
|
|
26
|
+
# require "square/reporting_helper"
|
|
27
|
+
#
|
|
28
|
+
# client = Square::Client.new(token: ENV.fetch("SQUARE_TOKEN"))
|
|
29
|
+
# response = client.reporting.load_and_wait(query: { ... })
|
|
30
|
+
class Client
|
|
31
|
+
# The value of the +error+ field the Reporting API returns on an HTTP 200
|
|
32
|
+
# while a +/reporting/v1/load+ query is still processing. It is NOT a
|
|
33
|
+
# failure — the identical request should be re-sent until real results
|
|
34
|
+
# arrive. See https://developer.squareup.com/docs/reporting-api/overview.
|
|
35
|
+
CONTINUE_WAIT_SENTINEL = "Continue wait"
|
|
36
|
+
|
|
37
|
+
# Default polling parameters for {#load_and_wait}.
|
|
38
|
+
DEFAULT_MAX_ATTEMPTS = 20
|
|
39
|
+
DEFAULT_INITIAL_DELAY = 2.0
|
|
40
|
+
DEFAULT_MAX_DELAY = 20.0
|
|
41
|
+
DEFAULT_BACKOFF_FACTOR = 2.0
|
|
42
|
+
|
|
43
|
+
# Granularity (seconds) at which a backoff wait checks +should_cancel+, so
|
|
44
|
+
# cancellation stays responsive even during a long delay.
|
|
45
|
+
POLL_TICK = 0.1
|
|
46
|
+
|
|
47
|
+
# Runs a reporting query and transparently polls until it resolves,
|
|
48
|
+
# returning the final {Square::Types::LoadResponse}.
|
|
49
|
+
#
|
|
50
|
+
# A query that is still being computed comes back as an HTTP 200 whose body
|
|
51
|
+
# is +{ "error": "Continue wait" }+. That body deserializes into a
|
|
52
|
+
# +LoadResponse+ whose +error+ key lands in the model's extra fields (it is
|
|
53
|
+
# not a declared field) while +results+ stays +nil+; that is the signal to
|
|
54
|
+
# retry. +load_and_wait+ re-sends the identical request with exponential
|
|
55
|
+
# backoff until real results arrive.
|
|
56
|
+
#
|
|
57
|
+
# @param request_options [Hash] forwarded verbatim to each underlying
|
|
58
|
+
# {#load} call.
|
|
59
|
+
# @param max_attempts [Integer] maximum number of +load+ calls before
|
|
60
|
+
# giving up. Defaults to {DEFAULT_MAX_ATTEMPTS}.
|
|
61
|
+
# @param initial_delay [Numeric] delay (seconds) before the first retry.
|
|
62
|
+
# Defaults to {DEFAULT_INITIAL_DELAY}.
|
|
63
|
+
# @param max_delay [Numeric] upper bound (seconds) on the backoff delay.
|
|
64
|
+
# Defaults to {DEFAULT_MAX_DELAY}.
|
|
65
|
+
# @param backoff_factor [Numeric] multiplier applied to the delay after each
|
|
66
|
+
# attempt. Defaults to {DEFAULT_BACKOFF_FACTOR}.
|
|
67
|
+
# @param should_cancel [#call, nil] optional predicate checked before each
|
|
68
|
+
# attempt and during each backoff wait; when it returns a truthy value the
|
|
69
|
+
# loop aborts with {PollingCancelledError}. This is the Ruby idiom for
|
|
70
|
+
# TypeScript's +AbortSignal+ / Go's +context.Context+.
|
|
71
|
+
# @param params [Hash] the reporting query, forwarded verbatim to {#load}
|
|
72
|
+
# (same keyword arguments as a direct +load+ call).
|
|
73
|
+
#
|
|
74
|
+
# @return [Square::Types::LoadResponse] the resolved response.
|
|
75
|
+
#
|
|
76
|
+
# @raise [ContinueWaitTimeoutError] if the query has not resolved within
|
|
77
|
+
# +max_attempts+ attempts.
|
|
78
|
+
# @raise [PollingCancelledError] if +should_cancel+ returns a truthy value.
|
|
79
|
+
def load_and_wait(
|
|
80
|
+
request_options: {},
|
|
81
|
+
max_attempts: DEFAULT_MAX_ATTEMPTS,
|
|
82
|
+
initial_delay: DEFAULT_INITIAL_DELAY,
|
|
83
|
+
max_delay: DEFAULT_MAX_DELAY,
|
|
84
|
+
backoff_factor: DEFAULT_BACKOFF_FACTOR,
|
|
85
|
+
should_cancel: nil,
|
|
86
|
+
**params
|
|
87
|
+
)
|
|
88
|
+
delay = initial_delay
|
|
89
|
+
attempt = 1
|
|
90
|
+
|
|
91
|
+
loop do
|
|
92
|
+
raise PollingCancelledError if should_cancel&.call
|
|
93
|
+
|
|
94
|
+
response = load(request_options: request_options, **params)
|
|
95
|
+
return response unless continue_wait?(response)
|
|
96
|
+
|
|
97
|
+
break if attempt >= max_attempts
|
|
98
|
+
|
|
99
|
+
cancellable_sleep(delay, should_cancel)
|
|
100
|
+
|
|
101
|
+
attempt += 1
|
|
102
|
+
delay = [delay * backoff_factor, max_delay].min
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
raise ContinueWaitTimeoutError,
|
|
106
|
+
"Reporting query did not complete after #{max_attempts} attempts " \
|
|
107
|
+
"(#{CONTINUE_WAIT_SENTINEL.inspect})"
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
private
|
|
111
|
+
|
|
112
|
+
# @param response [Square::Types::LoadResponse]
|
|
113
|
+
# @return [Boolean] whether +response+ is the "still processing" sentinel
|
|
114
|
+
# rather than a real result.
|
|
115
|
+
def continue_wait?(response)
|
|
116
|
+
return false if response.nil?
|
|
117
|
+
|
|
118
|
+
response.to_h["error"] == CONTINUE_WAIT_SENTINEL
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
# Sleeps for +seconds+, waking every {POLL_TICK} to honor +should_cancel+.
|
|
122
|
+
#
|
|
123
|
+
# @param seconds [Numeric]
|
|
124
|
+
# @param should_cancel [#call, nil]
|
|
125
|
+
# @return [void]
|
|
126
|
+
# @raise [PollingCancelledError] if +should_cancel+ becomes truthy.
|
|
127
|
+
def cancellable_sleep(seconds, should_cancel)
|
|
128
|
+
return if seconds <= 0
|
|
129
|
+
|
|
130
|
+
deadline = monotonic_now + seconds
|
|
131
|
+
loop do
|
|
132
|
+
raise PollingCancelledError if should_cancel&.call
|
|
133
|
+
|
|
134
|
+
remaining = deadline - monotonic_now
|
|
135
|
+
break if remaining <= 0
|
|
136
|
+
|
|
137
|
+
sleep([remaining, POLL_TICK].min)
|
|
138
|
+
end
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
# @return [Float] a monotonic clock reading in seconds.
|
|
142
|
+
def monotonic_now
|
|
143
|
+
Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
|
144
|
+
end
|
|
145
|
+
end
|
|
146
|
+
end
|
|
147
|
+
end
|
|
@@ -11,6 +11,8 @@ module Square
|
|
|
11
11
|
field :updated_before, -> { String }, optional: true, nullable: false
|
|
12
12
|
field :cursor, -> { String }, optional: true, nullable: false
|
|
13
13
|
field :limit, -> { Integer }, optional: true, nullable: false
|
|
14
|
+
field :sort, -> { Square::Types::BatchRetrieveInventoryChangesSort }, optional: true, nullable: false
|
|
15
|
+
field :reason_ids, -> { Internal::Types::Array[Square::Types::InventoryAdjustmentReasonId] }, optional: true, nullable: false
|
|
14
16
|
end
|
|
15
17
|
end
|
|
16
18
|
end
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Square
|
|
4
|
+
module Types
|
|
5
|
+
class BatchRetrieveInventoryChangesSort < Internal::Types::Model
|
|
6
|
+
field :field, -> { String }, optional: true, nullable: false
|
|
7
|
+
field :order, -> { Square::Types::SortOrder }, optional: true, nullable: false
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Square
|
|
4
|
+
module Types
|
|
5
|
+
module BatchRetrieveInventoryChangesSortField
|
|
6
|
+
# BatchRetrieveInventoryChangesSortField is an alias for Object
|
|
7
|
+
|
|
8
|
+
# @option str [String]
|
|
9
|
+
#
|
|
10
|
+
# @return [untyped]
|
|
11
|
+
def self.load(str)
|
|
12
|
+
::JSON.parse(str)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
# @option value [untyped]
|
|
16
|
+
#
|
|
17
|
+
# @return [String]
|
|
18
|
+
def self.dump(value)
|
|
19
|
+
::JSON.generate(value)
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Square
|
|
4
|
+
module Types
|
|
5
|
+
module CacheMode
|
|
6
|
+
extend Square::Internal::Types::Enum
|
|
7
|
+
|
|
8
|
+
STALE_IF_SLOW = "stale-if-slow"
|
|
9
|
+
STALE_WHILE_REVALIDATE = "stale-while-revalidate"
|
|
10
|
+
MUST_REVALIDATE = "must-revalidate"
|
|
11
|
+
NO_CACHE = "no-cache"
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
@@ -20,6 +20,8 @@ module Square
|
|
|
20
20
|
field :card_payment_timeline, -> { Square::Types::CardPaymentTimeline }, optional: true, nullable: false
|
|
21
21
|
field :refund_requires_card_presence, -> { Internal::Types::Boolean }, optional: true, nullable: false
|
|
22
22
|
field :errors, -> { Internal::Types::Array[Square::Types::Error] }, optional: true, nullable: false
|
|
23
|
+
field :applied_card_surcharge_details, -> { Square::Types::CardSurchargeDetails }, optional: true, nullable: false
|
|
24
|
+
field :wallet_type, -> { String }, optional: true, nullable: false
|
|
23
25
|
end
|
|
24
26
|
end
|
|
25
27
|
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Square
|
|
4
|
+
module Types
|
|
5
|
+
# Details related to an attempt to apply a card surcharge to this payment. When surcharge
|
|
6
|
+
# eligibility is not known in advance, such as when the card type (debit or credit) is required
|
|
7
|
+
# to make the eligibility determination, proposed_card_surcharge_money and
|
|
8
|
+
# proposed_additional_amount_money will match the values in the request, while card_surcharge_money
|
|
9
|
+
# and additional_amount_money are present only when the payment has a surcharge applied.
|
|
10
|
+
class CardSurchargeDetails < Internal::Types::Model
|
|
11
|
+
field :card_surcharge_money, -> { Square::Types::Money }, optional: true, nullable: false
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
@@ -42,6 +42,7 @@ module Square
|
|
|
42
42
|
field :team_member_ids, -> { Internal::Types::Array[String] }, optional: true, nullable: false
|
|
43
43
|
field :stockable_conversion, -> { Square::Types::CatalogStockConversion }, optional: true, nullable: false
|
|
44
44
|
field :kitchen_name, -> { String }, optional: true, nullable: false
|
|
45
|
+
field :vendor_information, -> { Internal::Types::Array[Square::Types::CatalogItemVariationVendorInformation] }, optional: true, nullable: false
|
|
45
46
|
end
|
|
46
47
|
end
|
|
47
48
|
end
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Square
|
|
4
|
+
module Types
|
|
5
|
+
# Information about the vendor of an item variation.
|
|
6
|
+
class CatalogItemVariationVendorInformation < Internal::Types::Model
|
|
7
|
+
field :vendor_id, -> { String }, optional: true, nullable: false
|
|
8
|
+
field :vendor_code, -> { String }, optional: true, nullable: false
|
|
9
|
+
field :unit_cost_money, -> { Square::Types::Money }, optional: true, nullable: false
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|