onesignal 0.3.0 → 1.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (141) hide show
  1. checksums.yaml +5 -5
  2. data/Gemfile +6 -1
  3. data/README.md +126 -111
  4. data/Rakefile +8 -8
  5. data/docs/App.md +76 -0
  6. data/docs/Button.md +22 -0
  7. data/docs/DefaultApi.md +1394 -0
  8. data/docs/DeliveryData.md +26 -0
  9. data/docs/ExportPlayersRequestBody.md +22 -0
  10. data/docs/Filter.md +24 -0
  11. data/docs/FilterExpressions.md +26 -0
  12. data/docs/FilterNotificationTarget.md +40 -0
  13. data/docs/GetNotificationRequestBody.md +22 -0
  14. data/docs/InlineResponse200.md +24 -0
  15. data/docs/InlineResponse2001.md +18 -0
  16. data/docs/InlineResponse2002.md +20 -0
  17. data/docs/InlineResponse2003.md +18 -0
  18. data/docs/InlineResponse2004.md +20 -0
  19. data/docs/InlineResponse2005.md +18 -0
  20. data/docs/InlineResponse201.md +20 -0
  21. data/docs/InlineResponse400.md +18 -0
  22. data/docs/InlineResponse4001.md +20 -0
  23. data/docs/InlineResponse4002.md +18 -0
  24. data/docs/InlineResponse409.md +20 -0
  25. data/docs/Notification.md +240 -0
  26. data/docs/NotificationAllOf.md +192 -0
  27. data/docs/NotificationAllOfAndroidBackgroundLayout.md +22 -0
  28. data/docs/NotificationSlice.md +24 -0
  29. data/docs/NotificationTarget.md +64 -0
  30. data/docs/Operator.md +18 -0
  31. data/docs/OutcomeData.md +22 -0
  32. data/docs/PlatformDeliveryData.md +28 -0
  33. data/docs/Player.md +70 -0
  34. data/docs/PlayerNotificationTarget.md +36 -0
  35. data/docs/PlayerSlice.md +24 -0
  36. data/docs/Purchase.md +22 -0
  37. data/docs/Segment.md +22 -0
  38. data/docs/SegmentNotificationTarget.md +20 -0
  39. data/docs/StringMap.md +102 -0
  40. data/docs/UpdatePlayerTagsRequestBody.md +18 -0
  41. data/git_push.sh +58 -0
  42. data/lib/OneSignal.rb +75 -0
  43. data/lib/onesignal/api/default_api.rb +1338 -0
  44. data/lib/onesignal/api_client.rb +391 -0
  45. data/lib/onesignal/api_error.rb +57 -0
  46. data/lib/onesignal/configuration.rb +242 -0
  47. data/lib/onesignal/models/app.rb +519 -13
  48. data/lib/onesignal/models/button.rb +241 -0
  49. data/lib/onesignal/models/delivery_data.rb +254 -0
  50. data/lib/onesignal/models/export_players_request_body.rb +241 -0
  51. data/lib/onesignal/models/filter.rb +293 -0
  52. data/lib/onesignal/models/filter_expressions.rb +335 -0
  53. data/lib/onesignal/models/filter_notification_target.rb +329 -0
  54. data/lib/onesignal/models/get_notification_request_body.rb +272 -0
  55. data/lib/onesignal/models/inline_response200.rb +256 -0
  56. data/lib/onesignal/models/inline_response2001.rb +218 -0
  57. data/lib/onesignal/models/inline_response2002.rb +227 -0
  58. data/lib/onesignal/models/inline_response2003.rb +218 -0
  59. data/lib/onesignal/models/inline_response2004.rb +227 -0
  60. data/lib/onesignal/models/inline_response2005.rb +218 -0
  61. data/lib/onesignal/models/inline_response201.rb +228 -0
  62. data/lib/onesignal/models/inline_response400.rb +220 -0
  63. data/lib/onesignal/models/inline_response4001.rb +229 -0
  64. data/lib/onesignal/models/inline_response4002.rb +220 -0
  65. data/lib/onesignal/models/inline_response409.rb +229 -0
  66. data/lib/onesignal/models/notification.rb +1395 -5
  67. data/lib/onesignal/models/notification_all_of.rb +1124 -0
  68. data/lib/onesignal/models/notification_all_of_android_background_layout.rb +240 -0
  69. data/lib/onesignal/models/notification_slice.rb +247 -0
  70. data/lib/onesignal/models/notification_target.rb +494 -0
  71. data/lib/onesignal/models/operator.rb +253 -0
  72. data/lib/onesignal/models/outcome_data.rb +285 -0
  73. data/lib/onesignal/models/platform_delivery_data.rb +264 -0
  74. data/lib/onesignal/models/player.rb +483 -9
  75. data/lib/onesignal/models/player_notification_target.rb +329 -0
  76. data/lib/onesignal/models/player_slice.rb +247 -0
  77. data/lib/onesignal/models/purchase.rb +254 -0
  78. data/lib/onesignal/models/segment.rb +251 -0
  79. data/lib/onesignal/models/segment_notification_target.rb +233 -0
  80. data/lib/onesignal/models/string_map.rb +644 -0
  81. data/lib/onesignal/models/update_player_tags_request_body.rb +219 -0
  82. data/lib/onesignal/version.rb +13 -1
  83. data/onesignal.gemspec +36 -27
  84. data/spec/api/default_api_spec.rb +285 -0
  85. data/spec/api_client_spec.rb +226 -0
  86. data/spec/configuration_spec.rb +42 -0
  87. data/spec/models/app_spec.rb +212 -0
  88. data/spec/models/button_spec.rb +46 -0
  89. data/spec/models/delivery_data_spec.rb +58 -0
  90. data/spec/models/export_players_request_body_spec.rb +46 -0
  91. data/spec/models/filter_expressions_spec.rb +66 -0
  92. data/spec/models/filter_notification_target_spec.rb +100 -0
  93. data/spec/models/filter_spec.rb +56 -0
  94. data/spec/models/get_notification_request_body_spec.rb +50 -0
  95. data/spec/models/inline_response2001_spec.rb +34 -0
  96. data/spec/models/inline_response2002_spec.rb +40 -0
  97. data/spec/models/inline_response2003_spec.rb +34 -0
  98. data/spec/models/inline_response2004_spec.rb +40 -0
  99. data/spec/models/inline_response2005_spec.rb +34 -0
  100. data/spec/models/inline_response200_spec.rb +52 -0
  101. data/spec/models/inline_response201_spec.rb +40 -0
  102. data/spec/models/inline_response4001_spec.rb +40 -0
  103. data/spec/models/inline_response4002_spec.rb +34 -0
  104. data/spec/models/inline_response400_spec.rb +34 -0
  105. data/spec/models/inline_response409_spec.rb +40 -0
  106. data/spec/models/notification_all_of_android_background_layout_spec.rb +46 -0
  107. data/spec/models/notification_all_of_spec.rb +560 -0
  108. data/spec/models/notification_slice_spec.rb +52 -0
  109. data/spec/models/notification_spec.rb +704 -0
  110. data/spec/models/notification_target_spec.rb +172 -0
  111. data/spec/models/operator_spec.rb +38 -0
  112. data/spec/models/outcome_data_spec.rb +50 -0
  113. data/spec/models/platform_delivery_data_spec.rb +64 -0
  114. data/spec/models/player_notification_target_spec.rb +88 -0
  115. data/spec/models/player_slice_spec.rb +52 -0
  116. data/spec/models/player_spec.rb +190 -0
  117. data/spec/models/purchase_spec.rb +46 -0
  118. data/spec/models/segment_notification_target_spec.rb +40 -0
  119. data/spec/models/segment_spec.rb +46 -0
  120. data/spec/models/string_map_spec.rb +286 -0
  121. data/spec/models/update_player_tags_request_body_spec.rb +34 -0
  122. data/spec/spec_helper.rb +111 -0
  123. metadata +182 -65
  124. data/.gitignore +0 -10
  125. data/.rubocop.yml +0 -17
  126. data/.travis.yml +0 -16
  127. data/CHANGELOG.md +0 -22
  128. data/CODE_OF_CONDUCT.md +0 -49
  129. data/LICENSE +0 -21
  130. data/bin/console +0 -14
  131. data/bin/setup +0 -8
  132. data/lib/onesignal/app_id_missing_error.rb +0 -7
  133. data/lib/onesignal/client.rb +0 -44
  134. data/lib/onesignal/models/base_model.rb +0 -40
  135. data/lib/onesignal/request.rb +0 -94
  136. data/lib/onesignal/request_error.rb +0 -21
  137. data/lib/onesignal/resources/app_resource.rb +0 -27
  138. data/lib/onesignal/resources/base_resource.rb +0 -35
  139. data/lib/onesignal/resources/notification_resource.rb +0 -33
  140. data/lib/onesignal/resources/player_resource.rb +0 -53
  141. data/lib/onesignal.rb +0 -23
@@ -0,0 +1,391 @@
1
+ =begin
2
+ #OneSignal
3
+
4
+ #A powerful way to send personalized messages at scale and build effective customer engagement strategies. Learn more at onesignal.com
5
+
6
+ The version of the OpenAPI document: 1.0.0
7
+ Contact: devrel@onesignal.com
8
+ Generated by: https://openapi-generator.tech
9
+ OpenAPI Generator version: 5.2.0-SNAPSHOT
10
+
11
+ =end
12
+
13
+ require 'date'
14
+ require 'json'
15
+ require 'logger'
16
+ require 'tempfile'
17
+ require 'time'
18
+ require 'typhoeus'
19
+
20
+ module OneSignal
21
+ class ApiClient
22
+ # The Configuration object holding settings to be used in the API client.
23
+ attr_accessor :config
24
+
25
+ # Defines the headers to be used in HTTP requests of all API calls by default.
26
+ #
27
+ # @return [Hash]
28
+ attr_accessor :default_headers
29
+
30
+ # Initializes the ApiClient
31
+ # @option config [Configuration] Configuration for initializing the object, default to Configuration.default
32
+ def initialize(config = Configuration.default)
33
+ @config = config
34
+ @user_agent = "OpenAPI-Generator/#{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, Integer, 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
+ if response.timed_out?
59
+ fail ApiError.new('Connection timed out')
60
+ elsif response.code == 0
61
+ # Errors from libcurl will be made visible here
62
+ fail ApiError.new(:code => 0,
63
+ :message => response.return_message)
64
+ else
65
+ fail ApiError.new(:code => response.code,
66
+ :response_headers => response.headers,
67
+ :response_body => response.body),
68
+ response.status_message
69
+ end
70
+ end
71
+
72
+ if opts[:return_type]
73
+ data = deserialize(response, opts[:return_type])
74
+ else
75
+ data = nil
76
+ end
77
+ return data, response.code, response.headers
78
+ end
79
+
80
+ # Builds the HTTP request
81
+ #
82
+ # @param [String] http_method HTTP method/verb (e.g. POST)
83
+ # @param [String] path URL path (e.g. /account/new)
84
+ # @option opts [Hash] :header_params Header parameters
85
+ # @option opts [Hash] :query_params Query parameters
86
+ # @option opts [Hash] :form_params Query parameters
87
+ # @option opts [Object] :body HTTP body (JSON/XML)
88
+ # @return [Typhoeus::Request] A Typhoeus Request
89
+ def build_request(http_method, path, opts = {})
90
+ url = build_request_url(path, opts)
91
+ http_method = http_method.to_sym.downcase
92
+
93
+ header_params = @default_headers.merge(opts[:header_params] || {})
94
+ header_params['OS-Usage-Data'] = 'kind=sdk, name=onesignal-ruby, version=1.0.0'
95
+ query_params = opts[:query_params] || {}
96
+ form_params = opts[:form_params] || {}
97
+
98
+ update_params_for_auth! header_params, query_params, opts[:auth_names]
99
+
100
+ # set ssl_verifyhosts option based on @config.verify_ssl_host (true/false)
101
+ _verify_ssl_host = @config.verify_ssl_host ? 2 : 0
102
+
103
+ req_opts = {
104
+ :method => http_method,
105
+ :headers => header_params,
106
+ :params => query_params,
107
+ :params_encoding => @config.params_encoding,
108
+ :timeout => @config.timeout,
109
+ :ssl_verifypeer => @config.verify_ssl,
110
+ :ssl_verifyhost => _verify_ssl_host,
111
+ :sslcert => @config.cert_file,
112
+ :sslkey => @config.key_file,
113
+ :verbose => @config.debugging
114
+ }
115
+
116
+ # set custom cert, if provided
117
+ req_opts[:cainfo] = @config.ssl_ca_cert if @config.ssl_ca_cert
118
+
119
+ if [:post, :patch, :put, :delete].include?(http_method)
120
+ req_body = build_request_body(header_params, form_params, opts[:body])
121
+ req_opts.update :body => req_body
122
+ if @config.debugging
123
+ @config.logger.debug "HTTP request body param ~BEGIN~\n#{req_body}\n~END~\n"
124
+ end
125
+ end
126
+
127
+ request = Typhoeus::Request.new(url, req_opts)
128
+ download_file(request) if opts[:return_type] == 'File'
129
+ request
130
+ end
131
+
132
+ # Builds the HTTP request body
133
+ #
134
+ # @param [Hash] header_params Header parameters
135
+ # @param [Hash] form_params Query parameters
136
+ # @param [Object] body HTTP body (JSON/XML)
137
+ # @return [String] HTTP body data in the form of string
138
+ def build_request_body(header_params, form_params, body)
139
+ # http form
140
+ if header_params['Content-Type'] == 'application/x-www-form-urlencoded' ||
141
+ header_params['Content-Type'] == 'multipart/form-data'
142
+ data = {}
143
+ form_params.each do |key, value|
144
+ case value
145
+ when ::File, ::Array, nil
146
+ # let typhoeus handle File, Array and nil parameters
147
+ data[key] = value
148
+ else
149
+ data[key] = value.to_s
150
+ end
151
+ end
152
+ elsif body
153
+ data = body.is_a?(String) ? body : body.to_json
154
+ else
155
+ data = nil
156
+ end
157
+ data
158
+ end
159
+
160
+ # Save response body into a file in (the defined) temporary folder, using the filename
161
+ # from the "Content-Disposition" header if provided, otherwise a random filename.
162
+ # The response body is written to the file in chunks in order to handle files which
163
+ # size is larger than maximum Ruby String or even larger than the maximum memory a Ruby
164
+ # process can use.
165
+ #
166
+ # @see Configuration#temp_folder_path
167
+ def download_file(request)
168
+ tempfile = nil
169
+ encoding = nil
170
+ request.on_headers do |response|
171
+ content_disposition = response.headers['Content-Disposition']
172
+ if content_disposition && content_disposition =~ /filename=/i
173
+ filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1]
174
+ prefix = sanitize_filename(filename)
175
+ else
176
+ prefix = 'download-'
177
+ end
178
+ prefix = prefix + '-' unless prefix.end_with?('-')
179
+ encoding = response.body.encoding
180
+ tempfile = Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding)
181
+ @tempfile = tempfile
182
+ end
183
+ request.on_body do |chunk|
184
+ chunk.force_encoding(encoding)
185
+ tempfile.write(chunk)
186
+ end
187
+ request.on_complete do |response|
188
+ if tempfile
189
+ tempfile.close
190
+ @config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\
191
+ "with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
192
+ "will be deleted automatically with GC. It's also recommended to delete the temp file "\
193
+ "explicitly with `tempfile.delete`"
194
+ end
195
+ end
196
+ end
197
+
198
+ # Check if the given MIME is a JSON MIME.
199
+ # JSON MIME examples:
200
+ # application/json
201
+ # application/json; charset=UTF8
202
+ # APPLICATION/JSON
203
+ # */*
204
+ # @param [String] mime MIME
205
+ # @return [Boolean] True if the MIME is application/json
206
+ def json_mime?(mime)
207
+ (mime == '*/*') || !(mime =~ /Application\/.*json(?!p)(;.*)?/i).nil?
208
+ end
209
+
210
+ # Deserialize the response to the given return type.
211
+ #
212
+ # @param [Response] response HTTP response
213
+ # @param [String] return_type some examples: "User", "Array<User>", "Hash<String, Integer>"
214
+ def deserialize(response, return_type)
215
+ body = response.body
216
+
217
+ # handle file downloading - return the File instance processed in request callbacks
218
+ # note that response body is empty when the file is written in chunks in request on_body callback
219
+ return @tempfile if return_type == 'File'
220
+
221
+ return nil if body.nil? || body.empty?
222
+
223
+ # return response body directly for String return type
224
+ return body if return_type == 'String'
225
+
226
+ # ensuring a default content type
227
+ content_type = response.headers['Content-Type'] || 'application/json'
228
+
229
+ fail "Content-Type is not supported: #{content_type}" unless json_mime?(content_type)
230
+
231
+ begin
232
+ data = JSON.parse("[#{body}]", :symbolize_names => true)[0]
233
+ rescue JSON::ParserError => e
234
+ if %w(String Date Time).include?(return_type)
235
+ data = body
236
+ else
237
+ raise e
238
+ end
239
+ end
240
+
241
+ convert_to_type data, return_type
242
+ end
243
+
244
+ # Convert data to the given return type.
245
+ # @param [Object] data Data to be converted
246
+ # @param [String] return_type Return type
247
+ # @return [Mixed] Data in a particular type
248
+ def convert_to_type(data, return_type)
249
+ return nil if data.nil?
250
+ case return_type
251
+ when 'String'
252
+ data.to_s
253
+ when 'Integer'
254
+ data.to_i
255
+ when 'Float'
256
+ data.to_f
257
+ when 'Boolean'
258
+ data == true
259
+ when 'Time'
260
+ # parse date time (expecting ISO 8601 format)
261
+ Time.parse data
262
+ when 'Date'
263
+ # parse date time (expecting ISO 8601 format)
264
+ Date.parse data
265
+ when 'Object'
266
+ # generic object (usually a Hash), return directly
267
+ data
268
+ when /\AArray<(.+)>\z/
269
+ # e.g. Array<Pet>
270
+ sub_type = $1
271
+ data.map { |item| convert_to_type(item, sub_type) }
272
+ when /\AHash\<String, (.+)\>\z/
273
+ # e.g. Hash<String, Integer>
274
+ sub_type = $1
275
+ {}.tap do |hash|
276
+ data.each { |k, v| hash[k] = convert_to_type(v, sub_type) }
277
+ end
278
+ else
279
+ # models (e.g. Pet) or oneOf
280
+ klass = OneSignal.const_get(return_type)
281
+ klass.respond_to?(:openapi_one_of) ? klass.build(data) : klass.build_from_hash(data)
282
+ end
283
+ end
284
+
285
+ # Sanitize filename by removing path.
286
+ # e.g. ../../sun.gif becomes sun.gif
287
+ #
288
+ # @param [String] filename the filename to be sanitized
289
+ # @return [String] the sanitized filename
290
+ def sanitize_filename(filename)
291
+ filename.gsub(/.*[\/\\]/, '')
292
+ end
293
+
294
+ def build_request_url(path, opts = {})
295
+ # Add leading and trailing slashes to path
296
+ path = "/#{path}".gsub(/\/+/, '/')
297
+ @config.base_url(opts[:operation]) + path
298
+ end
299
+
300
+ # Update hearder and query params based on authentication settings.
301
+ #
302
+ # @param [Hash] header_params Header parameters
303
+ # @param [Hash] query_params Query parameters
304
+ # @param [String] auth_names Authentication scheme name
305
+ def update_params_for_auth!(header_params, query_params, auth_names)
306
+ Array(auth_names).each do |auth_name|
307
+ auth_setting = @config.auth_settings[auth_name]
308
+ next unless auth_setting
309
+ case auth_setting[:in]
310
+ when 'header' then header_params[auth_setting[:key]] = auth_setting[:value]
311
+ when 'query' then query_params[auth_setting[:key]] = auth_setting[:value]
312
+ else fail ArgumentError, 'Authentication token must be in `query` or `header`'
313
+ end
314
+ end
315
+ end
316
+
317
+ # Sets user agent in HTTP header
318
+ #
319
+ # @param [String] user_agent User agent (e.g. openapi-generator/ruby/1.0.0)
320
+ def user_agent=(user_agent)
321
+ @user_agent = user_agent
322
+ @default_headers['User-Agent'] = @user_agent
323
+ end
324
+
325
+ # Return Accept header based on an array of accepts provided.
326
+ # @param [Array] accepts array for Accept
327
+ # @return [String] the Accept header (e.g. application/json)
328
+ def select_header_accept(accepts)
329
+ return nil if accepts.nil? || accepts.empty?
330
+ # use JSON when present, otherwise use all of the provided
331
+ json_accept = accepts.find { |s| json_mime?(s) }
332
+ json_accept || accepts.join(',')
333
+ end
334
+
335
+ # Return Content-Type header based on an array of content types provided.
336
+ # @param [Array] content_types array for Content-Type
337
+ # @return [String] the Content-Type header (e.g. application/json)
338
+ def select_header_content_type(content_types)
339
+ # use application/json by default
340
+ return 'application/json' if content_types.nil? || content_types.empty?
341
+ # use JSON when present, otherwise use the first one
342
+ json_content_type = content_types.find { |s| json_mime?(s) }
343
+ json_content_type || content_types.first
344
+ end
345
+
346
+ # Convert object (array, hash, object, etc) to JSON string.
347
+ # @param [Object] model object to be converted into JSON string
348
+ # @return [String] JSON string representation of the object
349
+ def object_to_http_body(model)
350
+ return model if model.nil? || model.is_a?(String)
351
+ local_body = nil
352
+ if model.is_a?(Array)
353
+ local_body = model.map { |m| object_to_hash(m) }
354
+ else
355
+ local_body = object_to_hash(model)
356
+ end
357
+ local_body.to_json
358
+ end
359
+
360
+ # Convert object(non-array) to hash.
361
+ # @param [Object] obj object to be converted into JSON string
362
+ # @return [String] JSON string representation of the object
363
+ def object_to_hash(obj)
364
+ if obj.respond_to?(:to_hash)
365
+ obj.to_hash
366
+ else
367
+ obj
368
+ end
369
+ end
370
+
371
+ # Build parameter value according to the given collection format.
372
+ # @param [String] collection_format one of :csv, :ssv, :tsv, :pipes and :multi
373
+ def build_collection_param(param, collection_format)
374
+ case collection_format
375
+ when :csv
376
+ param.join(',')
377
+ when :ssv
378
+ param.join(' ')
379
+ when :tsv
380
+ param.join("\t")
381
+ when :pipes
382
+ param.join('|')
383
+ when :multi
384
+ # return the array directly as typhoeus will handle it as expected
385
+ param
386
+ else
387
+ fail "unknown collection format: #{collection_format.inspect}"
388
+ end
389
+ end
390
+ end
391
+ end
@@ -0,0 +1,57 @@
1
+ =begin
2
+ #OneSignal
3
+
4
+ #A powerful way to send personalized messages at scale and build effective customer engagement strategies. Learn more at onesignal.com
5
+
6
+ The version of the OpenAPI document: 1.0.0
7
+ Contact: devrel@onesignal.com
8
+ Generated by: https://openapi-generator.tech
9
+ OpenAPI Generator version: 5.2.0-SNAPSHOT
10
+
11
+ =end
12
+
13
+ module OneSignal
14
+ class ApiError < StandardError
15
+ attr_reader :code, :response_headers, :response_body
16
+
17
+ # Usage examples:
18
+ # ApiError.new
19
+ # ApiError.new("message")
20
+ # ApiError.new(:code => 500, :response_headers => {}, :response_body => "")
21
+ # ApiError.new(:code => 404, :message => "Not Found")
22
+ def initialize(arg = nil)
23
+ if arg.is_a? Hash
24
+ if arg.key?(:message) || arg.key?('message')
25
+ super(arg[:message] || arg['message'])
26
+ else
27
+ super arg
28
+ end
29
+
30
+ arg.each do |k, v|
31
+ instance_variable_set "@#{k}", v
32
+ end
33
+ else
34
+ super arg
35
+ end
36
+ end
37
+
38
+ # Override to_s to display a friendly error message
39
+ def to_s
40
+ message
41
+ end
42
+
43
+ def message
44
+ if @message.nil?
45
+ msg = "Error message: the server returns an error"
46
+ else
47
+ msg = @message
48
+ end
49
+
50
+ msg += "\nHTTP status code: #{code}" if code
51
+ msg += "\nResponse headers: #{response_headers}" if response_headers
52
+ msg += "\nResponse body: #{response_body}" if response_body
53
+
54
+ msg
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,242 @@
1
+ =begin
2
+ #OneSignal
3
+
4
+ #A powerful way to send personalized messages at scale and build effective customer engagement strategies. Learn more at onesignal.com
5
+
6
+ The version of the OpenAPI document: 1.0.0
7
+ Contact: devrel@onesignal.com
8
+ Generated by: https://openapi-generator.tech
9
+ OpenAPI Generator version: 5.2.0-SNAPSHOT
10
+
11
+ =end
12
+
13
+ module OneSignal
14
+ class Configuration
15
+ # Defines url scheme
16
+ attr_accessor :scheme
17
+
18
+ # Defines url host
19
+ attr_accessor :host
20
+
21
+ # Defines url base path
22
+ attr_accessor :base_path
23
+
24
+ # Define server configuration index
25
+ attr_accessor :server_index
26
+
27
+ # Define server operation configuration index
28
+ attr_accessor :server_operation_index
29
+
30
+ # Default server variables
31
+ attr_accessor :server_variables
32
+
33
+ # Default server operation variables
34
+ attr_accessor :server_operation_variables
35
+
36
+ # OneSignal API token for App Authentication
37
+ attr_accessor :app_key
38
+
39
+ # OneSignal API token for User Authentication
40
+ attr_accessor :user_key
41
+
42
+ # Set this to enable/disable debugging. When enabled (set to true), HTTP request/response
43
+ # details will be logged with `logger.debug` (see the `logger` attribute).
44
+ # Default to false.
45
+ #
46
+ # @return [true, false]
47
+ attr_accessor :debugging
48
+
49
+ # Defines the logger used for debugging.
50
+ # Default to `Rails.logger` (when in Rails) or logging to STDOUT.
51
+ #
52
+ # @return [#debug]
53
+ attr_accessor :logger
54
+
55
+ # Defines the temporary folder to store downloaded files
56
+ # (for API endpoints that have file response).
57
+ # Default to use `Tempfile`.
58
+ #
59
+ # @return [String]
60
+ attr_accessor :temp_folder_path
61
+
62
+ # The time limit for HTTP request in seconds.
63
+ # Default to 0 (never times out).
64
+ attr_accessor :timeout
65
+
66
+ # Set this to false to skip client side validation in the operation.
67
+ # Default to true.
68
+ # @return [true, false]
69
+ attr_accessor :client_side_validation
70
+
71
+ ### TLS/SSL setting
72
+ # Set this to false to skip verifying SSL certificate when calling API from https server.
73
+ # Default to true.
74
+ #
75
+ # @note Do NOT set it to false in production code, otherwise you would face multiple types of cryptographic attacks.
76
+ #
77
+ # @return [true, false]
78
+ attr_accessor :verify_ssl
79
+
80
+ ### TLS/SSL setting
81
+ # Set this to false to skip verifying SSL host name
82
+ # Default to true.
83
+ #
84
+ # @note Do NOT set it to false in production code, otherwise you would face multiple types of cryptographic attacks.
85
+ #
86
+ # @return [true, false]
87
+ attr_accessor :verify_ssl_host
88
+
89
+ ### TLS/SSL setting
90
+ # Set this to customize the certificate file to verify the peer.
91
+ #
92
+ # @return [String] the path to the certificate file
93
+ #
94
+ # @see The `cainfo` option of Typhoeus, `--cert` option of libcurl. Related source code:
95
+ # https://github.com/typhoeus/typhoeus/blob/master/lib/typhoeus/easy_factory.rb#L145
96
+ attr_accessor :ssl_ca_cert
97
+
98
+ ### TLS/SSL setting
99
+ # Client certificate file (for client certificate)
100
+ attr_accessor :cert_file
101
+
102
+ ### TLS/SSL setting
103
+ # Client private key file (for client certificate)
104
+ attr_accessor :key_file
105
+
106
+ # Set this to customize parameters encoding of array parameter with multi collectionFormat.
107
+ # Default to nil.
108
+ #
109
+ # @see The params_encoding option of Ethon. Related source code:
110
+ # https://github.com/typhoeus/ethon/blob/master/lib/ethon/easy/queryable.rb#L96
111
+ attr_accessor :params_encoding
112
+
113
+ attr_accessor :inject_format
114
+
115
+ attr_accessor :force_ending_format
116
+
117
+ def initialize
118
+ @scheme = 'https'
119
+ @host = 'onesignal.com'
120
+ @base_path = '/api/v1'
121
+ @server_index = 0
122
+ @server_operation_index = {}
123
+ @server_variables = {}
124
+ @server_operation_variables = {}
125
+ @timeout = 0
126
+ @client_side_validation = true
127
+ @verify_ssl = true
128
+ @verify_ssl_host = true
129
+ @params_encoding = nil
130
+ @cert_file = nil
131
+ @key_file = nil
132
+ @debugging = false
133
+ @inject_format = false
134
+ @force_ending_format = false
135
+ @logger = defined?(Rails) ? Rails.logger : Logger.new(STDOUT)
136
+
137
+ yield(self) if block_given?
138
+ end
139
+
140
+ # The default Configuration object.
141
+ def self.default
142
+ @@default ||= Configuration.new
143
+ end
144
+
145
+ def configure
146
+ yield(self) if block_given?
147
+ end
148
+
149
+ def scheme=(scheme)
150
+ # remove :// from scheme
151
+ @scheme = scheme.sub(/:\/\//, '')
152
+ end
153
+
154
+ def host=(host)
155
+ # remove http(s):// and anything after a slash
156
+ @host = host.sub(/https?:\/\//, '').split('/').first
157
+ end
158
+
159
+ def base_path=(base_path)
160
+ # Add leading and trailing slashes to base_path
161
+ @base_path = "/#{base_path}".gsub(/\/+/, '/')
162
+ @base_path = '' if @base_path == '/'
163
+ end
164
+
165
+ # Returns base URL for specified operation based on server settings
166
+ def base_url(operation = nil)
167
+ index = server_operation_index.fetch(operation, server_index)
168
+ return "#{scheme}://#{[host, base_path].join('/').gsub(/\/+/, '/')}".sub(/\/+\z/, '') if index == nil
169
+
170
+ server_url(index, server_operation_variables.fetch(operation, server_variables), operation_server_settings[operation])
171
+ end
172
+
173
+ # Returns Auth Settings hash for api client.
174
+ def auth_settings
175
+ {
176
+ 'app_key' =>
177
+ {
178
+ type: 'bearer',
179
+ in: 'header',
180
+ key: 'Authorization',
181
+ value: "Bearer token=\"#{ app_key }\""
182
+ },
183
+ 'user_key' =>
184
+ {
185
+ type: 'bearer',
186
+ in: 'header',
187
+ key: 'Authorization',
188
+ value: "Bearer token=\"#{ user_key }\""
189
+ },
190
+ }
191
+ end
192
+
193
+ # Returns an array of Server setting
194
+ def server_settings
195
+ [
196
+ {
197
+ url: "https://onesignal.com/api/v1",
198
+ description: "No description provided",
199
+ }
200
+ ]
201
+ end
202
+
203
+ def operation_server_settings
204
+ {
205
+ }
206
+ end
207
+
208
+ # Returns URL based on server settings
209
+ #
210
+ # @param index array index of the server settings
211
+ # @param variables hash of variable and the corresponding value
212
+ def server_url(index, variables = {}, servers = nil)
213
+ servers = server_settings if servers == nil
214
+
215
+ # check array index out of bound
216
+ if (index < 0 || index >= servers.size)
217
+ fail ArgumentError, "Invalid index #{index} when selecting the server. Must be less than #{servers.size}"
218
+ end
219
+
220
+ server = servers[index]
221
+ url = server[:url]
222
+
223
+ return url unless server.key? :variables
224
+
225
+ # go through variable and assign a value
226
+ server[:variables].each do |name, variable|
227
+ if variables.key?(name)
228
+ if (!server[:variables][name].key?(:enum_values) || server[:variables][name][:enum_values].include?(variables[name]))
229
+ url.gsub! "{" + name.to_s + "}", variables[name]
230
+ else
231
+ fail ArgumentError, "The variable `#{name}` in the server URL has invalid value #{variables[name]}. Must be #{server[:variables][name][:enum_values]}."
232
+ end
233
+ else
234
+ # use default value
235
+ url.gsub! "{" + name.to_s + "}", server[:variables][name][:default_value]
236
+ end
237
+ end
238
+
239
+ url
240
+ end
241
+ end
242
+ end