artikcloud 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (193) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +4 -0
  3. data/Gemfile.lock +65 -0
  4. data/LICENSE +202 -0
  5. data/README.md +230 -0
  6. data/artikcloud.gemspec +32 -0
  7. data/docs/AckEnvelope.md +8 -0
  8. data/docs/Acknowledgement.md +11 -0
  9. data/docs/ActionDetails.md +9 -0
  10. data/docs/ActionDetailsArray.md +8 -0
  11. data/docs/ActionIn.md +13 -0
  12. data/docs/ActionOut.md +12 -0
  13. data/docs/AggregateData.md +13 -0
  14. data/docs/AggregatesHistogramData.md +14 -0
  15. data/docs/AggregatesHistogramResponse.md +14 -0
  16. data/docs/AggregatesResponse.md +13 -0
  17. data/docs/AppProperties.md +10 -0
  18. data/docs/CheckTokenMessage.md +8 -0
  19. data/docs/CheckTokenResponse.md +8 -0
  20. data/docs/Device.md +21 -0
  21. data/docs/DeviceArray.md +8 -0
  22. data/docs/DeviceEnvelope.md +8 -0
  23. data/docs/DeviceRegCompleteRequest.md +8 -0
  24. data/docs/DeviceRegConfirmUserRequest.md +10 -0
  25. data/docs/DeviceRegConfirmUserResponse.md +8 -0
  26. data/docs/DeviceRegConfirmUserResponseEnvelope.md +8 -0
  27. data/docs/DeviceRegStatusResponse.md +9 -0
  28. data/docs/DeviceRegStatusResponseEnvelope.md +8 -0
  29. data/docs/DeviceToken.md +11 -0
  30. data/docs/DeviceTokenEnvelope.md +8 -0
  31. data/docs/DeviceType.md +25 -0
  32. data/docs/DeviceTypeArray.md +8 -0
  33. data/docs/DeviceTypeEnvelope.md +8 -0
  34. data/docs/DeviceTypesApi.md +284 -0
  35. data/docs/DeviceTypesEnvelope.md +11 -0
  36. data/docs/DevicesApi.md +382 -0
  37. data/docs/DevicesEnvelope.md +11 -0
  38. data/docs/ErrorEnvelope.md +8 -0
  39. data/docs/ExportApi.md +225 -0
  40. data/docs/ExportData.md +14 -0
  41. data/docs/ExportDataArray.md +8 -0
  42. data/docs/ExportHistoryResponse.md +11 -0
  43. data/docs/ExportNormalizedMessagesResponse.md +20 -0
  44. data/docs/ExportRequest.md +15 -0
  45. data/docs/ExportRequestData.md +18 -0
  46. data/docs/ExportRequestInfo.md +17 -0
  47. data/docs/ExportRequestResponse.md +8 -0
  48. data/docs/ExportResponse.md +18 -0
  49. data/docs/ExportStatusResponse.md +12 -0
  50. data/docs/FieldPath.md +8 -0
  51. data/docs/FieldPresence.md +8 -0
  52. data/docs/FieldPresenceEnvelope.md +14 -0
  53. data/docs/FieldsActions.md +9 -0
  54. data/docs/ManifestProperties.md +8 -0
  55. data/docs/ManifestPropertiesEnvelope.md +8 -0
  56. data/docs/ManifestVersions.md +8 -0
  57. data/docs/ManifestVersionsEnvelope.md +8 -0
  58. data/docs/MessageAction.md +12 -0
  59. data/docs/MessageID.md +8 -0
  60. data/docs/MessageIDEnvelope.md +8 -0
  61. data/docs/MessageIn.md +13 -0
  62. data/docs/MessageOut.md +12 -0
  63. data/docs/MessagesApi.md +382 -0
  64. data/docs/NonEmptyString.md +8 -0
  65. data/docs/NormalizedMessage.md +15 -0
  66. data/docs/NormalizedMessagesEnvelope.md +17 -0
  67. data/docs/OutputRule.md +21 -0
  68. data/docs/PropertiesEnvelope.md +8 -0
  69. data/docs/RefreshTokenResponse.md +11 -0
  70. data/docs/RegisterMessage.md +12 -0
  71. data/docs/RegistrationsApi.md +167 -0
  72. data/docs/RuleArray.md +8 -0
  73. data/docs/RuleCreationInfo.md +11 -0
  74. data/docs/RuleEnvelope.md +8 -0
  75. data/docs/RuleError.md +11 -0
  76. data/docs/RuleUpdateInfo.md +11 -0
  77. data/docs/RuleWarningOutput.md +9 -0
  78. data/docs/RulesApi.md +226 -0
  79. data/docs/RulesEnvelope.md +11 -0
  80. data/docs/Tag.md +9 -0
  81. data/docs/TagArray.md +8 -0
  82. data/docs/TagsApi.md +169 -0
  83. data/docs/TagsEnvelope.md +8 -0
  84. data/docs/Token.md +11 -0
  85. data/docs/TokenRequest.md +8 -0
  86. data/docs/TokenResponse.md +8 -0
  87. data/docs/TokensApi.md +117 -0
  88. data/docs/UnregisterDeviceResponse.md +18 -0
  89. data/docs/UnregisterDeviceResponseEnvelope.md +8 -0
  90. data/docs/User.md +14 -0
  91. data/docs/UserEnvelope.md +8 -0
  92. data/docs/UsersApi.md +474 -0
  93. data/docs/WebSocketError.md +10 -0
  94. data/git_push.sh +52 -0
  95. data/lib/artikcloud/api/device_types_api.rb +340 -0
  96. data/lib/artikcloud/api/devices_api.rb +450 -0
  97. data/lib/artikcloud/api/export_api.rb +269 -0
  98. data/lib/artikcloud/api/messages_api.rb +468 -0
  99. data/lib/artikcloud/api/registrations_api.rb +205 -0
  100. data/lib/artikcloud/api/rules_api.rb +276 -0
  101. data/lib/artikcloud/api/tags_api.rb +209 -0
  102. data/lib/artikcloud/api/tokens_api.rb +152 -0
  103. data/lib/artikcloud/api/users_api.rb +552 -0
  104. data/lib/artikcloud/api_client.rb +336 -0
  105. data/lib/artikcloud/api_error.rb +38 -0
  106. data/lib/artikcloud/configuration.rb +170 -0
  107. data/lib/artikcloud/models/ack_envelope.rb +164 -0
  108. data/lib/artikcloud/models/acknowledgement.rb +198 -0
  109. data/lib/artikcloud/models/action_details.rb +178 -0
  110. data/lib/artikcloud/models/action_details_array.rb +166 -0
  111. data/lib/artikcloud/models/action_in.rb +221 -0
  112. data/lib/artikcloud/models/action_out.rb +209 -0
  113. data/lib/artikcloud/models/aggregate_data.rb +214 -0
  114. data/lib/artikcloud/models/aggregates_histogram_data.rb +224 -0
  115. data/lib/artikcloud/models/aggregates_histogram_response.rb +226 -0
  116. data/lib/artikcloud/models/aggregates_response.rb +216 -0
  117. data/lib/artikcloud/models/app_properties.rb +184 -0
  118. data/lib/artikcloud/models/check_token_message.rb +164 -0
  119. data/lib/artikcloud/models/check_token_response.rb +164 -0
  120. data/lib/artikcloud/models/device.rb +310 -0
  121. data/lib/artikcloud/models/device_array.rb +166 -0
  122. data/lib/artikcloud/models/device_envelope.rb +164 -0
  123. data/lib/artikcloud/models/device_reg_complete_request.rb +165 -0
  124. data/lib/artikcloud/models/device_reg_confirm_user_request.rb +187 -0
  125. data/lib/artikcloud/models/device_reg_confirm_user_response.rb +165 -0
  126. data/lib/artikcloud/models/device_reg_confirm_user_response_envelope.rb +164 -0
  127. data/lib/artikcloud/models/device_reg_status_response.rb +176 -0
  128. data/lib/artikcloud/models/device_reg_status_response_envelope.rb +164 -0
  129. data/lib/artikcloud/models/device_token.rb +194 -0
  130. data/lib/artikcloud/models/device_token_envelope.rb +164 -0
  131. data/lib/artikcloud/models/device_type.rb +353 -0
  132. data/lib/artikcloud/models/device_type_array.rb +166 -0
  133. data/lib/artikcloud/models/device_type_envelope.rb +164 -0
  134. data/lib/artikcloud/models/device_types_envelope.rb +194 -0
  135. data/lib/artikcloud/models/devices_envelope.rb +194 -0
  136. data/lib/artikcloud/models/error_envelope.rb +165 -0
  137. data/lib/artikcloud/models/export_data.rb +225 -0
  138. data/lib/artikcloud/models/export_data_array.rb +166 -0
  139. data/lib/artikcloud/models/export_history_response.rb +194 -0
  140. data/lib/artikcloud/models/export_normalized_messages_response.rb +284 -0
  141. data/lib/artikcloud/models/export_request.rb +234 -0
  142. data/lib/artikcloud/models/export_request_data.rb +275 -0
  143. data/lib/artikcloud/models/export_request_info.rb +264 -0
  144. data/lib/artikcloud/models/export_request_response.rb +164 -0
  145. data/lib/artikcloud/models/export_response.rb +275 -0
  146. data/lib/artikcloud/models/export_status_response.rb +205 -0
  147. data/lib/artikcloud/models/field_path.rb +166 -0
  148. data/lib/artikcloud/models/field_presence.rb +164 -0
  149. data/lib/artikcloud/models/field_presence_envelope.rb +226 -0
  150. data/lib/artikcloud/models/fields_actions.rb +180 -0
  151. data/lib/artikcloud/models/manifest_properties.rb +164 -0
  152. data/lib/artikcloud/models/manifest_properties_envelope.rb +164 -0
  153. data/lib/artikcloud/models/manifest_versions.rb +166 -0
  154. data/lib/artikcloud/models/manifest_versions_envelope.rb +164 -0
  155. data/lib/artikcloud/models/message_action.rb +210 -0
  156. data/lib/artikcloud/models/message_id.rb +165 -0
  157. data/lib/artikcloud/models/message_id_envelope.rb +164 -0
  158. data/lib/artikcloud/models/message_in.rb +224 -0
  159. data/lib/artikcloud/models/message_out.rb +209 -0
  160. data/lib/artikcloud/models/non_empty_string.rb +164 -0
  161. data/lib/artikcloud/models/normalized_message.rb +236 -0
  162. data/lib/artikcloud/models/normalized_messages_envelope.rb +256 -0
  163. data/lib/artikcloud/models/output_rule.rb +296 -0
  164. data/lib/artikcloud/models/properties_envelope.rb +164 -0
  165. data/lib/artikcloud/models/refresh_token_response.rb +194 -0
  166. data/lib/artikcloud/models/register_message.rb +211 -0
  167. data/lib/artikcloud/models/rule_array.rb +166 -0
  168. data/lib/artikcloud/models/rule_creation_info.rb +200 -0
  169. data/lib/artikcloud/models/rule_envelope.rb +164 -0
  170. data/lib/artikcloud/models/rule_error.rb +196 -0
  171. data/lib/artikcloud/models/rule_update_info.rb +200 -0
  172. data/lib/artikcloud/models/rule_warning_output.rb +174 -0
  173. data/lib/artikcloud/models/rules_envelope.rb +194 -0
  174. data/lib/artikcloud/models/tag.rb +176 -0
  175. data/lib/artikcloud/models/tag_array.rb +166 -0
  176. data/lib/artikcloud/models/tags_envelope.rb +164 -0
  177. data/lib/artikcloud/models/token.rb +194 -0
  178. data/lib/artikcloud/models/token_request.rb +164 -0
  179. data/lib/artikcloud/models/token_response.rb +164 -0
  180. data/lib/artikcloud/models/unregister_device_response.rb +275 -0
  181. data/lib/artikcloud/models/unregister_device_response_envelope.rb +164 -0
  182. data/lib/artikcloud/models/user.rb +224 -0
  183. data/lib/artikcloud/models/user_envelope.rb +164 -0
  184. data/lib/artikcloud/models/web_socket_error.rb +187 -0
  185. data/lib/artikcloud/version.rb +17 -0
  186. data/lib/artikcloud.rb +128 -0
  187. data/pom.xml +60 -0
  188. data/spec/api/messages_api_spec.rb +79 -0
  189. data/spec/api/tokens_api_spec.rb +79 -0
  190. data/spec/api/users_api_spec.rb +50 -0
  191. data/spec/spec.opts +4 -0
  192. data/spec/spec_helper.rb +36 -0
  193. metadata +420 -0
@@ -0,0 +1,336 @@
1
+ =begin
2
+ ARTIK Cloud API
3
+
4
+ OpenAPI spec version: 2.0.0
5
+
6
+ Generated by: https://github.com/swagger-api/swagger-codegen.git
7
+
8
+ License: MIT
9
+ http://en.wikipedia.org/wiki/MIT_License
10
+
11
+ Terms of Service: http://www.samsung.com/global/business/mobile/info/terms-and-conditions.html
12
+
13
+ =end
14
+
15
+ require 'date'
16
+ require 'json'
17
+ require 'logger'
18
+ require 'tempfile'
19
+ require 'typhoeus'
20
+ require 'uri'
21
+
22
+ module ArtikCloud
23
+ class ApiClient
24
+ # The Configuration object holding settings to be used in the API client.
25
+ attr_accessor :config
26
+
27
+ # Defines the headers to be used in HTTP requests of all API calls by default.
28
+ #
29
+ # @return [Hash]
30
+ attr_accessor :default_headers
31
+
32
+ def initialize(config = Configuration.default)
33
+ @config = config
34
+ @user_agent = "Swagger-Codegen/#{VERSION}/ruby"
35
+ @default_headers = {
36
+ 'Content-Type' => "application/json",
37
+ 'User-Agent' => @user_agent
38
+ }
39
+ end
40
+
41
+ def self.default
42
+ @@default ||= ApiClient.new
43
+ end
44
+
45
+ # Call an API with given options.
46
+ #
47
+ # @return [Array<(Object, Fixnum, Hash)>] an array of 3 elements:
48
+ # the data deserialized from response body (could be nil), response status code and response headers.
49
+ def call_api(http_method, path, opts = {})
50
+ request = build_request(http_method, path, opts)
51
+ response = request.run
52
+
53
+ if @config.debugging
54
+ @config.logger.debug "HTTP response body ~BEGIN~\n#{response.body}\n~END~\n"
55
+ end
56
+
57
+ unless response.success?
58
+ fail ApiError.new(:code => response.code,
59
+ :response_headers => response.headers,
60
+ :response_body => response.body),
61
+ response.status_message
62
+ end
63
+
64
+ if opts[:return_type]
65
+ data = deserialize(response, opts[:return_type])
66
+ else
67
+ data = nil
68
+ end
69
+ return data, response.code, response.headers
70
+ end
71
+
72
+ def build_request(http_method, path, opts = {})
73
+ url = build_request_url(path)
74
+ http_method = http_method.to_sym.downcase
75
+
76
+ header_params = @default_headers.merge(opts[:header_params] || {})
77
+ query_params = opts[:query_params] || {}
78
+ form_params = opts[:form_params] || {}
79
+
80
+
81
+ update_params_for_auth! header_params, query_params, opts[:auth_names]
82
+
83
+
84
+ req_opts = {
85
+ :method => http_method,
86
+ :headers => header_params,
87
+ :params => query_params,
88
+ :timeout => @config.timeout,
89
+ :ssl_verifypeer => @config.verify_ssl,
90
+ :sslcert => @config.cert_file,
91
+ :sslkey => @config.key_file,
92
+ :verbose => @config.debugging
93
+ }
94
+
95
+ req_opts[:cainfo] = @config.ssl_ca_cert if @config.ssl_ca_cert
96
+
97
+ if [:post, :patch, :put, :delete].include?(http_method)
98
+ req_body = build_request_body(header_params, form_params, opts[:body])
99
+ req_opts.update :body => req_body
100
+ if @config.debugging
101
+ @config.logger.debug "HTTP request body param ~BEGIN~\n#{req_body}\n~END~\n"
102
+ end
103
+ end
104
+
105
+ Typhoeus::Request.new(url, req_opts)
106
+ end
107
+
108
+ # Check if the given MIME is a JSON MIME.
109
+ # JSON MIME examples:
110
+ # application/json
111
+ # application/json; charset=UTF8
112
+ # APPLICATION/JSON
113
+ def json_mime?(mime)
114
+ !!(mime =~ /\Aapplication\/json(;.*)?\z/i)
115
+ end
116
+
117
+ # Deserialize the response to the given return type.
118
+ #
119
+ # @param [String] return_type some examples: "User", "Array[User]", "Hash[String,Integer]"
120
+ def deserialize(response, return_type)
121
+ body = response.body
122
+ return nil if body.nil? || body.empty?
123
+
124
+ # return response body directly for String return type
125
+ return body if return_type == 'String'
126
+
127
+ # handle file downloading - save response body into a tmp file and return the File instance
128
+ return download_file(response) if return_type == 'File'
129
+
130
+ # ensuring a default content type
131
+ content_type = response.headers['Content-Type'] || 'application/json'
132
+
133
+ fail "Content-Type is not supported: #{content_type}" unless json_mime?(content_type)
134
+
135
+ begin
136
+ data = JSON.parse("[#{body}]", :symbolize_names => true)[0]
137
+ rescue JSON::ParserError => e
138
+ if %w(String Date DateTime).include?(return_type)
139
+ data = body
140
+ else
141
+ raise e
142
+ end
143
+ end
144
+
145
+ convert_to_type data, return_type
146
+ end
147
+
148
+ # Convert data to the given return type.
149
+ def convert_to_type(data, return_type)
150
+ return nil if data.nil?
151
+ case return_type
152
+ when 'String'
153
+ data.to_s
154
+ when 'Integer'
155
+ data.to_i
156
+ when 'Float'
157
+ data.to_f
158
+ when 'BOOLEAN'
159
+ data == true
160
+ when 'DateTime'
161
+ # parse date time (expecting ISO 8601 format)
162
+ DateTime.parse data
163
+ when 'Date'
164
+ # parse date time (expecting ISO 8601 format)
165
+ Date.parse data
166
+ when 'Object'
167
+ # generic object (usually a Hash), return directly
168
+ data
169
+ when /\AArray<(.+)>\z/
170
+ # e.g. Array<Pet>
171
+ sub_type = $1
172
+ data.map {|item| convert_to_type(item, sub_type) }
173
+ when /\AHash\<String, (.+)\>\z/
174
+ # e.g. Hash<String, Integer>
175
+ sub_type = $1
176
+ {}.tap do |hash|
177
+ data.each {|k, v| hash[k] = convert_to_type(v, sub_type) }
178
+ end
179
+ else
180
+ # models, e.g. Pet
181
+ ArtikCloud.const_get(return_type).new.tap do |model|
182
+ model.build_from_hash data
183
+ end
184
+ end
185
+ end
186
+
187
+ # Save response body into a file in (the defined) temporary folder, using the filename
188
+ # from the "Content-Disposition" header if provided, otherwise a random filename.
189
+ #
190
+ # @see Configuration#temp_folder_path
191
+ # @return [Tempfile] the file downloaded
192
+ def download_file(response)
193
+ content_disposition = response.headers['Content-Disposition']
194
+ if content_disposition
195
+ filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1]
196
+ prefix = sanitize_filename(filename)
197
+ else
198
+ prefix = 'download-'
199
+ end
200
+ prefix = prefix + '-' unless prefix.end_with?('-')
201
+
202
+ tempfile = nil
203
+ encoding = response.body.encoding
204
+ Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding) do |file|
205
+ file.write(response.body)
206
+ tempfile = file
207
+ end
208
+ @config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\
209
+ "with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
210
+ "will be deleted automatically with GC. It's also recommended to delete the temp file "\
211
+ "explicitly with `tempfile.delete`"
212
+ tempfile
213
+ end
214
+
215
+ # Sanitize filename by removing path.
216
+ # e.g. ../../sun.gif becomes sun.gif
217
+ #
218
+ # @param [String] filename the filename to be sanitized
219
+ # @return [String] the sanitized filename
220
+ def sanitize_filename(filename)
221
+ filename.gsub /.*[\/\\]/, ''
222
+ end
223
+
224
+ def build_request_url(path)
225
+ # Add leading and trailing slashes to path
226
+ path = "/#{path}".gsub(/\/+/, '/')
227
+ URI.encode(@config.base_url + path)
228
+ end
229
+
230
+ def build_request_body(header_params, form_params, body)
231
+ # http form
232
+ if header_params['Content-Type'] == 'application/x-www-form-urlencoded' ||
233
+ header_params['Content-Type'] == 'multipart/form-data'
234
+ data = {}
235
+ form_params.each do |key, value|
236
+ case value
237
+ when File, Array, nil
238
+ # let typhoeus handle File, Array and nil parameters
239
+ data[key] = value
240
+ else
241
+ data[key] = value.to_s
242
+ end
243
+ end
244
+ elsif body
245
+ data = body.is_a?(String) ? body : body.to_json
246
+ else
247
+ data = nil
248
+ end
249
+ data
250
+ end
251
+
252
+ # Update hearder and query params based on authentication settings.
253
+ def update_params_for_auth!(header_params, query_params, auth_names)
254
+ Array(auth_names).each do |auth_name|
255
+ auth_setting = @config.auth_settings[auth_name]
256
+ next unless auth_setting
257
+ case auth_setting[:in]
258
+ when 'header' then header_params[auth_setting[:key]] = auth_setting[:value]
259
+ when 'query' then query_params[auth_setting[:key]] = auth_setting[:value]
260
+ else fail ArgumentError, 'Authentication token must be in `query` of `header`'
261
+ end
262
+ end
263
+ end
264
+
265
+ def user_agent=(user_agent)
266
+ @user_agent = user_agent
267
+ @default_headers['User-Agent'] = @user_agent
268
+ end
269
+
270
+ # Return Accept header based on an array of accepts provided.
271
+ # @param [Array] accepts array for Accept
272
+ # @return [String] the Accept header (e.g. application/json)
273
+ def select_header_accept(accepts)
274
+ return nil if accepts.nil? || accepts.empty?
275
+ # use JSON when present, otherwise use all of the provided
276
+ json_accept = accepts.find { |s| json_mime?(s) }
277
+ return json_accept || accepts.join(',')
278
+ end
279
+
280
+ # Return Content-Type header based on an array of content types provided.
281
+ # @param [Array] content_types array for Content-Type
282
+ # @return [String] the Content-Type header (e.g. application/json)
283
+ def select_header_content_type(content_types)
284
+ # use application/json by default
285
+ return 'application/json' if content_types.nil? || content_types.empty?
286
+ # use JSON when present, otherwise use the first one
287
+ json_content_type = content_types.find { |s| json_mime?(s) }
288
+ return json_content_type || content_types.first
289
+ end
290
+
291
+ # Convert object (array, hash, object, etc) to JSON string.
292
+ # @param [Object] model object to be converted into JSON string
293
+ # @return [String] JSON string representation of the object
294
+ def object_to_http_body(model)
295
+ return model if model.nil? || model.is_a?(String)
296
+ _body = nil
297
+ if model.is_a?(Array)
298
+ _body = model.map{|m| object_to_hash(m) }
299
+ else
300
+ _body = object_to_hash(model)
301
+ end
302
+ _body.to_json
303
+ end
304
+
305
+ # Convert object(non-array) to hash.
306
+ # @param [Object] obj object to be converted into JSON string
307
+ # @return [String] JSON string representation of the object
308
+ def object_to_hash(obj)
309
+ if obj.respond_to?(:to_hash)
310
+ obj.to_hash
311
+ else
312
+ obj
313
+ end
314
+ end
315
+
316
+ # Build parameter value according to the given collection format.
317
+ # @param [String] collection_format one of :csv, :ssv, :tsv, :pipes and :multi
318
+ def build_collection_param(param, collection_format)
319
+ case collection_format
320
+ when :csv
321
+ param.join(',')
322
+ when :ssv
323
+ param.join(' ')
324
+ when :tsv
325
+ param.join("\t")
326
+ when :pipes
327
+ param.join('|')
328
+ when :multi
329
+ # return the array directly as typhoeus will handle it as expected
330
+ param
331
+ else
332
+ fail "unknown collection format: #{collection_format.inspect}"
333
+ end
334
+ end
335
+ end
336
+ end
@@ -0,0 +1,38 @@
1
+ =begin
2
+ ARTIK Cloud API
3
+
4
+ OpenAPI spec version: 2.0.0
5
+
6
+ Generated by: https://github.com/swagger-api/swagger-codegen.git
7
+
8
+ License: MIT
9
+ http://en.wikipedia.org/wiki/MIT_License
10
+
11
+ Terms of Service: http://www.samsung.com/global/business/mobile/info/terms-and-conditions.html
12
+
13
+ =end
14
+
15
+ module ArtikCloud
16
+ class ApiError < StandardError
17
+ attr_reader :code, :response_headers, :response_body
18
+
19
+ # Usage examples:
20
+ # ApiError.new
21
+ # ApiError.new("message")
22
+ # ApiError.new(:code => 500, :response_headers => {}, :response_body => "")
23
+ # ApiError.new(:code => 404, :message => "Not Found")
24
+ def initialize(arg = nil)
25
+ if arg.is_a? Hash
26
+ arg.each do |k, v|
27
+ if k.to_s == 'message'
28
+ super v
29
+ else
30
+ instance_variable_set "@#{k}", v
31
+ end
32
+ end
33
+ else
34
+ super arg
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,170 @@
1
+ require 'uri'
2
+
3
+ module ArtikCloud
4
+ class Configuration
5
+ # Defines url scheme
6
+ attr_accessor :scheme
7
+
8
+ # Defines url host
9
+ attr_accessor :host
10
+
11
+ # Defines url base path
12
+ attr_accessor :base_path
13
+
14
+ # Defines API keys used with API Key authentications.
15
+ #
16
+ # @return [Hash] key: parameter name, value: parameter value (API key)
17
+ #
18
+ # @example parameter name is "api_key", API key is "xxx" (e.g. "api_key=xxx" in query string)
19
+ # config.api_key['api_key'] = 'xxx'
20
+ attr_accessor :api_key
21
+
22
+ # Defines API key prefixes used with API Key authentications.
23
+ #
24
+ # @return [Hash] key: parameter name, value: API key prefix
25
+ #
26
+ # @example parameter name is "Authorization", API key prefix is "Token" (e.g. "Authorization: Token xxx" in headers)
27
+ # config.api_key_prefix['api_key'] = 'Token'
28
+ attr_accessor :api_key_prefix
29
+
30
+ # Defines the username used with HTTP basic authentication.
31
+ #
32
+ # @return [String]
33
+ attr_accessor :username
34
+
35
+ # Defines the password used with HTTP basic authentication.
36
+ #
37
+ # @return [String]
38
+ attr_accessor :password
39
+
40
+ # Defines the access token (Bearer) used with OAuth2.
41
+ attr_accessor :access_token
42
+
43
+ # Set this to enable/disable debugging. When enabled (set to true), HTTP request/response
44
+ # details will be logged with `logger.debug` (see the `logger` attribute).
45
+ # Default to false.
46
+ #
47
+ # @return [true, false]
48
+ attr_accessor :debugging
49
+
50
+ # Defines the logger used for debugging.
51
+ # Default to `Rails.logger` (when in Rails) or logging to STDOUT.
52
+ #
53
+ # @return [#debug]
54
+ attr_accessor :logger
55
+
56
+ # Defines the temporary folder to store downloaded files
57
+ # (for API endpoints that have file response).
58
+ # Default to use `Tempfile`.
59
+ #
60
+ # @return [String]
61
+ attr_accessor :temp_folder_path
62
+
63
+ # The time limit for HTTP request in seconds.
64
+ # Default to 0 (never times out).
65
+ attr_accessor :timeout
66
+
67
+ ### TLS/SSL
68
+ # Set this to false to skip verifying SSL certificate when calling API from https server.
69
+ # Default to true.
70
+ #
71
+ # @note Do NOT set it to false in production code, otherwise you would face multiple types of cryptographic attacks.
72
+ #
73
+ # @return [true, false]
74
+ attr_accessor :verify_ssl
75
+
76
+ # Set this to customize the certificate file to verify the peer.
77
+ #
78
+ # @return [String] the path to the certificate file
79
+ #
80
+ # @see The `cainfo` option of Typhoeus, `--cert` option of libcurl. Related source code:
81
+ # https://github.com/typhoeus/typhoeus/blob/master/lib/typhoeus/easy_factory.rb#L145
82
+ attr_accessor :ssl_ca_cert
83
+
84
+ # Client certificate file (for client certificate)
85
+ attr_accessor :cert_file
86
+
87
+ # Client private key file (for client certificate)
88
+ attr_accessor :key_file
89
+
90
+ attr_accessor :inject_format
91
+
92
+ attr_accessor :force_ending_format
93
+
94
+ def initialize
95
+ @scheme = 'https'
96
+ @host = 'api.artik.cloud'
97
+ @base_path = '/v1.1'
98
+ @api_key = {}
99
+ @api_key_prefix = {}
100
+ @timeout = 0
101
+ @verify_ssl = true
102
+ @cert_file = nil
103
+ @key_file = nil
104
+ @debugging = false
105
+ @inject_format = false
106
+ @force_ending_format = false
107
+ @logger = defined?(Rails) ? Rails.logger : Logger.new(STDOUT)
108
+
109
+ yield(self) if block_given?
110
+ end
111
+
112
+ # The default Configuration object.
113
+ def self.default
114
+ @@default ||= Configuration.new
115
+ end
116
+
117
+ def configure
118
+ yield(self) if block_given?
119
+ end
120
+
121
+ def scheme=(scheme)
122
+ # remove :// from scheme
123
+ @scheme = scheme.sub(/:\/\//, '')
124
+ end
125
+
126
+ def host=(host)
127
+ # remove http(s):// and anything after a slash
128
+ @host = host.sub(/https?:\/\//, '').split('/').first
129
+ end
130
+
131
+ def base_path=(base_path)
132
+ # Add leading and trailing slashes to base_path
133
+ @base_path = "/#{base_path}".gsub(/\/+/, '/')
134
+ @base_path = "" if @base_path == "/"
135
+ end
136
+
137
+ def base_url
138
+ url = "#{scheme}://#{[host, base_path].join('/').gsub(/\/+/, '/')}".sub(/\/+\z/, '')
139
+ URI.encode(url)
140
+ end
141
+
142
+ # Gets API key (with prefix if set).
143
+ # @param [String] param_name the parameter name of API key auth
144
+ def api_key_with_prefix(param_name)
145
+ if @api_key_prefix[param_name]
146
+ "#{@api_key_prefix[param_name]} #{@api_key[param_name]}"
147
+ else
148
+ @api_key[param_name]
149
+ end
150
+ end
151
+
152
+ # Gets Basic Auth token string
153
+ def basic_auth_token
154
+ 'Basic ' + ["#{username}:#{password}"].pack('m').delete("\r\n")
155
+ end
156
+
157
+ # Returns Auth Settings hash for api client.
158
+ def auth_settings
159
+ {
160
+ 'artikcloud_oauth' =>
161
+ {
162
+ type: 'oauth2',
163
+ in: 'header',
164
+ key: 'Authorization',
165
+ value: "Bearer #{access_token}"
166
+ },
167
+ }
168
+ end
169
+ end
170
+ end
@@ -0,0 +1,164 @@
1
+ =begin
2
+ ARTIK Cloud API
3
+
4
+ OpenAPI spec version: 2.0.0
5
+
6
+ Generated by: https://github.com/swagger-api/swagger-codegen.git
7
+
8
+ License: MIT
9
+ http://en.wikipedia.org/wiki/MIT_License
10
+
11
+ Terms of Service: http://www.samsung.com/global/business/mobile/info/terms-and-conditions.html
12
+
13
+ =end
14
+
15
+ require 'date'
16
+
17
+ module ArtikCloud
18
+ # Acknowledgement Envelope.
19
+ class AckEnvelope
20
+ attr_accessor :data
21
+
22
+ # Attribute mapping from ruby-style variable name to JSON key.
23
+ def self.attribute_map
24
+ {
25
+
26
+ :'data' => :'data'
27
+
28
+ }
29
+ end
30
+
31
+ # Attribute type mapping.
32
+ def self.swagger_types
33
+ {
34
+ :'data' => :'Acknowledgement'
35
+
36
+ }
37
+ end
38
+
39
+ def initialize(attributes = {})
40
+ return unless attributes.is_a?(Hash)
41
+
42
+ # convert string to symbol for hash key
43
+ attributes = attributes.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
44
+
45
+
46
+ if attributes[:'data']
47
+ self.data = attributes[:'data']
48
+ end
49
+
50
+ end
51
+
52
+ # Check equality by comparing each attribute.
53
+ def ==(o)
54
+ return true if self.equal?(o)
55
+ self.class == o.class &&
56
+ data == o.data
57
+ end
58
+
59
+ # @see the `==` method
60
+ def eql?(o)
61
+ self == o
62
+ end
63
+
64
+ # Calculate hash code according to all attributes.
65
+ def hash
66
+ [data].hash
67
+ end
68
+
69
+ # build the object from hash
70
+ def build_from_hash(attributes)
71
+ return nil unless attributes.is_a?(Hash)
72
+ self.class.swagger_types.each_pair do |key, type|
73
+ if type =~ /^Array<(.*)>/i
74
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
75
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map{ |v| _deserialize($1, v) } )
76
+ else
77
+ #TODO show warning in debug mode
78
+ end
79
+ elsif !attributes[self.class.attribute_map[key]].nil?
80
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
81
+ else
82
+ # data not found in attributes(hash), not an issue as the data can be optional
83
+ end
84
+ end
85
+
86
+ self
87
+ end
88
+
89
+ def _deserialize(type, value)
90
+ case type.to_sym
91
+ when :DateTime
92
+ DateTime.parse(value)
93
+ when :Date
94
+ Date.parse(value)
95
+ when :String
96
+ value.to_s
97
+ when :Integer
98
+ value.to_i
99
+ when :Float
100
+ value.to_f
101
+ when :BOOLEAN
102
+ if value.to_s =~ /^(true|t|yes|y|1)$/i
103
+ true
104
+ else
105
+ false
106
+ end
107
+ when :Object
108
+ # generic object (usually a Hash), return directly
109
+ value
110
+ when /\AArray<(?<inner_type>.+)>\z/
111
+ inner_type = Regexp.last_match[:inner_type]
112
+ value.map { |v| _deserialize(inner_type, v) }
113
+ when /\AHash<(?<k_type>.+), (?<v_type>.+)>\z/
114
+ k_type = Regexp.last_match[:k_type]
115
+ v_type = Regexp.last_match[:v_type]
116
+ {}.tap do |hash|
117
+ value.each do |k, v|
118
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
119
+ end
120
+ end
121
+ else # model
122
+ _model = ArtikCloud.const_get(type).new
123
+ _model.build_from_hash(value)
124
+ end
125
+ end
126
+
127
+ def to_s
128
+ to_hash.to_s
129
+ end
130
+
131
+ # to_body is an alias to to_body (backward compatibility))
132
+ def to_body
133
+ to_hash
134
+ end
135
+
136
+ # return the object in the form of hash
137
+ def to_hash
138
+ hash = {}
139
+ self.class.attribute_map.each_pair do |attr, param|
140
+ value = self.send(attr)
141
+ next if value.nil?
142
+ hash[param] = _to_hash(value)
143
+ end
144
+ hash
145
+ end
146
+
147
+ # Method to output non-array value in the form of hash
148
+ # For object, use to_hash. Otherwise, just return the value
149
+ def _to_hash(value)
150
+ if value.is_a?(Array)
151
+ value.compact.map{ |v| _to_hash(v) }
152
+ elsif value.is_a?(Hash)
153
+ {}.tap do |hash|
154
+ value.each { |k, v| hash[k] = _to_hash(v) }
155
+ end
156
+ elsif value.respond_to? :to_hash
157
+ value.to_hash
158
+ else
159
+ value
160
+ end
161
+ end
162
+
163
+ end
164
+ end