square.rb 3.3.0.20191217

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +10 -0
  3. data/README.md +285 -0
  4. data/lib/square/api/apple_pay_api.rb +50 -0
  5. data/lib/square/api/base_api.rb +43 -0
  6. data/lib/square/api/cash_drawers_api.rb +150 -0
  7. data/lib/square/api/catalog_api.rb +545 -0
  8. data/lib/square/api/checkout_api.rb +49 -0
  9. data/lib/square/api/customers_api.rb +327 -0
  10. data/lib/square/api/employees_api.rb +86 -0
  11. data/lib/square/api/inventory_api.rb +295 -0
  12. data/lib/square/api/labor_api.rb +553 -0
  13. data/lib/square/api/locations_api.rb +146 -0
  14. data/lib/square/api/merchants_api.rb +82 -0
  15. data/lib/square/api/mobile_authorization_api.rb +52 -0
  16. data/lib/square/api/o_auth_api.rb +163 -0
  17. data/lib/square/api/orders_api.rb +266 -0
  18. data/lib/square/api/payments_api.rb +277 -0
  19. data/lib/square/api/refunds_api.rb +144 -0
  20. data/lib/square/api/reporting_api.rb +138 -0
  21. data/lib/square/api/transactions_api.rb +377 -0
  22. data/lib/square/api/v1_employees_api.rb +715 -0
  23. data/lib/square/api/v1_items_api.rb +2046 -0
  24. data/lib/square/api/v1_locations_api.rb +83 -0
  25. data/lib/square/api/v1_transactions_api.rb +568 -0
  26. data/lib/square/api_helper.rb +276 -0
  27. data/lib/square/client.rb +156 -0
  28. data/lib/square/configuration.rb +93 -0
  29. data/lib/square/exceptions/api_exception.rb +15 -0
  30. data/lib/square/http/api_response.rb +45 -0
  31. data/lib/square/http/auth/o_auth2.rb +12 -0
  32. data/lib/square/http/faraday_client.rb +59 -0
  33. data/lib/square/http/http_call_back.rb +19 -0
  34. data/lib/square/http/http_client.rb +99 -0
  35. data/lib/square/http/http_method_enum.rb +8 -0
  36. data/lib/square/http/http_request.rb +45 -0
  37. data/lib/square/http/http_response.rb +24 -0
  38. data/lib/square.rb +49 -0
  39. data/spec/user_journey_spec.rb +145 -0
  40. data/test/api/api_test_base.rb +24 -0
  41. data/test/api/test_catalog_api.rb +59 -0
  42. data/test/api/test_customers_api.rb +45 -0
  43. data/test/api/test_employees_api.rb +36 -0
  44. data/test/api/test_labor_api.rb +74 -0
  45. data/test/api/test_locations_api.rb +35 -0
  46. data/test/api/test_merchants_api.rb +40 -0
  47. data/test/api/test_payments_api.rb +42 -0
  48. data/test/api/test_refunds_api.rb +41 -0
  49. data/test/http_response_catcher.rb +19 -0
  50. data/test/test_helper.rb +94 -0
  51. metadata +190 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 00a4ada597456bcc942f896460303acf6a581aa50f4c9d2a64f1a311ea4d1689
4
+ data.tar.gz: b53863a3d76c327f63a52ec3b9beca8bbf2eea59058bf1ea9bce11524fde5a0a
5
+ SHA512:
6
+ metadata.gz: 8dd7e37e97bab6d4896db1a4e3e16582160c70131ae9d8ff3b27cdf2d874a156a6966b94d22c8c545dae6ee2383f844616bd056d7b3c2fc889f8a69b493cae2a
7
+ data.tar.gz: d242bdf3633f6ff99dd2016055b0a7c38de6c3619ae06e255ea2cc7314a6e12bd96a9dbf6e1cd72c3a650b4d7a33bfbdea336f5c8b48fa59f21eacab2723cce9
data/LICENSE ADDED
@@ -0,0 +1,10 @@
1
+ Copyright 2019 Square, Inc.
2
+ Licensed under the Apache License, Version 2.0 (the "License");
3
+ you may not use this file except in compliance with the License.
4
+ You may obtain a copy of the License at
5
+ https://www.apache.org/licenses/LICENSE-2.0
6
+ Unless required by applicable law or agreed to in writing, software
7
+ distributed under the License is distributed on an "AS IS" BASIS,
8
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
9
+ See the License for the specific language governing permissions and
10
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1,285 @@
1
+ ![Square logo]
2
+
3
+ # Square Ruby SDK
4
+
5
+ [![Travis status](https://travis-ci.org/square/square-ruby-sdk.svg?branch=master)](https://travis-ci.org/square/square-ruby-sdk)
6
+ [![Gem version](https://badge.fury.io/rb/square.rb.svg?new)](https://badge.fury.io/rb/square.rb)
7
+ [![Apache-2 license](https://img.shields.io/badge/license-Apache2-brightgreen.svg)](https://www.apache.org/licenses/LICENSE-2.0)
8
+
9
+ Use this gem to integrate Square payments into your app and grow your business with Square APIs including Catalog, Customers, Employees, Inventory, Labor, Locations, and Orders.
10
+
11
+ ## Installation
12
+
13
+ Install the gem from the command line:
14
+
15
+ ```ruby
16
+ gem install square.rb
17
+ ```
18
+
19
+ Or add the gem to your Gemfile and `bundle`:
20
+
21
+ ```ruby
22
+ gem 'square.rb'
23
+ ```
24
+
25
+ ## API documentation
26
+
27
+ ### API Client
28
+ * [Client]
29
+
30
+ ### Take Payments
31
+
32
+ * [Payments]
33
+ * [Checkout]
34
+
35
+ ### More Square APIs
36
+
37
+ * [Catalog]
38
+ * [Customers]
39
+ * [Employees]
40
+ * [Inventory]
41
+ * [Labor]
42
+ * [Locations]
43
+ * [Merchants]
44
+ * [Orders]
45
+ * [Apple Pay]
46
+ * [Refunds]
47
+ * [Reporting]
48
+
49
+ ### Authorization APIs
50
+
51
+ * [Mobile Authorization]
52
+ * [O Auth]
53
+
54
+ ### Deprecated APIs
55
+
56
+ * [V1 Locations]
57
+ * [V1 Employees]
58
+ * [V1 Transactions]
59
+ * [V1 Items]
60
+ * [Transactions]
61
+
62
+ ## Usage
63
+
64
+ First time using Square? Here’s how to get started:
65
+
66
+ 1. **Create a Square account.** If you don’t have one already, [sign up for a developer account].
67
+ 1. **Create an application.** Go to your [Developer Dashboard] and create your first application. All you need to do is give it a name. When you’re doing this for your production application, enter the name as you would want a customer to see it.
68
+ 1. **Make your first API call.** Almost all Square API calls require a location ID. You’ll make your first call to #list_locations, which happens to be one of the API calls that don’t require a location ID. For more information about locations, see the [Locations] API documentation.
69
+
70
+ Now let’s call your first Square API. Open your favorite text editor, create a new file called `locations.rb`, and copy the following code into that file:
71
+
72
+ ```ruby
73
+ require 'square'
74
+
75
+ # Create an instance of the API Client and initialize it with the credentials
76
+ # for the Square account whose assets you want to manage.
77
+
78
+ client = Square::Client.new(
79
+ access_token: 'YOUR SANDBOX ACCESS TOKEN HERE',
80
+ environment: 'sandbox'
81
+ )
82
+
83
+ # Call list_locations method to get all locations in this Square account
84
+ result = client.locations.list_locations
85
+
86
+ # Call the #success? method to see if the call succeeded
87
+ if result.success?
88
+ # The #data Struct contains a list of locations
89
+ locations = result.data.locations
90
+
91
+ # Iterate over the list
92
+ locations.each do |location|
93
+ # Each location is represented as a Hash
94
+ location.each do |key, value|
95
+ puts "#{key}: #{value}"
96
+ end
97
+ end
98
+ else
99
+ # Handle the case that the result is an error.
100
+ warn 'Error calling LocationsApi.listlocations ...'
101
+
102
+ # The #errors method returns an Array of error Hashes
103
+ result.errors.each do |key, value|
104
+ warn "#{key}: #{value}"
105
+ end
106
+ end
107
+ ```
108
+
109
+ Next, get an access token and reference it in your code. Go back to your application in the Developer Dashboard, in the Sandbox section click Show in the Sandbox Access Token box, copy that access token, and replace `'YOUR SANDBOX ACCESS TOKEN HERE'` with that token.
110
+
111
+ **Important** When you eventually switch from trying things out on sandbox to actually working with your real production resources, you should not embed the access token in your code. Make sure you store and access your production access tokens securely.
112
+
113
+ Now save `locations.rb` and run it:
114
+
115
+ ```sh
116
+ ruby locations.rb
117
+ ```
118
+
119
+ If your call is successful, you’ll get a response that looks like this:
120
+
121
+ ```
122
+ address : {'address_line_1': '1455 Market Street', 'administrative_district_level_1': 'CA', 'country': 'US', 'locality': 'San Francisco', 'postal_code': '94103'}
123
+ # ...
124
+ ```
125
+
126
+ Yay! You successfully made your first call. If you didn’t, you would see an error message that looks something like this:
127
+
128
+ ```
129
+ Error calling LocationsApi.listlocations
130
+ category : AUTHENTICATION_ERROR
131
+ code : UNAUTHORIZED
132
+ detail : This request could not be authorized.
133
+ ```
134
+
135
+ This error was returned when an invalid token was used to call the API.
136
+
137
+ After you’ve tried out the Square APIs and tested your application using sandbox, you will want to switch to your production credentials so that you can manage real Square resources. Don't forget to switch your access token from sandbox to production for real data.
138
+
139
+ ## SDK patterns
140
+ If you know a few patterns, you’ll be able to call any API in the SDK. Here are some important ones:
141
+
142
+ ### Get an access token
143
+
144
+ To use the Square API to manage the resources (such as payments, orders, customers, etc.) of a Square account, you need to create an application (or use an existing one) in the Developer Dashboard and get an access token.
145
+
146
+ When you call a Square API, you call it using an access key. An access key has specific permissions to resources in a specific Square account that can be accessed by a specific application in a specific developer account.
147
+ Use an access token that is appropriate for your use case. There are two options:
148
+
149
+ - To manage the resources for your own Square account, use the Personal Access Token for the application created in your Square account.
150
+ - To manage resources for other Square accounts, use OAuth to ask owners of the accounts you want to manage so that you can work on their behalf. When you implement OAuth, you ask the Square account holder for permission to manage resources in their account (you can define the specific resources to access) and get an OAuth access token and refresh token for their account.
151
+
152
+ **Important** For both use cases, make sure you store and access the tokens securely.
153
+
154
+ ### Import and Instantiate the Client Class
155
+
156
+ To use the Square API, you import the Client class, instantiate a Client object, and initialize it with the appropriate access token. Here’s how:
157
+
158
+ - Instantiate a `Square::Client` object with the access token for the Square account whose resources you want to manage. To access sandbox resources, initialize the `Square::Client` with environment set to sandbox:
159
+
160
+ ```ruby
161
+ client = Square::Client.new(
162
+ access_token: 'SANDBOX ACCESS TOKEN HERE',
163
+ environment: 'sandbox'
164
+ )
165
+ ```
166
+
167
+ - To access production resources, set environment to production:
168
+
169
+ ```ruby
170
+ client = Square::Client.new(
171
+ access_token: 'ACCESS TOKEN HERE',
172
+ environment: 'production'
173
+ )
174
+ ```
175
+
176
+ ### Get an Instance of an API object and call its methods
177
+
178
+ Each API is implemented as a class. The Client object instantiates every API class and exposes them as properties so you can easily start using any Square API. You work with an API by calling methods on an instance of an API class. Here’s how:
179
+
180
+ - Work with an API by calling the methods on the API object. For example, you would call list_customers to get a list of all customers in the Square account:
181
+
182
+ ```ruby
183
+ result = client.customers.list_customers
184
+ ```
185
+
186
+ See the SDK documentation for the list of methods for each API class.
187
+
188
+ Pass complex parameters (such as create, update, search, etc.) as a Hash. For example, you would pass a Hash containing the values used to create a new customer using create_customer:
189
+
190
+ ```ruby
191
+ # Create a unique key for this creation operation so you don't accidentally
192
+ # create the customer multiple times if you need to retry this operation.
193
+ require 'securerandom'
194
+
195
+ idempotency_key = SecureRandom.uuid
196
+
197
+ # To create a customer, you'll need to specify at least a few required fields.
198
+ request_body = {idempotency_key: idempotency_key, given_name: 'Amelia', family_name: 'Earhardt'}
199
+
200
+ # Call create_customer method to create a new customer in this Square account
201
+ result = client.customers.create_customer(request_body)
202
+ ```
203
+
204
+ If your call succeeds, you’ll see a response that looks like this:
205
+ ```
206
+ {'customer': {'created_at': '2019-06-28T21:23:05.126Z', 'creation_source': 'THIRD_PARTY', 'family_name': 'Earhardt', 'given_name': 'Amelia', 'id': 'CBASEDwl3El91nohQ2FLEk4aBfcgAQ', 'preferences': {'email_unsubscribed': False}, 'updated_at': '2019-06-28T21:23:05.126Z'}}
207
+ ```
208
+
209
+ - Use idempotency for create, update, or other calls that you want to avoid calling twice. To make an idempotent API call, you add the idempotency_key with a unique value in the Hash for the API call’s request.
210
+ - Specify a location ID for APIs such as Transactions, Orders, and Checkout that deal with payments. When a payment or order is created in Square, it is always associated with a location.
211
+
212
+ ### Handle the response
213
+
214
+ API calls return a response object that contains properties that describe both the request (headers and request) and the response (status_code, reason_phrase, text, errors, body, and cursor). The response also has #success? and #error? helper methods so you can easily determine the success or failure of a call:
215
+
216
+ ```ruby
217
+ if result.success?
218
+ p result.data
219
+ elsif result.error?
220
+ warn result.errors.inspect
221
+ end
222
+ ```
223
+
224
+ - Read the response payload. The response payload is returned as a Struct from the #data method. For retrieve calls, a Struct containing a single item is returned with a key name that is the name of the object (for example, customer). For list calls, a Struct containing a Array of objects is returned with a key name that is the plural of the object name (for example, customers).
225
+ - Make sure you get all items returned in a list call by checking the cursor value returned in the API response. When you call a list API the first time, set the cursor to an empty String or omit it from the API request. If the API response contains a cursor with a value, you call the API again to get the next page of items and continue to call that API again until the cursor is an empty String.
226
+
227
+ ## Tests
228
+
229
+ First, clone the gem locally and `cd` into the directory.
230
+
231
+ ```sh
232
+ git clone https://github.com/square/square-ruby-sdk.git
233
+ cd square-ruby-sdk
234
+ ```
235
+
236
+ Next, make sure Bundler is installed and install the development dependencies.
237
+
238
+ ```sh
239
+ gem install bundler
240
+ bundle
241
+ ```
242
+
243
+ Before running the tests, find a sandbox token in your [Developer Dashboard] and set a `SQUARE_SANDBOX_TOKEN` environment variable.
244
+
245
+ ```sh
246
+ export SQUARE_SANDBOX_TOKEN="YOUR SANDBOX TOKEN HERE"
247
+ ```
248
+
249
+ And run the tests.
250
+
251
+ ```sh
252
+ rake
253
+ ```
254
+
255
+ ## Learn more
256
+
257
+ The Square Platform is built on the [Square API]. Square has a number of other SDKs that enable you to securely handle credit card information on both mobile and web so that you can process payments via the Square API.
258
+
259
+ You can also use the Square API to create applications or services that work with payments, orders, inventory, etc. that have been created and managed in Square’s in-person hardware products (Square Point of Sale and Square Register).
260
+
261
+ [Square Logo]: https://docs.connect.squareup.com/images/github/github-square-logo.svg
262
+ [Developer Dashboard]: https://developer.squareup.com/apps
263
+ [Square API]: https://squareup.com/developers
264
+ [sign up for a developer account]: https://squareup.com/signup?v=developers
265
+ [Client]: doc/client.md
266
+ [Payments]: doc/payments.md
267
+ [Checkout]: doc/checkout.md
268
+ [Catalog]: doc/catalog.md
269
+ [Customers]: doc/customers.md
270
+ [Employees]: doc/employees.md
271
+ [Inventory]: doc/inventory.md
272
+ [Labor]: doc/labor.md
273
+ [Locations]: doc/locations.md
274
+ [Merchants]: doc/merchants.md
275
+ [Orders]: doc/orders.md
276
+ [Apple Pay]: doc/apple-pay.md
277
+ [Refunds]: doc/refunds.md
278
+ [Reporting]: doc/reporting.md
279
+ [Mobile Authorization]: doc/mobile-authorization.md
280
+ [O Auth]: doc/o-auth.md
281
+ [V1 Locations]: doc/v1-locations.md
282
+ [V1 Employees]: doc/v1-employees.md
283
+ [V1 Transactions]: doc/v1-transactions.md
284
+ [V1 Items]: doc/v1-items.md
285
+ [Transactions]: doc/transactions.md
@@ -0,0 +1,50 @@
1
+ module Square
2
+ # ApplePayApi
3
+ class ApplePayApi < BaseApi
4
+ def initialize(config, http_call_back: nil)
5
+ super(config, http_call_back: http_call_back)
6
+ end
7
+
8
+ # Activates a domain for use with Web Apple Pay and Square. A validation
9
+ # will be performed on this domain by Apple to ensure is it properly set up
10
+ # as
11
+ # an Apple Pay enabled domain.
12
+ # This endpoint provides an easy way for platform developers to bulk
13
+ # activate
14
+ # Web Apple Pay with Square for merchants using their platform.
15
+ # To learn more about Apple Pay on Web see the Apple Pay section in the
16
+ # [Square Payment Form
17
+ # Walkthrough](https://developer.squareup.com/docs/docs/payment-form/payment
18
+ # -form-walkthrough).
19
+ # @param [RegisterDomainRequest] body Required parameter: An object
20
+ # containing the fields to POST for the request. See the corresponding
21
+ # object definition for field details.
22
+ # @return [RegisterDomainResponse Hash] response from the API call
23
+ def register_domain(body:)
24
+ # Prepare query url.
25
+ _query_builder = config.get_base_uri
26
+ _query_builder << '/v2/apple-pay/domains'
27
+ _query_url = APIHelper.clean_url _query_builder
28
+
29
+ # Prepare headers.
30
+ _headers = {
31
+ 'accept' => 'application/json',
32
+ 'content-type' => 'application/json; charset=utf-8'
33
+ }
34
+
35
+ # Prepare and execute HttpRequest.
36
+ _request = config.http_client.post(
37
+ _query_url,
38
+ headers: _headers,
39
+ parameters: body.to_json
40
+ )
41
+ OAuth2.apply(config, _request)
42
+ _response = execute_request(_request)
43
+
44
+ # Return appropriate response type.
45
+ decoded = APIHelper.json_deserialize(_response.raw_body)
46
+ _errors = APIHelper.map_response(decoded, ['errors'])
47
+ ApiResponse.new(_response, data: decoded, errors: _errors)
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,43 @@
1
+ module Square
2
+ # BaseApi.
3
+ class BaseApi
4
+ attr_accessor :config, :http_call_back
5
+
6
+ def initialize(config, http_call_back: nil)
7
+ @config = config
8
+ @http_call_back = http_call_back
9
+
10
+ @global_headers = {
11
+ 'user-agent' => 'Square-Ruby-SDK/3.3.0.20191217',
12
+ 'Square-Version' => '2019-12-17'
13
+ }
14
+ end
15
+
16
+ def validate_parameters(args)
17
+ args.each do |_name, value|
18
+ if value.nil?
19
+ raise ArgumentError, "Required parameter #{_name} cannot be nil."
20
+ end
21
+ end
22
+ end
23
+
24
+ def execute_request(request, binary: false)
25
+ @http_call_back.on_before_request(request) if @http_call_back
26
+
27
+ APIHelper.clean_hash(request.headers)
28
+ request.headers.merge!(@global_headers)
29
+ unless config.additional_headers.nil?
30
+ request.headers.merge!(config.additional_headers)
31
+ end
32
+
33
+ response = if binary
34
+ config.http_client.execute_as_binary(request)
35
+ else
36
+ config.http_client.execute_as_string(request)
37
+ end
38
+ @http_call_back.on_after_response(response) if @http_call_back
39
+
40
+ response
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,150 @@
1
+ module Square
2
+ # CashDrawersApi
3
+ class CashDrawersApi < BaseApi
4
+ def initialize(config, http_call_back: nil)
5
+ super(config, http_call_back: http_call_back)
6
+ end
7
+
8
+ # Provides the details for all of the cash drawer shifts for a location
9
+ # in a date range.
10
+ # @param [String] location_id Required parameter: The ID of the location to
11
+ # query for a list of cash drawer shifts.
12
+ # @param [SortOrder] sort_order Optional parameter: The order in which cash
13
+ # drawer shifts are listed in the response, based on their opened_at field.
14
+ # Default value: ASC
15
+ # @param [String] begin_time Optional parameter: The inclusive start time of
16
+ # the query on opened_at, in ISO 8601 format.
17
+ # @param [String] end_time Optional parameter: The exclusive end date of the
18
+ # query on opened_at, in ISO 8601 format.
19
+ # @param [Integer] limit Optional parameter: Number of cash drawer shift
20
+ # events in a page of results (200 by default, 1000 max).
21
+ # @param [String] cursor Optional parameter: Opaque cursor for fetching the
22
+ # next page of results.
23
+ # @return [ListCashDrawerShiftsResponse Hash] response from the API call
24
+ def list_cash_drawer_shifts(location_id:,
25
+ sort_order: nil,
26
+ begin_time: nil,
27
+ end_time: nil,
28
+ limit: nil,
29
+ cursor: nil)
30
+ # Prepare query url.
31
+ _query_builder = config.get_base_uri
32
+ _query_builder << '/v2/cash-drawers/shifts'
33
+ _query_builder = APIHelper.append_url_with_query_parameters(
34
+ _query_builder,
35
+ 'location_id' => location_id,
36
+ 'sort_order' => sort_order,
37
+ 'begin_time' => begin_time,
38
+ 'end_time' => end_time,
39
+ 'limit' => limit,
40
+ 'cursor' => cursor
41
+ )
42
+ _query_url = APIHelper.clean_url _query_builder
43
+
44
+ # Prepare headers.
45
+ _headers = {
46
+ 'accept' => 'application/json'
47
+ }
48
+
49
+ # Prepare and execute HttpRequest.
50
+ _request = config.http_client.get(
51
+ _query_url,
52
+ headers: _headers
53
+ )
54
+ OAuth2.apply(config, _request)
55
+ _response = execute_request(_request)
56
+
57
+ # Return appropriate response type.
58
+ decoded = APIHelper.json_deserialize(_response.raw_body)
59
+ _errors = APIHelper.map_response(decoded, ['errors'])
60
+ ApiResponse.new(_response, data: decoded, errors: _errors)
61
+ end
62
+
63
+ # Provides the summary details for a single cash drawer shift. See
64
+ # RetrieveCashDrawerShiftEvents for a list of cash drawer shift events.
65
+ # @param [String] location_id Required parameter: The ID of the location to
66
+ # retrieve cash drawer shifts from.
67
+ # @param [String] shift_id Required parameter: The shift ID.
68
+ # @return [RetrieveCashDrawerShiftResponse Hash] response from the API call
69
+ def retrieve_cash_drawer_shift(location_id:,
70
+ shift_id:)
71
+ # Prepare query url.
72
+ _query_builder = config.get_base_uri
73
+ _query_builder << '/v2/cash-drawers/shifts/{shift_id}'
74
+ _query_builder = APIHelper.append_url_with_template_parameters(
75
+ _query_builder,
76
+ 'shift_id' => shift_id
77
+ )
78
+ _query_builder = APIHelper.append_url_with_query_parameters(
79
+ _query_builder,
80
+ 'location_id' => location_id
81
+ )
82
+ _query_url = APIHelper.clean_url _query_builder
83
+
84
+ # Prepare headers.
85
+ _headers = {
86
+ 'accept' => 'application/json'
87
+ }
88
+
89
+ # Prepare and execute HttpRequest.
90
+ _request = config.http_client.get(
91
+ _query_url,
92
+ headers: _headers
93
+ )
94
+ OAuth2.apply(config, _request)
95
+ _response = execute_request(_request)
96
+
97
+ # Return appropriate response type.
98
+ decoded = APIHelper.json_deserialize(_response.raw_body)
99
+ _errors = APIHelper.map_response(decoded, ['errors'])
100
+ ApiResponse.new(_response, data: decoded, errors: _errors)
101
+ end
102
+
103
+ # Provides a paginated list of events for a single cash drawer shift.
104
+ # @param [String] location_id Required parameter: The ID of the location to
105
+ # list cash drawer shifts for.
106
+ # @param [String] shift_id Required parameter: The shift ID.
107
+ # @param [Integer] limit Optional parameter: Number of resources to be
108
+ # returned in a page of results (200 by default, 1000 max).
109
+ # @param [String] cursor Optional parameter: Opaque cursor for fetching the
110
+ # next page of results.
111
+ # @return [ListCashDrawerShiftEventsResponse Hash] response from the API call
112
+ def list_cash_drawer_shift_events(location_id:,
113
+ shift_id:,
114
+ limit: nil,
115
+ cursor: nil)
116
+ # Prepare query url.
117
+ _query_builder = config.get_base_uri
118
+ _query_builder << '/v2/cash-drawers/shifts/{shift_id}/events'
119
+ _query_builder = APIHelper.append_url_with_template_parameters(
120
+ _query_builder,
121
+ 'shift_id' => shift_id
122
+ )
123
+ _query_builder = APIHelper.append_url_with_query_parameters(
124
+ _query_builder,
125
+ 'location_id' => location_id,
126
+ 'limit' => limit,
127
+ 'cursor' => cursor
128
+ )
129
+ _query_url = APIHelper.clean_url _query_builder
130
+
131
+ # Prepare headers.
132
+ _headers = {
133
+ 'accept' => 'application/json'
134
+ }
135
+
136
+ # Prepare and execute HttpRequest.
137
+ _request = config.http_client.get(
138
+ _query_url,
139
+ headers: _headers
140
+ )
141
+ OAuth2.apply(config, _request)
142
+ _response = execute_request(_request)
143
+
144
+ # Return appropriate response type.
145
+ decoded = APIHelper.json_deserialize(_response.raw_body)
146
+ _errors = APIHelper.map_response(decoded, ['errors'])
147
+ ApiResponse.new(_response, data: decoded, errors: _errors)
148
+ end
149
+ end
150
+ end