suggestgrid 0.1.27 → 0.1.30

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/lib/suggest_grid/api_helper.rb +6 -0
  4. data/lib/suggest_grid/configuration.rb +1 -0
  5. data/lib/suggest_grid/controllers/action_controller.rb +94 -142
  6. data/lib/suggest_grid/controllers/base_controller.rb +3 -2
  7. data/lib/suggest_grid/controllers/metadata_controller.rb +182 -330
  8. data/lib/suggest_grid/controllers/recommendation_controller.rb +18 -42
  9. data/lib/suggest_grid/controllers/similarity_controller.rb +18 -42
  10. data/lib/suggest_grid/controllers/type_controller.rb +76 -140
  11. data/lib/suggest_grid/exceptions/delete_error_response_exception.rb +7 -7
  12. data/lib/suggest_grid/exceptions/detailed_error_response_exception.rb +1 -1
  13. data/lib/suggest_grid/exceptions/error_response_exception.rb +1 -1
  14. data/lib/suggest_grid/exceptions/limit_exceeded_error_response_exception.rb +3 -3
  15. data/lib/suggest_grid/http/faraday_client.rb +3 -1
  16. data/lib/suggest_grid/http/http_client.rb +4 -2
  17. data/lib/suggest_grid/models/action.rb +19 -2
  18. data/lib/suggest_grid/models/actions_response.rb +10 -2
  19. data/lib/suggest_grid/models/base_model.rb +17 -0
  20. data/lib/suggest_grid/models/bulk_post_error.rb +10 -2
  21. data/lib/suggest_grid/models/bulk_post_response.rb +10 -2
  22. data/lib/suggest_grid/models/delete_success_response.rb +16 -8
  23. data/lib/suggest_grid/models/get_recommended_items_body.rb +16 -8
  24. data/lib/suggest_grid/models/get_recommended_users_body.rb +16 -8
  25. data/lib/suggest_grid/models/get_similar_items_body.rb +15 -7
  26. data/lib/suggest_grid/models/get_similar_users_body.rb +15 -7
  27. data/lib/suggest_grid/models/get_type_response.rb +10 -2
  28. data/lib/suggest_grid/models/get_types_response.rb +8 -9
  29. data/lib/suggest_grid/models/items_response.rb +10 -2
  30. data/lib/suggest_grid/models/message_response.rb +10 -2
  31. data/lib/suggest_grid/models/metadata.rb +19 -10
  32. data/lib/suggest_grid/models/type_request_body.rb +11 -5
  33. data/lib/suggest_grid/models/users_response.rb +10 -2
  34. data/lib/suggest_grid.rb +2 -0
  35. data/spec/swagger.yaml +122 -194
  36. metadata +21 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4d16c4bda91e756fab948c163a5eca7f9be6b13b
4
- data.tar.gz: 5b7380e60f648cb6cb4ba6490a651be6110966f2
3
+ metadata.gz: 0a511c55944959fd302cda98f0de49a47b7e2fc0
4
+ data.tar.gz: c07cb656d5bbd87b4ec356c49acea5731381f8b5
5
5
  SHA512:
6
- metadata.gz: 9b823a73f7c09feab64633bda1001e68fcfe7c95923a39bf7753b2402124a88673d20ac01e29c9c775a13a72aaa4d1e75f381e988e6cf7a0f3b4a8b650359f01
7
- data.tar.gz: 2ddf6fe0bdc8da3b348c94fe4845ff188ebbaad1e4af15f7019bae5a781321e69e94ba66aba05b47128fde2c444a1a6a1af45c884e724fcb148b512467653bbc
6
+ metadata.gz: 9c8585d8f20f804af0b04d49e36f03f88529983ae0f97f147acc9fbeda9d85064c64b65285b4648cf16b0a93e7aba2606ce84b1511164a30fdd983759fa50b15
7
+ data.tar.gz: ecd0386e2c43a5ae9f76a79ee0a6a7b354918baf5c34b23986578b1b0b4ff364a5f75cee958f1f09178bfd0662ec28e31a7c373415f7d0e4afaac81b6da53747
data/README.md CHANGED
@@ -23,7 +23,7 @@ Let's implement this feature in five minutes with SuggestGrid!
23
23
  We are beginning the development by adding the client as a dependency.
24
24
 
25
25
  ```ruby
26
- gem 'suggest_grid', git: 'https://github.com/suggestgrid/suggestgrid-ruby.git'
26
+ gem 'suggestgrid'
27
27
  ```
28
28
 
29
29
 
@@ -94,6 +94,12 @@ module SuggestGrid
94
94
  end
95
95
  end
96
96
 
97
+ # Removes elements with empty values from a hash.
98
+ # @param [Hash] The hash to clean.
99
+ def self.clean_hash(hash)
100
+ hash.delete_if { |key, value| value.to_s.strip.empty? }
101
+ end
102
+
97
103
  # Form encodes a hash of parameters.
98
104
  # @param [Hash] The hash of parameters to encode.
99
105
  # @return [Hash] A hash with the same parameters form encoded.
@@ -1,6 +1,7 @@
1
1
  # This file was automatically generated for SuggestGrid by APIMATIC v2.0 ( https://apimatic.io ).
2
2
 
3
3
  module SuggestGrid
4
+
4
5
  class Configuration
5
6
  # The base Uri for API calls
6
7
  @base_uri = 'https://example.com/api'
@@ -8,145 +8,114 @@ module SuggestGrid
8
8
  @@instance
9
9
  end
10
10
 
11
- # Get Actions
12
- # @param [String] type Optional parameter: The type of the actions.
13
- # @param [String] user_id Optional parameter: The user id of the actions.
14
- # @param [String] item_id Optional parameter: The item id of the actions.
15
- # @param [String] older_than Optional parameter: Maxium timestamp of the actions. Valid times are 1s, 1m, 1h, 1d, 1M, 1y, or unix timestamp (like 1443798195).
16
- # @param [Integer] 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".
17
- # @param [Integer] from Optional parameter: The number of users to be skipped for response. Defaults to 0. Must be bigger than or equal to 0. This parameter must be string represetation of an integer like "1".
18
- # @return ActionsResponse response from the API call
19
- def get_actions(type = nil,
20
- user_id = nil,
21
- item_id = nil,
22
- older_than = nil,
23
- size = nil,
24
- from = nil)
11
+ # Post an Action
12
+ # @param [Action] action Required parameter: The action to be posted.
13
+ # @return MessageResponse response from the API call
14
+ def post_action(action)
25
15
 
26
- # the base uri for api requests
16
+ # prepare query url
27
17
  _query_builder = Configuration.base_uri.dup
28
-
29
- # prepare query string for API call
30
18
  _query_builder << '/v1/actions'
31
-
32
- # process optional query parameters
33
- _query_builder = APIHelper.append_url_with_query_parameters _query_builder, {
34
- 'type' => type,
35
- 'user_id' => user_id,
36
- 'item_id' => item_id,
37
- 'older_than' => older_than,
38
- 'size' => size,
39
- 'from' => from
40
- }
41
-
42
- # validate and preprocess url
43
19
  _query_url = APIHelper.clean_url _query_builder
44
20
 
45
21
  # prepare headers
46
22
  _headers = {
47
- 'accept' => 'application/json'
23
+ 'accept' => 'application/json',
24
+ 'content-type' => 'application/json; charset=utf-8'
48
25
  }
49
26
 
50
- # create the HttpRequest object for the call
51
- _request = @http_client.get _query_url, headers: _headers
52
-
53
- # apply authentication
27
+ # prepare and execute HttpRequest
28
+ _request = @http_client.post _query_url, headers: _headers, parameters: action.to_json
54
29
  BasicAuth.apply(_request)
55
-
56
- # execute the request
57
30
  _context = execute_request(_request)
58
31
 
59
- # endpoint error handling using HTTP status codes.
60
- if _context.response.status_code == 429
61
- raise ErrorResponseException.new '429 - Too many requests.', _context
62
- elsif _context.response.status_code == 500
63
- raise APIException.new '500 - Unexpected internal error.', _context
32
+ # validate response against endpoint and global error codes
33
+ if _context.response.status_code == 400
34
+ raise ErrorResponseException.new 'Required user id or item id parameters are missing from the request.', _context
35
+ elsif _context.response.status_code == 402
36
+ raise ErrorResponseException.new 'Action limit exceeded.', _context
37
+ elsif _context.response.status_code == 404
38
+ raise ErrorResponseException.new 'Action type does not exists.', _context
39
+ elsif !_context.response.status_code.between?(200, 208)
40
+ raise ErrorResponseException.new 'Unexpected internal error.', _context
64
41
  end
65
-
66
- # global error handling using HTTP status codes.
67
42
  validate_response(_context)
68
43
 
69
44
  # return appropriate response type
70
45
  decoded = APIHelper.json_deserialize(_context.response.raw_body)
71
- return ActionsResponse.from_hash(decoded)
46
+ return MessageResponse.from_hash(decoded)
72
47
  end
73
48
 
74
- # Post an Action
75
- # @param [Action] action Required parameter: The action to be posted.
76
- # @return MessageResponse response from the API call
77
- def post_action(action)
49
+ # Post Bulk Actions
50
+ # @param [Collection] actions Required parameter: List of actions to be posted.
51
+ # @return BulkPostResponse response from the API call
52
+ def post_bulk_actions(actions)
53
+ body = ''
54
+ actions.each do |action|
55
+ body += "#{action.to_json}\n"
56
+ end
78
57
 
79
- # the base uri for api requests
58
+ # prepare query url
80
59
  _query_builder = Configuration.base_uri.dup
81
-
82
- # prepare query string for API call
83
- _query_builder << '/v1/actions'
84
-
85
- # validate and preprocess url
60
+ _query_builder << '/v1/actions/_bulk'
86
61
  _query_url = APIHelper.clean_url _query_builder
87
62
 
88
63
  # prepare headers
89
64
  _headers = {
90
65
  'accept' => 'application/json',
91
- 'content-type' => 'application/json; charset=utf-8'
66
+ 'content-type' => 'text/plain; charset=utf-8'
92
67
  }
93
68
 
94
- # create the HttpRequest object for the call
95
- _request = @http_client.post _query_url, headers: _headers, parameters: action.to_json
96
-
97
- # apply authentication
69
+ # prepare and execute HttpRequest
70
+ _request = @http_client.post _query_url, headers: _headers, parameters: body
98
71
  BasicAuth.apply(_request)
99
-
100
- # execute the request
101
72
  _context = execute_request(_request)
102
73
 
103
- # endpoint error handling using HTTP status codes.
74
+ # validate response against endpoint and global error codes
104
75
  if _context.response.status_code == 400
105
- raise ErrorResponseException.new '400 - Required `user_id` or `item_id` parameters are missing from the request body.', _context
76
+ raise ErrorResponseException.new 'Body is missing.', _context
106
77
  elsif _context.response.status_code == 402
107
- raise ErrorResponseException.new '402 - Action limit exceeded.', _context
78
+ raise ErrorResponseException.new 'Action limit exceeded.', _context
108
79
  elsif _context.response.status_code == 404
109
- raise ErrorResponseException.new '404 - Type does not exists.', _context
110
- elsif _context.response.status_code == 429
111
- raise ErrorResponseException.new '429 - Too many requests.', _context
112
- elsif _context.response.status_code == 500
113
- raise APIException.new '500 - Unexpected internal error.', _context
80
+ raise ErrorResponseException.new 'Action type does not exists.', _context
81
+ elsif _context.response.status_code == 413
82
+ raise ErrorResponseException.new 'Bulk request maximum line count exceeded.', _context
83
+ elsif !_context.response.status_code.between?(200, 208)
84
+ raise ErrorResponseException.new 'Unexpected internal error.', _context
114
85
  end
115
-
116
- # global error handling using HTTP status codes.
117
86
  validate_response(_context)
118
87
 
119
88
  # return appropriate response type
120
89
  decoded = APIHelper.json_deserialize(_context.response.raw_body)
121
- return MessageResponse.from_hash(decoded)
90
+ return BulkPostResponse.from_hash(decoded)
122
91
  end
123
92
 
124
- # Delete Actions
93
+ # Get Actions
125
94
  # @param [String] type Optional parameter: The type of the actions.
126
95
  # @param [String] user_id Optional parameter: The user id of the actions.
127
96
  # @param [String] item_id Optional parameter: The item id of the actions.
128
- # @param [String] older_than Optional parameter: Delete all actions of a type older than the given timestamp or time. Valid times are 1s, 1m, 1h, 1d, 1M, 1y, or unix timestamp (like 1443798195).
129
- # @return DeleteSuccessResponse response from the API call
130
- def delete_actions(type = nil,
131
- user_id = nil,
132
- item_id = nil,
133
- older_than = nil)
97
+ # @param [String] older_than Optional parameter: Maxium timestamp of the actions. Valid times are in form of 1s, 1m, 1h, 1d, 1M, 1y, where 1 can be any integer, or a UNIX timestamp like 1443798195.
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".
100
+ # @return ActionsResponse response from the API call
101
+ def get_actions(type = nil,
102
+ user_id = nil,
103
+ item_id = nil,
104
+ older_than = nil,
105
+ size = nil,
106
+ from = nil)
134
107
 
135
- # the base uri for api requests
108
+ # prepare query url
136
109
  _query_builder = Configuration.base_uri.dup
137
-
138
- # prepare query string for API call
139
110
  _query_builder << '/v1/actions'
140
-
141
- # process optional query parameters
142
111
  _query_builder = APIHelper.append_url_with_query_parameters _query_builder, {
143
112
  'type' => type,
144
113
  'user_id' => user_id,
145
114
  'item_id' => item_id,
146
- 'older_than' => older_than
115
+ 'older_than' => older_than,
116
+ 'size' => size,
117
+ 'from' => from
147
118
  }
148
-
149
- # validate and preprocess url
150
119
  _query_url = APIHelper.clean_url _query_builder
151
120
 
152
121
  # prepare headers
@@ -154,88 +123,71 @@ module SuggestGrid
154
123
  'accept' => 'application/json'
155
124
  }
156
125
 
157
- # create the HttpRequest object for the call
158
- _request = @http_client.delete _query_url, headers: _headers
159
-
160
- # apply authentication
126
+ # prepare and execute HttpRequest
127
+ _request = @http_client.get _query_url, headers: _headers
161
128
  BasicAuth.apply(_request)
162
-
163
- # execute the request
164
129
  _context = execute_request(_request)
165
130
 
166
- # endpoint error handling using HTTP status codes.
167
- if _context.response.status_code == 400
168
- raise ErrorResponseException.new '400 - Required `user_id` or `item_id` parameters are missing from the request body.', _context
169
- elsif _context.response.status_code == 404
170
- raise DeleteErrorResponseException.new '404 - Delete actions not found.', _context
171
- elsif _context.response.status_code == 422
172
- raise ErrorResponseException.new '422 - No query parameter (`user_id`, `item_id`, or `older_than`) is given. In order to delete all actionsdelete the type.', _context
173
- elsif _context.response.status_code == 429
174
- raise ErrorResponseException.new '429 - Too many requests.', _context
175
- elsif _context.response.status_code == 505
176
- raise ErrorResponseException.new '505 - Request timed out.', _context
177
- elsif _context.response.status_code == 500
178
- raise APIException.new '500 - Unexpected internal error.', _context
131
+ # validate response against endpoint and global error codes
132
+ if _context.response.status_code == 0
133
+ raise ErrorResponseException.new 'Unexpected internal error.', _context
179
134
  end
180
-
181
- # global error handling using HTTP status codes.
182
135
  validate_response(_context)
183
136
 
184
137
  # return appropriate response type
185
138
  decoded = APIHelper.json_deserialize(_context.response.raw_body)
186
- return DeleteSuccessResponse.from_hash(decoded)
139
+ return ActionsResponse.from_hash(decoded)
187
140
  end
188
141
 
189
- # Post Bulk Actions
190
- # @param [Collection] actions Required parameter: List of actions to be posted.
191
- # @return BulkPostResponse response from the API call
192
- def post_bulk_actions(actions)
193
- body = ''
194
- actions.each do |action|
195
- body += "#{action.to_json}\n"
196
- end
142
+ # Delete Actions
143
+ # @param [String] type Optional parameter: The type of the actions.
144
+ # @param [String] user_id Optional parameter: The user id of the actions.
145
+ # @param [String] item_id Optional parameter: The item id of the actions.
146
+ # @param [String] older_than Optional parameter: Delete all actions of a type older than the given timestamp or time. Valid times are in form of 1s, 1m, 1h, 1d, 1M, 1y, where 1 can be any integer, or a UNIX timestamp like 1443798195.
147
+ # @return DeleteSuccessResponse response from the API call
148
+ def delete_actions(type = nil,
149
+ user_id = nil,
150
+ item_id = nil,
151
+ older_than = nil)
197
152
 
198
- # the base uri for api requests
153
+ # prepare query url
199
154
  _query_builder = Configuration.base_uri.dup
200
-
201
- # prepare query string for API call
202
- _query_builder << '/v1/actions/_bulk'
203
-
204
- # validate and preprocess url
155
+ _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
+ }
205
162
  _query_url = APIHelper.clean_url _query_builder
206
163
 
207
164
  # prepare headers
208
165
  _headers = {
209
- 'accept' => 'application/json',
210
- 'content-type' => 'text/plain; charset=utf-8'
166
+ 'accept' => 'application/json'
211
167
  }
212
168
 
213
- # create the HttpRequest object for the call
214
- _request = @http_client.post _query_url, headers: _headers, parameters: actions
215
-
216
- # apply authentication
169
+ # prepare and execute HttpRequest
170
+ _request = @http_client.delete _query_url, headers: _headers
217
171
  BasicAuth.apply(_request)
218
-
219
- # execute the request
220
172
  _context = execute_request(_request)
221
173
 
222
- # endpoint error handling using HTTP status codes.
174
+ # validate response against endpoint and global error codes
223
175
  if _context.response.status_code == 400
224
- raise ErrorResponseException.new '400 - Body is missing.', _context
225
- elsif _context.response.status_code == 402
226
- raise ErrorResponseException.new '402 - Action limit exceeded.', _context
227
- elsif _context.response.status_code == 429
228
- raise ErrorResponseException.new '429 - Too many requests.', _context
229
- elsif _context.response.status_code == 500
230
- raise APIException.new '500 - Unexpected internal error.', _context
176
+ raise ErrorResponseException.new 'Required user id or item id parameters are missing.', _context
177
+ elsif _context.response.status_code == 404
178
+ raise DeleteErrorResponseException.new 'Delete actions not found.', _context
179
+ elsif _context.response.status_code == 422
180
+ raise ErrorResponseException.new 'No query parameter (user id, item id, or older than) is given. qIn order to delete all actionsdelete the type.', _context
181
+ elsif _context.response.status_code == 505
182
+ raise ErrorResponseException.new 'Request timed out.', _context
183
+ elsif !_context.response.status_code.between?(200, 208)
184
+ raise ErrorResponseException.new 'Unexpected internal error.', _context
231
185
  end
232
-
233
- # global error handling using HTTP status codes.
234
186
  validate_response(_context)
235
187
 
236
188
  # return appropriate response type
237
189
  decoded = APIHelper.json_deserialize(_context.response.raw_body)
238
- return BulkPostResponse.from_hash(decoded)
190
+ return DeleteSuccessResponse.from_hash(decoded)
239
191
  end
240
192
  end
241
193
  end
@@ -18,14 +18,15 @@ module SuggestGrid
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.new 'Required parameter #{name} cannot be nil.'
22
22
  end
23
23
  end
24
24
  end
25
25
 
26
- def execute_request(request, binary: false)
26
+ def execute_request(request, binary: false)
27
27
  @http_call_back.on_before_request(request) if @http_call_back
28
28
 
29
+ APIHelper.clean_hash(request.headers)
29
30
  request.headers = @@global_headers.clone.merge(request.headers)
30
31
 
31
32
  response = binary ? @http_client.execute_as_binary(request) : @http_client.execute_as_string(request)