square.rb 17.1.0.20220120 → 18.0.0.20220216

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 407147246777f8a4eda2d4848cad5edb62be5801c25b6361f0dfb21d58663fd9
4
- data.tar.gz: 735c7e92297b1d4a79ebd856dbe39cc304051536622f0277ddd9489811652cb6
3
+ metadata.gz: d63ad56661f521ead949670191ddb004cf944daedf7836047c9281e8e6600ecf
4
+ data.tar.gz: 548171c3a90103f2a2492166e6b69f9c0dd7855f1c20d656e4c7c1f922053e86
5
5
  SHA512:
6
- metadata.gz: 90ccb1516f8ff8998787d63a168c8c8688b9a12691d85cac3a2b6af35ce52af93bbc013e11336d5319cc252ec75ce7f790165ea5c38c69367f092e5ef62b365d
7
- data.tar.gz: 05a3eb69caf678ad7f071b66a27c3ed4375ac96470ba09e51df9db6eba1401b80bd461c7fd6cb7bde91f30bb7ee5d11b9f7f293a59d40c70ab5ed52b25b9d180
6
+ metadata.gz: 4d5f5cdb0c4992a16eca7327a67642d9fcb807ae040b7c3426d5635ac3ef9f40ab9d144fe011b60c5ad996b81b098e49a3e4cf8a3e6aa3dd4742fab08fd6e1b3
7
+ data.tar.gz: 56b7b2f269877ec3b2f867d608e0a803a066e74bc958d2e0f60e156a034360e872d0c7eccefa5d552a35b700f2c9cb83b364a942e96968a713ab33013069dea5
data/README.md CHANGED
@@ -10,7 +10,7 @@ Use this gem to integrate Square payments into your app and grow your business w
10
10
 
11
11
  ## Requirements
12
12
 
13
- We support Ruby 2.5.x, 2.6.x, 2.7.x, and 3.0.x.
13
+ We support Ruby 2.6 through 3.1.
14
14
 
15
15
  ## Installation
16
16
 
@@ -38,7 +38,7 @@ module Square
38
38
  end
39
39
 
40
40
  def get_user_agent
41
- user_agent = 'Square-Ruby-SDK/17.1.0.20220120 ({api-version}) {engine}/{engine-version} ({os-info}) {detail}'
41
+ user_agent = 'Square-Ruby-SDK/18.0.0.20220216 ({api-version}) {engine}/{engine-version} ({os-info}) {detail}'
42
42
  user_agent['{engine}'] = RUBY_ENGINE
43
43
  user_agent['{engine-version}'] = RUBY_ENGINE_VERSION
44
44
  user_agent['{os-info}'] = RUBY_PLATFORM
@@ -5,15 +5,17 @@ module Square
5
5
  super(config, http_call_back: http_call_back)
6
6
  end
7
7
 
8
- # Returns `Merchant` information for a given access token.
9
- # If you don't know a `Merchant` ID, you can use this endpoint to retrieve
10
- # the merchant ID for an access token.
11
- # You can specify your personal access token to get your own merchant
12
- # information or specify an OAuth token
13
- # to get the information for the merchant that granted you access.
8
+ # Provides details about the merchant associated with a given access token.
9
+ # The access token used to connect your application to a Square seller is
10
+ # associated
11
+ # with a single merchant. That means that `ListMerchants` returns a list
12
+ # with a single `Merchant` object. You can specify your personal access
13
+ # token
14
+ # to get your own merchant information or specify an OAuth token to get the
15
+ # information for the merchant that granted your application access.
14
16
  # If you know the merchant ID, you can also use the
15
17
  # [RetrieveMerchant]($e/Merchants/RetrieveMerchant)
16
- # endpoint to get the merchant information.
18
+ # endpoint to retrieve the merchant information.
17
19
  # @param [Integer] cursor Optional parameter: The cursor generated by the
18
20
  # previous response.
19
21
  # @return [ListMerchantsResponse Hash] response from the API call
@@ -48,7 +50,7 @@ module Square
48
50
  )
49
51
  end
50
52
 
51
- # Retrieve a `Merchant` object for the given `merchant_id`.
53
+ # Retrieves the `Merchant` object for the given `merchant_id`.
52
54
  # @param [String] merchant_id Required parameter: The ID of the merchant to
53
55
  # retrieve. If the string "me" is supplied as the ID, then retrieve the
54
56
  # merchant that is currently accessible to this call.
@@ -8,18 +8,16 @@ module Square
8
8
  def self.serialize_array(key, array, formatting: 'indexed')
9
9
  tuples = []
10
10
 
11
- case formatting
12
- when 'unindexed'
13
- tuples += array.map { |element| ["#{key}[]", element] }
14
- when 'indexed'
15
- tuples += array.map.with_index do |element, index|
16
- ["#{key}[#{index}]", element]
17
- end
18
- when 'plain'
19
- tuples += array.map { |element| [key, element] }
20
- else
21
- raise ArgumentError, 'Invalid format provided.'
22
- end
11
+ tuples += case formatting
12
+ when 'csv'
13
+ [[key, array.map { |element| CGI.escape(element.to_s) }.join(',')]]
14
+ when 'psv'
15
+ [[key, array.map { |element| CGI.escape(element.to_s) }.join('|')]]
16
+ when 'tsv'
17
+ [[key, array.map { |element| CGI.escape(element.to_s) }.join("\t")]]
18
+ else
19
+ array.map { |element| [key, element] }
20
+ end
23
21
  tuples
24
22
  end
25
23
 
@@ -75,31 +73,19 @@ module Square
75
73
  return query_builder if parameters.nil?
76
74
 
77
75
  array_serialization = 'indexed'
76
+ parameters = process_complex_types_parameters(parameters, array_serialization)
78
77
 
79
78
  parameters.each do |key, value|
80
79
  seperator = query_builder.include?('?') ? '&' : '?'
81
80
  unless value.nil?
82
81
  if value.instance_of? Array
83
82
  value.compact!
84
- query_builder += case array_serialization
85
- when 'csv'
86
- "#{seperator}#{key}=#{value.map do |element|
87
- CGI.escape(element.to_s)
88
- end.join(',')}"
89
- when 'psv'
90
- "#{seperator}#{key}=#{value.map do |element|
91
- CGI.escape(element.to_s)
92
- end.join('|')}"
93
- when 'tsv'
94
- "#{seperator}#{key}=#{value.map do |element|
95
- CGI.escape(element.to_s)
96
- end.join("\t")}"
97
- else
98
- "#{seperator}#{APIHelper.serialize_array(
99
- key, value, formatting: array_serialization
100
- ).map { |k, v| "#{k}=#{CGI.escape(v.to_s)}" }
101
- .join('&')}"
102
- end
83
+ APIHelper.serialize_array(
84
+ key, value, formatting: array_serialization
85
+ ).each do |element|
86
+ seperator = query_builder.include?('?') ? '&' : '?'
87
+ query_builder += "#{seperator}#{element[0]}=#{element[1]}"
88
+ end
103
89
  else
104
90
  query_builder += "#{seperator}#{key}=#{CGI.escape(value.to_s)}"
105
91
  end
@@ -163,6 +149,18 @@ module Square
163
149
  encoded
164
150
  end
165
151
 
152
+ # Process complex types in query_params.
153
+ # @param [Hash] The hash of query parameters.
154
+ # @return [Hash] A hash with the processed query parameters.
155
+ def self.process_complex_types_parameters(query_parameters, array_serialization)
156
+ processed_params = {}
157
+ query_parameters.each do |key, value|
158
+ processed_params.merge!(APIHelper.form_encode(value, key, formatting:
159
+ array_serialization))
160
+ end
161
+ processed_params
162
+ end
163
+
166
164
  def self.custom_merge(a, b)
167
165
  x = {}
168
166
  a.each do |key, value_a|
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
- '17.1.0.20220120'
7
+ '18.0.0.20220216'
8
8
  end
9
9
 
10
10
  def square_version
@@ -213,16 +213,16 @@ module Square
213
213
  @terminal ||= TerminalApi.new config
214
214
  end
215
215
 
216
- def initialize(http_client_instance: nil, timeout: 60, max_retries: 0,
216
+ def initialize(connection: nil, timeout: 60, max_retries: 0,
217
217
  retry_interval: 1, backoff_factor: 2,
218
218
  retry_statuses: [408, 413, 429, 500, 502, 503, 504, 521, 522, 524],
219
219
  retry_methods: %i[get put], environment: 'production',
220
220
  custom_url: 'https://connect.squareup.com',
221
- square_version: '2022-01-20', access_token: '',
221
+ square_version: '2022-02-16', access_token: '',
222
222
  user_agent_detail: '', additional_headers: {}, config: nil)
223
223
  @config = if config.nil?
224
- Configuration.new(http_client_instance: http_client_instance,
225
- timeout: timeout, max_retries: max_retries,
224
+ Configuration.new(connection: connection, timeout: timeout,
225
+ max_retries: max_retries,
226
226
  retry_interval: retry_interval,
227
227
  backoff_factor: backoff_factor,
228
228
  retry_statuses: retry_statuses,
@@ -3,9 +3,9 @@ module Square
3
3
  # are configured in this class.
4
4
  class Configuration
5
5
  # The attribute readers for properties.
6
- attr_reader :http_client, :http_client_instance, :timeout, :max_retries, :retry_interval,
7
- :backoff_factor, :retry_statuses, :retry_methods, :environment, :custom_url,
8
- :square_version, :access_token, :user_agent_detail
6
+ attr_reader :http_client, :connection, :timeout, :max_retries, :retry_interval, :backoff_factor,
7
+ :retry_statuses, :retry_methods, :environment, :custom_url, :square_version,
8
+ :access_token, :user_agent_detail
9
9
 
10
10
  def additional_headers
11
11
  @additional_headers.clone
@@ -15,15 +15,15 @@ module Square
15
15
  attr_reader :environments
16
16
  end
17
17
 
18
- def initialize(http_client_instance: nil, timeout: 60, max_retries: 0,
18
+ def initialize(connection: nil, timeout: 60, max_retries: 0,
19
19
  retry_interval: 1, backoff_factor: 2,
20
20
  retry_statuses: [408, 413, 429, 500, 502, 503, 504, 521, 522, 524],
21
21
  retry_methods: %i[get put], environment: 'production',
22
22
  custom_url: 'https://connect.squareup.com',
23
- square_version: '2022-01-20', access_token: '',
23
+ square_version: '2022-02-16', access_token: '',
24
24
  user_agent_detail: '', additional_headers: {})
25
- # The Http Client passed from the sdk user for making requests
26
- @http_client_instance = http_client_instance
25
+ # The Faraday connection object passed by the SDK user for making requests
26
+ @connection = connection
27
27
 
28
28
  # The value to use for connection timeout
29
29
  @timeout = timeout
@@ -66,12 +66,12 @@ module Square
66
66
  @user_agent_detail = get_user_agent(user_agent_detail)
67
67
  end
68
68
 
69
- def clone_with(http_client_instance: nil, timeout: nil, max_retries: nil,
69
+ def clone_with(connection: nil, timeout: nil, max_retries: nil,
70
70
  retry_interval: nil, backoff_factor: nil,
71
71
  retry_statuses: nil, retry_methods: nil, environment: nil,
72
72
  custom_url: nil, square_version: nil, access_token: nil,
73
73
  user_agent_detail: nil, additional_headers: nil)
74
- http_client_instance ||= self.http_client_instance
74
+ connection ||= self.connection
75
75
  timeout ||= self.timeout
76
76
  max_retries ||= self.max_retries
77
77
  retry_interval ||= self.retry_interval
@@ -85,8 +85,8 @@ module Square
85
85
  user_agent_detail ||= self.user_agent_detail
86
86
  additional_headers ||= self.additional_headers
87
87
 
88
- Configuration.new(http_client_instance: http_client_instance,
89
- timeout: timeout, max_retries: max_retries,
88
+ Configuration.new(connection: connection, timeout: timeout,
89
+ max_retries: max_retries,
90
90
  retry_interval: retry_interval,
91
91
  backoff_factor: backoff_factor,
92
92
  retry_statuses: retry_statuses,
@@ -102,8 +102,7 @@ module Square
102
102
  retry_interval: retry_interval,
103
103
  backoff_factor: backoff_factor,
104
104
  retry_statuses: retry_statuses,
105
- retry_methods: retry_methods,
106
- http_client_instance: http_client_instance)
105
+ retry_methods: retry_methods, connection: connection)
107
106
  end
108
107
 
109
108
  def get_user_agent(user_agent_detail)
@@ -4,29 +4,28 @@ require 'faraday_middleware'
4
4
  module Square
5
5
  # An implementation of HttpClient.
6
6
  class FaradayClient < HttpClient
7
+ # The attribute readers for properties.
8
+ attr_reader :connection
9
+
7
10
  # The constructor.
8
11
  def initialize(timeout:, max_retries:, retry_interval:,
9
12
  backoff_factor:, retry_statuses:, retry_methods:,
10
- http_client_instance: nil, cache: false, verify: true)
11
- if http_client_instance.nil?
12
- create_connection(timeout: timeout, max_retries: max_retries,
13
- retry_interval: retry_interval, backoff_factor: backoff_factor,
14
- retry_statuses: retry_statuses, retry_methods: retry_methods,
15
- cache: cache, verify: verify)
16
- else
17
- if http_client_instance.instance_variable_get('@connection').nil?
18
- raise ArgumentError,
19
- "`connection` cannot be nil in `#{self.class}`. Please specify a valid value."
20
- end
21
- @connection = http_client_instance.instance_variable_get('@connection')
22
- end
13
+ connection: nil, cache: false, verify: true)
14
+ @connection = if connection.nil?
15
+ create_connection(timeout: timeout, max_retries: max_retries,
16
+ retry_interval: retry_interval, backoff_factor: backoff_factor,
17
+ retry_statuses: retry_statuses, retry_methods: retry_methods,
18
+ cache: cache, verify: verify)
19
+ else
20
+ connection
21
+ end
23
22
  end
24
23
 
25
24
  # Method to initialize connection.
26
25
  def create_connection(timeout:, max_retries:, retry_interval:,
27
26
  backoff_factor:, retry_statuses:, retry_methods:,
28
27
  cache: false, verify: true)
29
- @connection = Faraday.new do |faraday|
28
+ Faraday.new do |faraday|
30
29
  faraday.use Faraday::HttpCache, serializer: Marshal if cache
31
30
  faraday.use FaradayMiddleware::FollowRedirects
32
31
  faraday.use :gzip
@@ -42,7 +41,6 @@ module Square
42
41
  faraday.options[:params_encoder] = Faraday::FlatParamsEncoder
43
42
  faraday.options[:timeout] = timeout if timeout.positive?
44
43
  end
45
- @connection
46
44
  end
47
45
 
48
46
  # Method overridden from HttpClient.
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: 17.1.0.20220120
4
+ version: 18.0.0.20220216
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: 2022-01-20 00:00:00.000000000 Z
11
+ date: 2022-02-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: logging