suggestgrid 0.3.0 → 0.5.0.rc3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/lib/suggestgrid/api_helper.rb +146 -54
  3. data/lib/suggestgrid/configuration.rb +5 -2
  4. data/lib/suggestgrid/controllers/action_controller.rb +178 -79
  5. data/lib/suggestgrid/controllers/base_controller.rb +18 -15
  6. data/lib/suggestgrid/controllers/metadata_controller.rb +313 -171
  7. data/lib/suggestgrid/controllers/recommendation_controller.rb +75 -35
  8. data/lib/suggestgrid/controllers/similarity_controller.rb +75 -35
  9. data/lib/suggestgrid/controllers/type_controller.rb +131 -74
  10. data/lib/suggestgrid/exceptions/api_exception.rb +4 -2
  11. data/lib/suggestgrid/exceptions/{detailed_error_response_error_exception.rb → detailed_error_response.rb} +9 -9
  12. data/lib/suggestgrid/exceptions/{error_response_error_exception.rb → error_response.rb} +9 -9
  13. data/lib/suggestgrid/exceptions/{limit_exceeded_error_response_error_exception.rb → limit_exceeded_error_response.rb} +9 -9
  14. data/lib/suggestgrid/http/auth/basic_auth.rb +8 -5
  15. data/lib/suggestgrid/http/faraday_client.rb +19 -7
  16. data/lib/suggestgrid/http/http_call_back.rb +11 -6
  17. data/lib/suggestgrid/http/http_client.rb +50 -32
  18. data/lib/suggestgrid/http/http_context.rb +5 -2
  19. data/lib/suggestgrid/http/http_method_enum.rb +6 -2
  20. data/lib/suggestgrid/http/http_request.rb +7 -3
  21. data/lib/suggestgrid/http/http_response.rb +3 -1
  22. data/lib/suggestgrid/models/action.rb +15 -14
  23. data/lib/suggestgrid/models/actions_response.rb +16 -14
  24. data/lib/suggestgrid/models/base_model.rb +11 -9
  25. data/lib/suggestgrid/models/bulk_post_error.rb +11 -11
  26. data/lib/suggestgrid/models/bulk_post_response.rb +16 -13
  27. data/lib/suggestgrid/models/get_recommended_items_body.rb +32 -25
  28. data/lib/suggestgrid/models/get_recommended_users_body.rb +32 -25
  29. data/lib/suggestgrid/models/get_similar_items_body.rb +33 -24
  30. data/lib/suggestgrid/models/get_similar_users_body.rb +30 -23
  31. data/lib/suggestgrid/models/get_type_response.rb +9 -9
  32. data/lib/suggestgrid/models/get_types_response.rb +9 -9
  33. data/lib/suggestgrid/models/items_response.rb +16 -14
  34. data/lib/suggestgrid/models/message_response.rb +9 -9
  35. data/lib/suggestgrid/models/metadata.rb +9 -8
  36. data/lib/suggestgrid/models/type_request_body.rb +11 -10
  37. data/lib/suggestgrid/models/users_response.rb +16 -14
  38. data/lib/suggestgrid/suggestgrid_client.rb +16 -14
  39. data/lib/suggestgrid.rb +5 -4
  40. data/spec/swagger.yaml +3 -3
  41. metadata +8 -8
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f4162fd36c4cfabbbc3ac47dc4a9b442ee8d2899
4
- data.tar.gz: 4ccbc83218922d0368ed16256fd9c6782944fdbb
3
+ metadata.gz: a2a974bdf596222b4c056093bce0bd736ecc28f5
4
+ data.tar.gz: 9853de9a1a5c71516759bd8060d03831ab0f7e47
5
5
  SHA512:
6
- metadata.gz: 24c608a35956ccaab49f3b4e16819840abf3d632f8fbe68fce58ece6fb9a3cf55332a1adfc27a9e691903498cf20004e8cc395c2f008a71bd959518e88081fcb
7
- data.tar.gz: 1251ea00f8fe3e5aa4d6b7e674945b1f1060e19030b0085360766dd4543093f2913ef1a6a16bc3e56f9d2d7725848b5bce49ad5a218822cca920414caf1b8f22
6
+ metadata.gz: 3976ab3ffa54efe3444cd5363d647e2756d74a72a5b19387f7d6158a60bcff4842e89ed8ed754bb2ab1cea8027a64e74799a55eecb166134411a08b24fc5cb79
7
+ data.tar.gz: 11656a71d76f28961d61abc699f62b4122fbe45ad97249853acb2b6def8c65d455618ec031db9dcf6c59f1306e9cba008b353af2a11404b1aa8872733e76ec0e
@@ -1,18 +1,22 @@
1
- # This file was automatically generated for SuggestGrid by APIMATIC v2.0 ( https://apimatic.io ).
1
+ # This file was automatically generated for SuggestGrid by APIMATIC v2.0
2
+ # ( https://apimatic.io ).
2
3
 
3
4
  module SuggestGrid
5
+ # API utility class
4
6
  class APIHelper
5
- # Serializes an array parameter (creates key value pairs)
6
- # @param [String] The name of the parameter
7
- # @param [Array] The value of the parameter
8
- # @param [String] The format of the serialization
7
+ # Serializes an array parameter (creates key value pairs).
8
+ # @param [String] The name of the parameter.
9
+ # @param [Array] The value of the parameter.
10
+ # @param [String] The format of the serialization.
9
11
  def self.serialize_array(key, array, formatting: 'indexed')
10
12
  tuples = []
11
13
 
12
14
  if formatting == 'unindexed'
13
15
  tuples += array.map { |element| ["#{key}[]", element] }
14
16
  elsif formatting == 'indexed'
15
- tuples += array.map.with_index { |element, index| ["#{key}[#{index}]", element] }
17
+ tuples += array.map.with_index do |element, index|
18
+ ["#{key}[#{index}]", element]
19
+ end
16
20
  elsif formatting == 'plain'
17
21
  tuples += array.map { |element| [key, element] }
18
22
  else
@@ -21,17 +25,21 @@ module SuggestGrid
21
25
  tuples
22
26
  end
23
27
 
24
- # Replaces template parameters in the given url
25
- # @param [String] The query string builder to replace the template parameters
26
- # @param [Hash] The parameters to replace in the url
28
+ # Replaces template parameters in the given url.
29
+ # @param [String] The query string builder to replace the template
30
+ # parameters.
31
+ # @param [Hash] The parameters to replace in the url.
27
32
  def self.append_url_with_template_parameters(query_builder, parameters)
28
33
  # perform parameter validation
29
- raise ArgumentError, 'Given value for parameter \"query_builder\" is invalid.' unless query_builder.instance_of? String
34
+ unless query_builder.instance_of? String
35
+ raise ArgumentError, 'Given value for parameter \"query_builder\" is
36
+ invalid.'
37
+ end
30
38
 
31
- # return if there are no parameters to replace
39
+ # Return if there are no parameters to replace.
32
40
  return query_builder if parameters.nil?
33
41
 
34
- # iterate and append parameters
42
+ # Iterate and append parameters.
35
43
  parameters.each do |key, value|
36
44
  replace_value = ''
37
45
 
@@ -44,38 +52,50 @@ module SuggestGrid
44
52
  replace_value = CGI.escape(value.to_s)
45
53
  end
46
54
 
47
- # find the template parameter and replace it with its value
55
+ # Find the template parameter and replace it with its value.
48
56
  query_builder = query_builder.gsub('{' + key.to_s + '}', replace_value)
49
57
  end
50
58
  query_builder
51
59
  end
52
60
 
53
- # Appends the given set of parameters to the given query string
54
- # @param [String] The query string builder to add the query parameters to
55
- # @param [Hash] The parameters to append
56
- # @param [String] The format of array parameter serialization
57
- def self.append_url_with_query_parameters(query_builder, parameters, array_serialization: 'indexed')
58
- # perform parameter validation
59
- raise ArgumentError, 'Given value for parameter \"query_builder\" is invalid.' unless query_builder.instance_of? String
61
+ # Appends the given set of parameters to the given query string.
62
+ # @param [String] The query string builder to add the query parameters to.
63
+ # @param [Hash] The parameters to append.
64
+ # @param [String] The format of array parameter serialization.
65
+ def self.append_url_with_query_parameters(query_builder, parameters,
66
+ array_serialization: 'indexed')
67
+ # Perform parameter validation.
68
+ unless query_builder.instance_of? String
69
+ raise ArgumentError, 'Given value for parameter \"query_builder\"
70
+ is invalid.'
71
+ end
60
72
 
61
- # return if there are no parameters to replace
73
+ # Return if there are no parameters to replace.
62
74
  return query_builder if parameters.nil?
63
75
 
64
76
  parameters.each do |key, value|
65
- seperator = (query_builder.include? '?') ? '&' : '?'
66
- if not value.nil?
77
+ seperator = query_builder.include?('?') ? '&' : '?'
78
+ unless value.nil?
67
79
  if value.instance_of? Array
68
80
  value.compact!
69
- if array_serialization == 'csv'
70
- query_builder += "#{seperator}#{key}=#{value.map { |element| CGI.escape(element.to_s) }.join(',')}"
71
- elsif array_serialization == 'psv'
72
- query_builder += "#{seperator}#{key}=#{value.map { |element| CGI.escape(element.to_s) }.join('|')}"
73
- elsif array_serialization == 'tsv'
74
- query_builder += "#{seperator}#{key}=#{value.map { |element| CGI.escape(element.to_s) }.join('\t')}"
75
- else
76
- query_builder += "#{seperator}#{APIHelper.serialize_array(key, value, formatting: array_serialization).
77
- map { |k, v| "#{k}=#{CGI.escape(v.to_s)}" }.join('&')}"
78
- end
81
+ query_builder += if array_serialization == 'csv'
82
+ "#{seperator}#{key}=#{value.map do |element|
83
+ CGI.escape(element.to_s)
84
+ end.join(',')}"
85
+ elsif array_serialization == 'psv'
86
+ "#{seperator}#{key}=#{value.map do |element|
87
+ CGI.escape(element.to_s)
88
+ end.join('|')}"
89
+ elsif array_serialization == 'tsv'
90
+ "#{seperator}#{key}=#{value.map do |element|
91
+ CGI.escape(element.to_s)
92
+ end.join("\t")}"
93
+ else
94
+ "#{seperator}#{APIHelper.serialize_array(
95
+ key, value, formatting: array_serialization
96
+ ).map { |k, v| "#{k}=#{CGI.escape(v.to_s)}" }
97
+ .join('&')}"
98
+ end
79
99
  else
80
100
  query_builder += "#{seperator}#{key}=#{CGI.escape(value.to_s)}"
81
101
  end
@@ -84,31 +104,31 @@ module SuggestGrid
84
104
  query_builder
85
105
  end
86
106
 
87
- # Validates and processes the given Url
88
- # @param [String] The given Url to process
89
- # @return [String] Pre-processed Url as string
107
+ # Validates and processes the given Url.
108
+ # @param [String] The given Url to process.
109
+ # @return [String] Pre-processed Url as string.
90
110
  def self.clean_url(url)
91
- # perform parameter validation
111
+ # Perform parameter validation.
92
112
  raise ArgumentError, 'Invalid Url.' unless url.instance_of? String
93
113
 
94
- # ensure that the urls are absolute
114
+ # Ensure that the urls are absolute.
95
115
  matches = url.match(%r{^(https?:\/\/[^\/]+)})
96
116
  raise ArgumentError, 'Invalid Url format.' if matches.nil?
97
117
 
98
- # get the http protocol match
118
+ # Get the http protocol match.
99
119
  protocol = matches[1]
100
120
 
101
- # check if parameters exist
121
+ # Check if parameters exist.
102
122
  index = url.index('?')
103
123
 
104
- # remove redundant forward slashes
124
+ # Remove redundant forward slashes.
105
125
  query = url[protocol.length...(!index.nil? ? index : url.length)]
106
126
  query.gsub!(%r{\/\/+}, '/')
107
127
 
108
- # get the parameters
128
+ # Get the parameters.
109
129
  parameters = !index.nil? ? url[url.index('?')...url.length] : ''
110
130
 
111
- # return processed url
131
+ # Return processed url.
112
132
  protocol + query + parameters
113
133
  end
114
134
 
@@ -116,7 +136,7 @@ module SuggestGrid
116
136
  # @param [String] A JSON string.
117
137
  def self.json_deserialize(json)
118
138
  return JSON.parse(json)
119
- rescue
139
+ rescue StandardError
120
140
  raise TypeError, 'Server responded with invalid JSON.'
121
141
  end
122
142
 
@@ -132,18 +152,52 @@ module SuggestGrid
132
152
  def self.form_encode_parameters(form_parameters)
133
153
  encoded = {}
134
154
  form_parameters.each do |key, value|
135
- encoded.merge!(APIHelper.form_encode(value, key))
155
+ encoded.merge!(APIHelper.form_encode(value, key, formatting:
156
+ Configuration.array_serialization))
136
157
  end
137
158
  encoded
138
159
  end
139
160
 
161
+ def self.custom_merge(a, b)
162
+ x = {}
163
+ a.each do |key, value_a|
164
+ b.each do |k, value_b|
165
+ next unless key == k
166
+ x[k] = []
167
+ if value_a.instance_of? Array
168
+ value_a.each do |v|
169
+ x[k].push(v)
170
+ end
171
+ else
172
+ x[k].push(value_a)
173
+ end
174
+ if value_b.instance_of? Array
175
+ value_b.each do |v|
176
+ x[k].push(v)
177
+ end
178
+ else
179
+ x[k].push(value_b)
180
+ end
181
+ a.delete(k)
182
+ b.delete(k)
183
+ end
184
+ end
185
+ x.merge!(a)
186
+ x.merge!(b)
187
+ x
188
+ end
189
+
140
190
  # Form encodes an object.
141
191
  # @param [Dynamic] An object to form encode.
142
192
  # @param [String] The name of the object.
143
- # @return [Hash] A form encoded representation of the object in the form of a hash.
144
- def self.form_encode(obj, instance_name)
193
+ # @return [Hash] A form encoded representation of the object in the form
194
+ # of a hash.
195
+ def self.form_encode(obj, instance_name, formatting: 'indexed')
145
196
  retval = {}
146
197
 
198
+ serializable_types = [String, Numeric, TrueClass,
199
+ FalseClass, Date, DateTime]
200
+
147
201
  # If this is a structure, resolve it's field names.
148
202
  obj = obj.to_hash if obj.is_a? BaseModel
149
203
 
@@ -151,31 +205,69 @@ module SuggestGrid
151
205
  if obj.nil?
152
206
  nil
153
207
  elsif obj.instance_of? Array
154
- obj.each_with_index do |value, index|
155
- retval.merge!(APIHelper.form_encode(value, instance_name + '[' + index.to_s + ']'))
208
+ if formatting == 'indexed'
209
+ obj.each_with_index do |value, index|
210
+ retval.merge!(APIHelper.form_encode(value, instance_name + '[' +
211
+ index.to_s + ']'))
212
+ end
213
+ elsif serializable_types.map { |x| obj[0].is_a? x }.any?
214
+ obj.each do |value|
215
+ abc = if formatting == 'unindexed'
216
+ APIHelper.form_encode(value, instance_name + '[]',
217
+ formatting: formatting)
218
+ else
219
+ APIHelper.form_encode(value, instance_name,
220
+ formatting: formatting)
221
+ end
222
+ retval = APIHelper.custom_merge(retval, abc)
223
+ # print retval
224
+ end
225
+ else
226
+ obj.each_with_index do |value, index|
227
+ retval.merge!(APIHelper.form_encode(value, instance_name + '[' +
228
+ index.to_s + ']', formatting: formatting))
229
+ end
156
230
  end
157
231
  elsif obj.instance_of? Hash
158
232
  obj.each do |key, value|
159
- retval.merge!(APIHelper.form_encode(value, instance_name + '[' + key + ']'))
233
+ retval.merge!(APIHelper.form_encode(value, instance_name + '[' +
234
+ key + ']', formatting: formatting))
160
235
  end
161
236
  else
162
237
  retval[instance_name] = obj
163
238
  end
164
239
  retval
165
240
  end
241
+
242
+ # Safely converts a string into an rfc3339 DateTime object
243
+ # @param [String] The datetime string
244
+ # @return [DateTime] A DateTime object of rfc3339 format
245
+ def self.rfc3339(date_time)
246
+ # missing timezone information
247
+ if date_time.end_with?('Z') || date_time.index('+')
248
+ DateTime.rfc3339(date_time)
249
+ else
250
+ DateTime.rfc3339(date_time + 'Z')
251
+ end
252
+ end
166
253
  end
167
254
  end
168
255
 
169
- # extend types to support to_bool
256
+ # Extend types to support to_bool.
170
257
  module ToBoolean
171
258
  def to_bool
172
- return true if self == true || self.to_s.strip =~ /^(true|yes|y|1)$/i
173
- return false
259
+ return true if self == true || to_s.strip =~ /^(true|yes|y|1)$/i
260
+ false
174
261
  end
175
262
  end
176
263
 
264
+ # Extend NilClass type to support to_bool.
177
265
  class NilClass; include ToBoolean; end
266
+ # Extend TrueClass type to support to_bool.
178
267
  class TrueClass; include ToBoolean; end
268
+ # Extend FalseClass type to support to_bool.
179
269
  class FalseClass; include ToBoolean; end
270
+ # Extend Numeric type to support to_bool.
180
271
  class Numeric; include ToBoolean; end
181
- class String; include ToBoolean; end
272
+ # Extend String type to support to_bool.
273
+ class String; include ToBoolean; end
@@ -1,6 +1,9 @@
1
- # This file was automatically generated for SuggestGrid by APIMATIC v2.0 ( https://apimatic.io ).
1
+ # This file was automatically generated for SuggestGrid by APIMATIC v2.0
2
+ # ( https://apimatic.io ).
2
3
 
3
4
  module SuggestGrid
5
+ # All configuration including auth info and base URI for the API access
6
+ # are configured in this class.
4
7
  class Configuration
5
8
  # The base Uri for API calls
6
9
  @base_uri = 'https://example.com/api'
@@ -11,7 +14,7 @@ module SuggestGrid
11
14
  # The password to use with basic authentication
12
15
  @basic_auth_password = 'TODO: Replace'
13
16
 
14
- # The attribute accessors for public properties
17
+ # The attribute accessors for public properties.
15
18
  class << self
16
19
  attr_accessor :array_serialization
17
20
  attr_accessor :base_uri