square.rb 10.0.0.20210421 → 13.0.0.20210721

Sign up to get free protection for your applications and to get access to all the features.
@@ -152,8 +152,9 @@ module Square
152
152
 
153
153
  # Charges a card represented by a card nonce or a customer's card on file.
154
154
  # Your request to this endpoint must include _either_:
155
- # - A value for the `card_nonce` parameter (to charge a card nonce generated
156
- # with the `SqPaymentForm`)
155
+ # - A value for the `card_nonce` parameter (to charge a card payment token
156
+ # generated
157
+ # with the Web Payments SDK)
157
158
  # - Values for the `customer_card_id` and `customer_id` parameters (to
158
159
  # charge
159
160
  # a customer's card on file)
@@ -20,6 +20,7 @@ module Square
20
20
  order: nil,
21
21
  limit: nil,
22
22
  batch_token: nil)
23
+ warn 'Endpoint list_orders in V1TransactionsApi is deprecated'
23
24
  # Prepare query url.
24
25
  _query_builder = config.get_base_uri
25
26
  _query_builder << '/v1/{location_id}/orders'
@@ -66,6 +67,7 @@ module Square
66
67
  # @return [V1Order Hash] response from the API call
67
68
  def retrieve_order(location_id:,
68
69
  order_id:)
70
+ warn 'Endpoint retrieve_order in V1TransactionsApi is deprecated'
69
71
  # Prepare query url.
70
72
  _query_builder = config.get_base_uri
71
73
  _query_builder << '/v1/{location_id}/orders/{order_id}'
@@ -111,6 +113,7 @@ module Square
111
113
  def update_order(location_id:,
112
114
  order_id:,
113
115
  body:)
116
+ warn 'Endpoint update_order in V1TransactionsApi is deprecated'
114
117
  # Prepare query url.
115
118
  _query_builder = config.get_base_uri
116
119
  _query_builder << '/v1/{location_id}/orders/{order_id}'
@@ -184,6 +187,7 @@ module Square
184
187
  limit: nil,
185
188
  batch_token: nil,
186
189
  include_partial: false)
190
+ warn 'Endpoint list_payments in V1TransactionsApi is deprecated'
187
191
  # Prepare query url.
188
192
  _query_builder = config.get_base_uri
189
193
  _query_builder << '/v1/{location_id}/payments'
@@ -233,6 +237,7 @@ module Square
233
237
  # @return [V1Payment Hash] response from the API call
234
238
  def retrieve_payment(location_id:,
235
239
  payment_id:)
240
+ warn 'Endpoint retrieve_payment in V1TransactionsApi is deprecated'
236
241
  # Prepare query url.
237
242
  _query_builder = config.get_base_uri
238
243
  _query_builder << '/v1/{location_id}/payments/{payment_id}'
@@ -294,6 +299,7 @@ module Square
294
299
  end_time: nil,
295
300
  limit: nil,
296
301
  batch_token: nil)
302
+ warn 'Endpoint list_refunds in V1TransactionsApi is deprecated'
297
303
  # Prepare query url.
298
304
  _query_builder = config.get_base_uri
299
305
  _query_builder << '/v1/{location_id}/refunds'
@@ -350,6 +356,7 @@ module Square
350
356
  # @return [V1Refund Hash] response from the API call
351
357
  def create_refund(location_id:,
352
358
  body:)
359
+ warn 'Endpoint create_refund in V1TransactionsApi is deprecated'
353
360
  # Prepare query url.
354
361
  _query_builder = config.get_base_uri
355
362
  _query_builder << '/v1/{location_id}/refunds'
@@ -417,6 +424,7 @@ module Square
417
424
  limit: nil,
418
425
  status: nil,
419
426
  batch_token: nil)
427
+ warn 'Endpoint list_settlements in V1TransactionsApi is deprecated'
420
428
  # Prepare query url.
421
429
  _query_builder = config.get_base_uri
422
430
  _query_builder << '/v1/{location_id}/settlements'
@@ -479,6 +487,7 @@ module Square
479
487
  # @return [V1Settlement Hash] response from the API call
480
488
  def retrieve_settlement(location_id:,
481
489
  settlement_id:)
490
+ warn 'Endpoint retrieve_settlement in V1TransactionsApi is deprecated'
482
491
  # Prepare query url.
483
492
  _query_builder = config.get_base_uri
484
493
  _query_builder << '/v1/{location_id}/settlements/{settlement_id}'
@@ -265,17 +265,5 @@ module Square
265
265
  end
266
266
  val
267
267
  end
268
-
269
- # Safely converts a string into an rfc3339 DateTime object
270
- # @param [String] The datetime string
271
- # @return [DateTime] A DateTime object of rfc3339 format
272
- def self.rfc3339(date_time)
273
- # missing timezone information
274
- if date_time.end_with?('Z') || date_time.index('+')
275
- DateTime.rfc3339(date_time)
276
- else
277
- DateTime.rfc3339(date_time + 'Z')
278
- end
279
- end
280
268
  end
281
269
  end
data/lib/square/client.rb CHANGED
@@ -4,7 +4,7 @@ module Square
4
4
  attr_reader :config
5
5
 
6
6
  def sdk_version
7
- '10.0.0.20210421'
7
+ '13.0.0.20210721'
8
8
  end
9
9
 
10
10
  def square_version
@@ -53,6 +53,12 @@ module Square
53
53
  @bookings ||= BookingsApi.new config
54
54
  end
55
55
 
56
+ # Access to cards controller.
57
+ # @return [CardsApi] Returns the controller instance.
58
+ def cards
59
+ @cards ||= CardsApi.new config
60
+ end
61
+
56
62
  # Access to cash_drawers controller.
57
63
  # @return [CashDrawersApi] Returns the controller instance.
58
64
  def cash_drawers
@@ -101,6 +107,18 @@ module Square
101
107
  @employees ||= EmployeesApi.new config
102
108
  end
103
109
 
110
+ # Access to gift_cards controller.
111
+ # @return [GiftCardsApi] Returns the controller instance.
112
+ def gift_cards
113
+ @gift_cards ||= GiftCardsApi.new config
114
+ end
115
+
116
+ # Access to gift_card_activities controller.
117
+ # @return [GiftCardActivitiesApi] Returns the controller instance.
118
+ def gift_card_activities
119
+ @gift_card_activities ||= GiftCardActivitiesApi.new config
120
+ end
121
+
104
122
  # Access to inventory controller.
105
123
  # @return [InventoryApi] Returns the controller instance.
106
124
  def inventory
@@ -167,6 +185,18 @@ module Square
167
185
  @refunds ||= RefundsApi.new config
168
186
  end
169
187
 
188
+ # Access to sites controller.
189
+ # @return [SitesApi] Returns the controller instance.
190
+ def sites
191
+ @sites ||= SitesApi.new config
192
+ end
193
+
194
+ # Access to snippets controller.
195
+ # @return [SnippetsApi] Returns the controller instance.
196
+ def snippets
197
+ @snippets ||= SnippetsApi.new config
198
+ end
199
+
170
200
  # Access to subscriptions controller.
171
201
  # @return [SubscriptionsApi] Returns the controller instance.
172
202
  def subscriptions
@@ -186,14 +216,18 @@ module Square
186
216
  end
187
217
 
188
218
  def initialize(timeout: 60, max_retries: 0, retry_interval: 1,
189
- backoff_factor: 1, environment: 'production',
219
+ backoff_factor: 2,
220
+ retry_statuses: [408, 413, 429, 500, 502, 503, 504, 521, 522, 524],
221
+ retry_methods: %i[get put], environment: 'production',
190
222
  custom_url: 'https://connect.squareup.com',
191
- square_version: '2021-04-21', access_token: 'TODO: Replace',
223
+ square_version: '2021-07-21', access_token: 'TODO: Replace',
192
224
  additional_headers: {}, config: nil)
193
225
  @config = if config.nil?
194
226
  Configuration.new(timeout: timeout, max_retries: max_retries,
195
227
  retry_interval: retry_interval,
196
228
  backoff_factor: backoff_factor,
229
+ retry_statuses: retry_statuses,
230
+ retry_methods: retry_methods,
197
231
  environment: environment,
198
232
  custom_url: custom_url,
199
233
  square_version: square_version,
@@ -8,6 +8,8 @@ module Square
8
8
  attr_reader :max_retries
9
9
  attr_reader :retry_interval
10
10
  attr_reader :backoff_factor
11
+ attr_reader :retry_statuses
12
+ attr_reader :retry_methods
11
13
  attr_reader :environment
12
14
  attr_reader :custom_url
13
15
  attr_reader :square_version
@@ -22,9 +24,11 @@ module Square
22
24
  end
23
25
 
24
26
  def initialize(timeout: 60, max_retries: 0, retry_interval: 1,
25
- backoff_factor: 1, environment: 'production',
27
+ backoff_factor: 2,
28
+ retry_statuses: [408, 413, 429, 500, 502, 503, 504, 521, 522, 524],
29
+ retry_methods: %i[get put], environment: 'production',
26
30
  custom_url: 'https://connect.squareup.com',
27
- square_version: '2021-04-21', access_token: 'TODO: Replace',
31
+ square_version: '2021-07-21', access_token: 'TODO: Replace',
28
32
  additional_headers: {})
29
33
  # The value to use for connection timeout
30
34
  @timeout = timeout
@@ -39,6 +43,12 @@ module Square
39
43
  # by in order to provide backoff
40
44
  @backoff_factor = backoff_factor
41
45
 
46
+ # A list of HTTP statuses to retry
47
+ @retry_statuses = retry_statuses
48
+
49
+ # A list of HTTP methods to retry
50
+ @retry_methods = retry_methods
51
+
42
52
  # Current API environment
43
53
  @environment = String(environment)
44
54
 
@@ -59,13 +69,15 @@ module Square
59
69
  end
60
70
 
61
71
  def clone_with(timeout: nil, max_retries: nil, retry_interval: nil,
62
- backoff_factor: nil, environment: nil, custom_url: nil,
63
- square_version: nil, access_token: nil,
64
- additional_headers: nil)
72
+ backoff_factor: nil, retry_statuses: nil, retry_methods: nil,
73
+ environment: nil, custom_url: nil, square_version: nil,
74
+ access_token: nil, additional_headers: nil)
65
75
  timeout ||= self.timeout
66
76
  max_retries ||= self.max_retries
67
77
  retry_interval ||= self.retry_interval
68
78
  backoff_factor ||= self.backoff_factor
79
+ retry_statuses ||= self.retry_statuses
80
+ retry_methods ||= self.retry_methods
69
81
  environment ||= self.environment
70
82
  custom_url ||= self.custom_url
71
83
  square_version ||= self.square_version
@@ -75,8 +87,9 @@ module Square
75
87
  Configuration.new(timeout: timeout, max_retries: max_retries,
76
88
  retry_interval: retry_interval,
77
89
  backoff_factor: backoff_factor,
78
- environment: environment, custom_url: custom_url,
79
- square_version: square_version,
90
+ retry_statuses: retry_statuses,
91
+ retry_methods: retry_methods, environment: environment,
92
+ custom_url: custom_url, square_version: square_version,
80
93
  access_token: access_token,
81
94
  additional_headers: additional_headers)
82
95
  end
@@ -84,7 +97,9 @@ module Square
84
97
  def create_http_client
85
98
  FaradayClient.new(timeout: timeout, max_retries: max_retries,
86
99
  retry_interval: retry_interval,
87
- backoff_factor: backoff_factor)
100
+ backoff_factor: backoff_factor,
101
+ retry_statuses: retry_statuses,
102
+ retry_methods: retry_methods)
88
103
  end
89
104
 
90
105
  # All the environments the SDK can run in.
@@ -6,7 +6,8 @@ module Square
6
6
  class FaradayClient < HttpClient
7
7
  # The constructor.
8
8
  def initialize(timeout:, max_retries:, retry_interval:,
9
- backoff_factor:, cache: false, verify: true)
9
+ backoff_factor:, retry_statuses:, retry_methods:,
10
+ cache: false, verify: true)
10
11
  @connection = Faraday.new do |faraday|
11
12
  faraday.use Faraday::HttpCache, serializer: Marshal if cache
12
13
  faraday.use FaradayMiddleware::FollowRedirects
@@ -16,7 +17,9 @@ module Square
16
17
  faraday.ssl[:ca_file] = Certifi.where
17
18
  faraday.ssl[:verify] = verify
18
19
  faraday.request :retry, max: max_retries, interval: retry_interval,
19
- backoff_factor: backoff_factor
20
+ backoff_factor: backoff_factor,
21
+ retry_statuses: retry_statuses,
22
+ methods: retry_methods
20
23
  faraday.adapter Faraday.default_adapter
21
24
  faraday.options[:params_encoder] = Faraday::FlatParamsEncoder
22
25
  faraday.options[:timeout] = timeout if timeout > 0
@@ -0,0 +1,151 @@
1
+ require 'date'
2
+ module Square
3
+ # A utility that supports dateTime conversion to different formats
4
+ class DateTimeHelper
5
+ # Safely converts a DateTime object into a rfc1123 format string
6
+ # @param [DateTime] The DateTime object
7
+ # @return [String] The rfc1123 formatted datetime string
8
+ def self.to_rfc1123(date_time)
9
+ date_time.httpdate unless date_time.nil?
10
+ end
11
+
12
+ # Safely converts a map of DateTime objects into a map of rfc1123 format string
13
+ # @param [hash] a map of DateTime objects
14
+ # @return [hash] a map of rfc1123 formatted datetime string
15
+ def self.to_rfc1123_map(date_time, hash, key)
16
+ return if date_time.nil?
17
+
18
+ hash[key] = {}
19
+ date_time.each do |k, v|
20
+ hash[key][k] =
21
+ if v.is_a?(BaseModel)
22
+ v.to_hash
23
+ else
24
+ v.is_a?(DateTime) ? DateTimeHelper.to_rfc1123(v) : v
25
+ end
26
+ end
27
+ hash[key]
28
+ end
29
+
30
+ # Safely converts an array of DateTime objects into an array of rfc1123 format string
31
+ # @param [Array] an array of DateTime objects
32
+ # @return [Array] an array of rfc1123 formatted datetime string
33
+ def self.to_rfc1123_array(date_time, hash, key)
34
+ return if date_time.nil?
35
+
36
+ hash[key] = date_time.map do |v|
37
+ if v.is_a?(BaseModel)
38
+ v.to_hash
39
+ else
40
+ v.is_a?(DateTime) ? DateTimeHelper.to_rfc1123(v) : v
41
+ end
42
+ end
43
+ end
44
+
45
+ # Safely converts a DateTime object into a unix format string
46
+ # @param [DateTime] The DateTime object
47
+ # @return [String] The unix formatted datetime string
48
+ def self.to_unix(date_time)
49
+ date_time.to_time.utc.to_i unless date_time.nil?
50
+ end
51
+
52
+ # Safely converts a map of DateTime objects into a map of unix format string
53
+ # @param [hash] a map of DateTime objects
54
+ # @return [hash] a map of unix formatted datetime string
55
+ def self.to_unix_map(date_time, hash, key)
56
+ return if date_time.nil?
57
+
58
+ hash[key] = {}
59
+ date_time.each do |k, v|
60
+ hash[key][k] =
61
+ if v.is_a?(BaseModel)
62
+ v.to_hash
63
+ else
64
+ v.is_a?(DateTime) ? DateTimeHelper.to_unix(v) : v
65
+ end
66
+ end
67
+ hash[key]
68
+ end
69
+
70
+ # Safely converts an array of DateTime objects into a map of unix format string
71
+ # @param [hash] an array of DateTime objects
72
+ # @return [hash] an array of unix formatted datetime string
73
+ def self.to_unix_array(date_time, hash, key)
74
+ return if date_time.nil?
75
+
76
+ hash[key] = date_time.map do |v|
77
+ if v.is_a?(BaseModel)
78
+ v.to_hash
79
+ else
80
+ v.is_a?(DateTime) ? DateTimeHelper.to_unix(v) : v
81
+ end
82
+ end
83
+ end
84
+
85
+ # Safely converts a DateTime object into a rfc3339 format string
86
+ # @param [DateTime] The DateTime object
87
+ # @return [String] The rfc3339 formatted datetime string
88
+ def self.to_rfc3339(date_time)
89
+ date_time.rfc3339 unless date_time.nil?
90
+ end
91
+
92
+ # Safely converts a map of DateTime objects into a map of rfc1123 format string
93
+ # @param [hash] a map of DateTime objects
94
+ # @return [hash] a map of rfc1123 formatted datetime string
95
+ def self.to_rfc3339_map(date_time, hash, key)
96
+ return if date_time.nil?
97
+
98
+ hash[key] = {}
99
+ date_time.each do |k, v|
100
+ hash[key][k] =
101
+ if v.is_a?(BaseModel)
102
+ v.to_hash
103
+ else
104
+ v.is_a?(DateTime) ? DateTimeHelper.to_rfc3339(v) : v
105
+ end
106
+ end
107
+ hash[key]
108
+ end
109
+
110
+ # Safely converts an array of DateTime objects into an array of rfc1123 format string
111
+ # @param [Array] an array of DateTime objects
112
+ # @return [Array] an array of rfc1123 formatted datetime string
113
+ def self.to_rfc3339_array(date_time, hash, key)
114
+ return if date_time.nil?
115
+
116
+ hash[key] = date_time.map do |v|
117
+ if v.is_a?(BaseModel)
118
+ v.to_hash
119
+ else
120
+ v.is_a?(DateTime) ? DateTimeHelper.to_rfc3339(v) : v
121
+ end
122
+ end
123
+ end
124
+
125
+ # Safely converts a rfc1123 format string into a DateTime object
126
+ # @param [String] The rfc1123 formatted datetime string
127
+ # @return [DateTime] A DateTime object
128
+ def self.from_rfc1123(date_time)
129
+ DateTime.httpdate(date_time)
130
+ end
131
+
132
+ # Safely converts a unix format string into a DateTime object
133
+ # @param [String] The unix formatted datetime string
134
+ # @return [DateTime] A DateTime object
135
+ def self.from_unix(date_time)
136
+ Time.at(date_time.to_i).utc.to_datetime
137
+ end
138
+
139
+ # Safely converts a rfc3339 format string into a DateTime object
140
+ # @param [String] The rfc3339 formatted datetime string
141
+ # @return [DateTime] A DateTime object
142
+ def self.from_rfc3339(date_time)
143
+ # missing timezone information
144
+ if date_time.end_with?('Z') || date_time.index('+')
145
+ DateTime.rfc3339(date_time)
146
+ else
147
+ DateTime.rfc3339("#{date_time}Z")
148
+ end
149
+ end
150
+ end
151
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: square.rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 10.0.0.20210421
4
+ version: 13.0.0.20210721
5
5
  platform: ruby
6
6
  authors:
7
7
  - Square Developer Platform
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-04-27 00:00:00.000000000 Z
11
+ date: 2021-07-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: logging
@@ -31,9 +31,9 @@ dependencies:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '1.0'
34
- - - ">="
34
+ - - "<="
35
35
  - !ruby/object:Gem::Version
36
- version: 1.0.1
36
+ version: 1.3.0
37
37
  type: :runtime
38
38
  prerelease: false
39
39
  version_requirements: !ruby/object:Gem::Requirement
@@ -41,9 +41,9 @@ dependencies:
41
41
  - - "~>"
42
42
  - !ruby/object:Gem::Version
43
43
  version: '1.0'
44
- - - ">="
44
+ - - "<="
45
45
  - !ruby/object:Gem::Version
46
- version: 1.0.1
46
+ version: 1.3.0
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: faraday_middleware
49
49
  requirement: !ruby/object:Gem::Requirement
@@ -140,6 +140,7 @@ files:
140
140
  - lib/square/api/bank_accounts_api.rb
141
141
  - lib/square/api/base_api.rb
142
142
  - lib/square/api/bookings_api.rb
143
+ - lib/square/api/cards_api.rb
143
144
  - lib/square/api/cash_drawers_api.rb
144
145
  - lib/square/api/catalog_api.rb
145
146
  - lib/square/api/checkout_api.rb
@@ -149,6 +150,8 @@ files:
149
150
  - lib/square/api/devices_api.rb
150
151
  - lib/square/api/disputes_api.rb
151
152
  - lib/square/api/employees_api.rb
153
+ - lib/square/api/gift_card_activities_api.rb
154
+ - lib/square/api/gift_cards_api.rb
152
155
  - lib/square/api/inventory_api.rb
153
156
  - lib/square/api/invoices_api.rb
154
157
  - lib/square/api/labor_api.rb
@@ -160,6 +163,8 @@ files:
160
163
  - lib/square/api/orders_api.rb
161
164
  - lib/square/api/payments_api.rb
162
165
  - lib/square/api/refunds_api.rb
166
+ - lib/square/api/sites_api.rb
167
+ - lib/square/api/snippets_api.rb
163
168
  - lib/square/api/subscriptions_api.rb
164
169
  - lib/square/api/team_api.rb
165
170
  - lib/square/api/terminal_api.rb
@@ -178,6 +183,7 @@ files:
178
183
  - lib/square/http/http_method_enum.rb
179
184
  - lib/square/http/http_request.rb
180
185
  - lib/square/http/http_response.rb
186
+ - lib/square/utilities/date_time_helper.rb
181
187
  - lib/square/utilities/file_wrapper.rb
182
188
  - spec/user_journey_spec.rb
183
189
  - test/api/api_test_base.rb