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
@@ -1,102 +1,159 @@
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
+ # ActionController
4
6
  class ActionController < BaseController
5
- @@instance = ActionController.new
6
- # Singleton instance of the controller class
7
- def self.instance
8
- @@instance
7
+ @instance = ActionController.new
8
+
9
+ class << self
10
+ attr_accessor :instance
11
+ end
12
+
13
+ def instance
14
+ self.class.instance
9
15
  end
10
16
 
11
- # Posts an Action
17
+ # Posts an action to the given type in the body.
18
+ # The body must have user id, item id and type.
19
+ # Rating is required for actions sent to an explicit type.
12
20
  # @param [Action] action Required parameter: The action to be posted.
13
21
  # @return MessageResponse response from the API call
14
22
  def post_action(action)
15
-
16
- # prepare query url
23
+ # Prepare query url.
17
24
  _query_builder = Configuration.base_uri.dup
18
25
  _query_builder << '/v1/actions'
19
26
  _query_url = APIHelper.clean_url _query_builder
20
27
 
21
- # prepare headers
28
+ # Prepare headers.
22
29
  _headers = {
23
30
  'accept' => 'application/json',
24
31
  'content-type' => 'application/json; charset=utf-8'
25
32
  }
26
33
 
27
- # prepare and execute HttpRequest
28
- _request = @http_client.post _query_url, headers: _headers, parameters: action.to_json
34
+ # Prepare and execute HttpRequest.
35
+ _request = @http_client.post(
36
+ _query_url,
37
+ headers: _headers,
38
+ parameters: action.to_json
39
+ )
29
40
  BasicAuth.apply(_request)
30
41
  _context = execute_request(_request)
31
42
 
32
- # validate response against endpoint and global error codes
43
+ # Validate response against endpoint and global error codes.
33
44
  if _context.response.status_code == 400
34
- raise ErrorResponseErrorException.new 'Required user id or item id parameters are missing from the request.', _context
45
+ raise ErrorResponse.new(
46
+ 'Required user id or item id parameters are missing from the' \
47
+ ' request.',
48
+ _context
49
+ )
35
50
  elsif _context.response.status_code == 402
36
- raise ErrorResponseErrorException.new 'Action limit exceeded.', _context
51
+ raise ErrorResponse.new(
52
+ 'Action limit exceeded.',
53
+ _context
54
+ )
37
55
  elsif _context.response.status_code == 404
38
- raise ErrorResponseErrorException.new 'Action type does not exists.', _context
39
- elsif !_context.response.status_code.between?(200, 208)
40
- raise ErrorResponseErrorException.new 'Unexpected internal error.', _context
56
+ raise ErrorResponse.new(
57
+ 'Action type does not exists.',
58
+ _context
59
+ )
60
+ end
61
+ unless _context.response.status_code.between?(200, 208)
62
+ raise ErrorResponse.new(
63
+ 'Unexpected internal error.',
64
+ _context
65
+ )
41
66
  end
42
67
  validate_response(_context)
43
68
 
44
- # return appropriate response type
69
+ # Return appropriate response type.
45
70
  decoded = APIHelper.json_deserialize(_context.response.raw_body)
46
- return MessageResponse.from_hash(decoded)
71
+ MessageResponse.from_hash(decoded)
47
72
  end
48
73
 
49
- # Posts Actions
50
- # @param [Collection] actions Required parameter: List of actions to be posted.
74
+ # Posts bulk actions to SuggestGrid.
75
+ # The recommended method for posting multiple actions at once.
76
+ # @param [Collection] actions Required parameter: List of actions to be posted
77
+ # separated with newlines. Note that this is not a valid JSON data
78
+ # structure. The body size is limited to 10 thousand lines.
51
79
  # @return BulkPostResponse response from the API call
52
80
  def post_bulk_actions(actions)
53
81
  body = ''
54
82
  actions.each do |action|
55
83
  body += "#{action.to_json}\n"
56
84
  end
57
-
58
- # prepare query url
85
+ # Prepare query url.
59
86
  _query_builder = Configuration.base_uri.dup
60
87
  _query_builder << '/v1/actions/_bulk'
61
88
  _query_url = APIHelper.clean_url _query_builder
62
89
 
63
- # prepare headers
90
+ # Prepare headers.
64
91
  _headers = {
65
92
  'accept' => 'application/json',
66
93
  'content-type' => 'text/plain; charset=utf-8'
67
94
  }
68
95
 
69
- # prepare and execute HttpRequest
70
- _request = @http_client.post _query_url, headers: _headers, parameters: body
96
+ # Prepare and execute HttpRequest.
97
+ _request = @http_client.post(
98
+ _query_url,
99
+ headers: _headers,
100
+ parameters: body
101
+ )
71
102
  BasicAuth.apply(_request)
72
103
  _context = execute_request(_request)
73
104
 
74
- # validate response against endpoint and global error codes
105
+ # Validate response against endpoint and global error codes.
75
106
  if _context.response.status_code == 400
76
- raise ErrorResponseErrorException.new 'Body is missing.', _context
107
+ raise ErrorResponse.new(
108
+ 'Body is missing.',
109
+ _context
110
+ )
77
111
  elsif _context.response.status_code == 402
78
- raise ErrorResponseErrorException.new 'Action limit exceeded.', _context
112
+ raise ErrorResponse.new(
113
+ 'Action limit exceeded.',
114
+ _context
115
+ )
79
116
  elsif _context.response.status_code == 404
80
- raise ErrorResponseErrorException.new 'Action type does not exists.', _context
117
+ raise ErrorResponse.new(
118
+ 'Action type does not exists.',
119
+ _context
120
+ )
81
121
  elsif _context.response.status_code == 413
82
- raise ErrorResponseErrorException.new 'Bulk request maximum line count exceeded.', _context
83
- elsif !_context.response.status_code.between?(200, 208)
84
- raise ErrorResponseErrorException.new 'Unexpected internal error.', _context
122
+ raise ErrorResponse.new(
123
+ 'Bulk request maximum line count exceeded.',
124
+ _context
125
+ )
126
+ end
127
+ unless _context.response.status_code.between?(200, 208)
128
+ raise ErrorResponse.new(
129
+ 'Unexpected internal error.',
130
+ _context
131
+ )
85
132
  end
86
133
  validate_response(_context)
87
134
 
88
- # return appropriate response type
135
+ # Return appropriate response type.
89
136
  decoded = APIHelper.json_deserialize(_context.response.raw_body)
90
- return BulkPostResponse.from_hash(decoded)
137
+ BulkPostResponse.from_hash(decoded)
91
138
  end
92
139
 
93
- # Gets Actions
140
+ # Get actions. Defaut responses will be paged by 10 actios each.
141
+ # Type, user id, item id, or older than parameters could be provided.
142
+ # The intersection of the provided parameters will be returned.
94
143
  # @param [String] type Optional parameter: Get actions of a type.
95
144
  # @param [String] user_id Optional parameter: Get actions of a user id.
96
145
  # @param [String] item_id Optional parameter: Get actions of an item id.
97
- # @param [String] older_than Optional parameter: Get actions older than the given duration, or the given time number. Could be a ISO 8601 duration, or a Unix time number. Specifications are available at https://en.wikipedia.org/wiki/ISO_8601#Durations, or https://en.wikipedia.org/wiki/Unix_time.
98
- # @param [Long] size Optional parameter: The number of the users response. Defaults to 10. Must be between 1 and 10,000 inclusive. This parameter must be string represetation of an integer like "1".
99
- # @param [Long] from Optional parameter: The number of users to be skipped from the response. Defaults to 0. Must be bigger than or equal to 0. This parameter must be string represetation of an integer like "1".
146
+ # @param [String] older_than Optional parameter: Get actions older than the
147
+ # given duration, or the given time number. Could be a ISO 8601 duration, or
148
+ # a Unix time number. Specifications are available at
149
+ # https://en.wikipedia.org/wiki/ISO_8601#Durations, or
150
+ # https://en.wikipedia.org/wiki/Unix_time.
151
+ # @param [Long] size Optional parameter: The number of the users response.
152
+ # Defaults to 10. Must be between 1 and 10,000 inclusive. This parameter
153
+ # must be string represetation of an integer like "1".
154
+ # @param [Long] from Optional parameter: The number of users to be skipped
155
+ # from the response. Defaults to 0. Must be bigger than or equal to 0. This
156
+ # parameter must be string represetation of an integer like "1".
100
157
  # @return ActionsResponse response from the API call
101
158
  def get_actions(type = nil,
102
159
  user_id = nil,
@@ -104,86 +161,128 @@ module SuggestGrid
104
161
  older_than = nil,
105
162
  size = nil,
106
163
  from = nil)
107
-
108
- # prepare query url
164
+ # Prepare query url.
109
165
  _query_builder = Configuration.base_uri.dup
110
166
  _query_builder << '/v1/actions'
111
- _query_builder = APIHelper.append_url_with_query_parameters _query_builder, {
112
- 'type' => type,
113
- 'user_id' => user_id,
114
- 'item_id' => item_id,
115
- 'older_than' => older_than,
116
- 'size' => size,
117
- 'from' => from
118
- }, array_serialization: Configuration.array_serialization
167
+ _query_builder = APIHelper.append_url_with_query_parameters(
168
+ _query_builder,
169
+ {
170
+ 'type' => type,
171
+ 'user_id' => user_id,
172
+ 'item_id' => item_id,
173
+ 'older_than' => older_than,
174
+ 'size' => size,
175
+ 'from' => from
176
+ },
177
+ array_serialization: Configuration.array_serialization
178
+ )
119
179
  _query_url = APIHelper.clean_url _query_builder
120
180
 
121
- # prepare headers
181
+ # Prepare headers.
122
182
  _headers = {
123
183
  'accept' => 'application/json'
124
184
  }
125
185
 
126
- # prepare and execute HttpRequest
127
- _request = @http_client.get _query_url, headers: _headers
186
+ # Prepare and execute HttpRequest.
187
+ _request = @http_client.get(
188
+ _query_url,
189
+ headers: _headers
190
+ )
128
191
  BasicAuth.apply(_request)
129
192
  _context = execute_request(_request)
130
193
 
131
- # validate response against endpoint and global error codes
132
- if _context.response.status_code == 0
133
- raise ErrorResponseErrorException.new 'Unexpected internal error.', _context
194
+ # Validate response against endpoint and global error codes.
195
+ unless _context.response.status_code.between?(200, 208)
196
+ raise ErrorResponse.new(
197
+ 'Unexpected internal error.',
198
+ _context
199
+ )
134
200
  end
135
201
  validate_response(_context)
136
202
 
137
- # return appropriate response type
203
+ # Return appropriate response type.
138
204
  decoded = APIHelper.json_deserialize(_context.response.raw_body)
139
- return ActionsResponse.from_hash(decoded)
205
+ ActionsResponse.from_hash(decoded)
140
206
  end
141
207
 
142
- # Delete Actions
143
- # @param [String] type Required parameter: Delete actions of a type. This parameter and at least one other parameter is required.
208
+ # Warning: Please use get actions with the exact parameters first to inspect
209
+ # the actions to be deleted.
210
+ # * Type must be provided.
211
+ # * If user id is provided, all actions of the user will be deleted.
212
+ # * If item id is provided, all actions on the item will be deleted.
213
+ # * If older than is provided, all actions older than the timestamp or the
214
+ # duration will be deleted.
215
+ # * If a number of these parameters are provided, the intersection of these
216
+ # parameters will be deleted.
217
+ # * In addition to a type, at least one of these parameters must be
218
+ # provided. In order to delete all the actions of a type, delete the type.
219
+ # @param [String] type Required parameter: Delete actions of a type. This
220
+ # parameter and at least one other parameter is required.
144
221
  # @param [String] user_id Optional parameter: Delete actions of a user id.
145
- # @param [String] item_id Optional parameter: Delete actions of an item id.
146
- # @param [String] older_than Optional parameter: Delete actions older than the given duration, or the given time number. Could be a ISO 8601 duration, or a Unix time number. Specifications are available at https://en.wikipedia.org/wiki/ISO_8601#Durations, or https://en.wikipedia.org/wiki/Unix_time.
222
+ # @param [String] item_id Optional parameter: Delete actions of an item
223
+ # id.
224
+ # @param [String] older_than Optional parameter: Delete actions older than
225
+ # the given duration, or the given time number. Could be a ISO 8601
226
+ # duration, or a Unix time number. Specifications are available at
227
+ # https://en.wikipedia.org/wiki/ISO_8601#Durations, or
228
+ # https://en.wikipedia.org/wiki/Unix_time.
147
229
  # @return MessageResponse response from the API call
148
230
  def delete_actions(type,
149
231
  user_id = nil,
150
232
  item_id = nil,
151
233
  older_than = nil)
152
-
153
- # prepare query url
234
+ # Prepare query url.
154
235
  _query_builder = Configuration.base_uri.dup
155
236
  _query_builder << '/v1/actions'
156
- _query_builder = APIHelper.append_url_with_query_parameters _query_builder, {
157
- 'type' => type,
158
- 'user_id' => user_id,
159
- 'item_id' => item_id,
160
- 'older_than' => older_than
161
- }, array_serialization: Configuration.array_serialization
237
+ _query_builder = APIHelper.append_url_with_query_parameters(
238
+ _query_builder,
239
+ {
240
+ 'type' => type,
241
+ 'user_id' => user_id,
242
+ 'item_id' => item_id,
243
+ 'older_than' => older_than
244
+ },
245
+ array_serialization: Configuration.array_serialization
246
+ )
162
247
  _query_url = APIHelper.clean_url _query_builder
163
248
 
164
- # prepare headers
249
+ # Prepare headers.
165
250
  _headers = {
166
251
  'accept' => 'application/json'
167
252
  }
168
253
 
169
- # prepare and execute HttpRequest
170
- _request = @http_client.delete _query_url, headers: _headers
254
+ # Prepare and execute HttpRequest.
255
+ _request = @http_client.delete(
256
+ _query_url,
257
+ headers: _headers
258
+ )
171
259
  BasicAuth.apply(_request)
172
260
  _context = execute_request(_request)
173
261
 
174
- # validate response against endpoint and global error codes
262
+ # Validate response against endpoint and global error codes.
175
263
  if _context.response.status_code == 400
176
- raise ErrorResponseErrorException.new 'Required user id or item id parameters are missing.', _context
264
+ raise ErrorResponse.new(
265
+ 'Required user id or item id parameters are missing.',
266
+ _context
267
+ )
177
268
  elsif _context.response.status_code == 422
178
- raise ErrorResponseErrorException.new 'No query parameter (user id, item id, or older than) is given. qIn order to delete all actionsdelete the type.', _context
179
- elsif !_context.response.status_code.between?(200, 208)
180
- raise ErrorResponseErrorException.new 'Unexpected internal error.', _context
269
+ raise ErrorResponse.new(
270
+ 'No query parameter (user id, item id, or older than) is given.' \
271
+ ' qIn order to delete all actionsdelete the type.',
272
+ _context
273
+ )
274
+ end
275
+ unless _context.response.status_code.between?(200, 208)
276
+ raise ErrorResponse.new(
277
+ 'Unexpected internal error.',
278
+ _context
279
+ )
181
280
  end
182
281
  validate_response(_context)
183
282
 
184
- # return appropriate response type
283
+ # Return appropriate response type.
185
284
  decoded = APIHelper.json_deserialize(_context.response.raw_body)
186
- return MessageResponse.from_hash(decoded)
285
+ MessageResponse.from_hash(decoded)
187
286
  end
188
287
  end
189
288
  end
@@ -1,24 +1,24 @@
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
+ # Base controller.
4
6
  class BaseController
5
7
  attr_accessor :http_client, :http_call_back
6
8
 
7
- @@http_client = FaradayClient.new
8
-
9
- @@global_headers = {
10
- 'user-agent' => 'SUGGESTGRID'
11
- }
12
-
13
9
  def initialize(http_client: nil, http_call_back: nil)
14
- @http_client = http_client ||= @@http_client
10
+ @http_client = http_client || FaradayClient.new
15
11
  @http_call_back = http_call_back
12
+
13
+ @global_headers = {
14
+ 'user-agent' => 'SUGGESTGRID'
15
+ }
16
16
  end
17
17
 
18
18
  def validate_parameters(args)
19
19
  args.each do |_name, value|
20
20
  if value.nil?
21
- raise ArgumentError.new 'Required parameter #{name} cannot be nil.'
21
+ raise ArgumentError, "Required parameter #{_name} cannot be nil."
22
22
  end
23
23
  end
24
24
  end
@@ -27,20 +27,23 @@ module SuggestGrid
27
27
  @http_call_back.on_before_request(request) if @http_call_back
28
28
 
29
29
  APIHelper.clean_hash(request.headers)
30
- request.headers = @@global_headers.clone.merge(request.headers)
30
+ request.headers = @global_headers.clone.merge(request.headers)
31
31
 
32
- response = binary ? @http_client.execute_as_binary(request) : @http_client.execute_as_string(request)
32
+ response = if binary
33
+ @http_client.execute_as_binary(request)
34
+ else
35
+ @http_client.execute_as_string(request)
36
+ end
33
37
  context = HttpContext.new(request, response)
34
38
 
35
39
  @http_call_back.on_after_response(context) if @http_call_back
36
40
 
37
- return context
41
+ context
38
42
  end
39
43
 
40
44
  def validate_response(context)
41
- if !context.response.status_code.between?(200, 208) #[200,208] = HTTP OK
42
- raise APIException.new 'HTTP Response Not OK', context
43
- end
45
+ raise APIException.new 'HTTP Response Not OK', context unless
46
+ context.response.status_code.between?(200, 208) # [200,208] = HTTP OK
44
47
  end
45
48
  end
46
49
  end