onesignal_sdk 2.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (233) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +31 -0
  3. data/Gemfile +9 -0
  4. data/LICENSE +24 -0
  5. data/README.md +210 -0
  6. data/RELEASE_INSTRUCTIONS.md +11 -0
  7. data/Rakefile +10 -0
  8. data/docs/App.md +84 -0
  9. data/docs/BasicNotification.md +228 -0
  10. data/docs/BasicNotificationAllOf.md +200 -0
  11. data/docs/BasicNotificationAllOfAndroidBackgroundLayout.md +22 -0
  12. data/docs/BeginLiveActivityRequest.md +20 -0
  13. data/docs/Button.md +22 -0
  14. data/docs/CancelNotificationSuccessResponse.md +18 -0
  15. data/docs/CreateNotificationSuccessResponse.md +24 -0
  16. data/docs/CreatePlayerSuccessResponse.md +20 -0
  17. data/docs/CreateSegmentConflictResponse.md +20 -0
  18. data/docs/CreateSegmentSuccessResponse.md +20 -0
  19. data/docs/CreateSubscriptionRequestBody.md +20 -0
  20. data/docs/CreateUserConflictResponse.md +18 -0
  21. data/docs/CreateUserConflictResponseErrorsInner.md +22 -0
  22. data/docs/CreateUserConflictResponseErrorsItemsMeta.md +18 -0
  23. data/docs/DefaultApi.md +2713 -0
  24. data/docs/DeletePlayerNotFoundResponse.md +18 -0
  25. data/docs/DeletePlayerSuccessResponse.md +18 -0
  26. data/docs/DeleteSegmentNotFoundResponse.md +18 -0
  27. data/docs/DeleteSegmentSuccessResponse.md +18 -0
  28. data/docs/DeliveryData.md +26 -0
  29. data/docs/ExportEventsSuccessResponse.md +18 -0
  30. data/docs/ExportPlayersRequestBody.md +22 -0
  31. data/docs/ExportPlayersSuccessResponse.md +18 -0
  32. data/docs/Filter.md +24 -0
  33. data/docs/FilterExpressions.md +26 -0
  34. data/docs/GenericError.md +18 -0
  35. data/docs/GenericErrorErrorsInner.md +20 -0
  36. data/docs/GetNotificationRequestBody.md +22 -0
  37. data/docs/InlineResponse200.md +18 -0
  38. data/docs/InlineResponse2003.md +18 -0
  39. data/docs/InlineResponse201.md +18 -0
  40. data/docs/InlineResponse202.md +18 -0
  41. data/docs/InvalidIdentifierError.md +20 -0
  42. data/docs/Notification.md +230 -0
  43. data/docs/Notification200Errors.md +49 -0
  44. data/docs/NotificationAllOf.md +18 -0
  45. data/docs/NotificationHistorySuccessResponse.md +20 -0
  46. data/docs/NotificationSlice.md +24 -0
  47. data/docs/NotificationTarget.md +44 -0
  48. data/docs/NotificationWithMeta.md +250 -0
  49. data/docs/NotificationWithMetaAllOf.md +38 -0
  50. data/docs/Operator.md +18 -0
  51. data/docs/OutcomeData.md +22 -0
  52. data/docs/OutcomesData.md +18 -0
  53. data/docs/PlatformDeliveryData.md +32 -0
  54. data/docs/PlatformDeliveryDataEmailAllOf.md +30 -0
  55. data/docs/PlatformDeliveryDataSmsAllOf.md +22 -0
  56. data/docs/Player.md +70 -0
  57. data/docs/PlayerNotificationTarget.md +40 -0
  58. data/docs/PlayerNotificationTargetIncludeAliases.md +18 -0
  59. data/docs/PlayerSlice.md +24 -0
  60. data/docs/PropertiesDeltas.md +22 -0
  61. data/docs/PropertiesObject.md +38 -0
  62. data/docs/Purchase.md +24 -0
  63. data/docs/RateLimiterError.md +18 -0
  64. data/docs/Segment.md +22 -0
  65. data/docs/SegmentNotificationTarget.md +20 -0
  66. data/docs/StringMap.md +102 -0
  67. data/docs/SubscriptionObject.md +50 -0
  68. data/docs/TransferSubscriptionRequestBody.md +18 -0
  69. data/docs/UpdateLiveActivityRequest.md +24 -0
  70. data/docs/UpdateLiveActivitySuccessResponse.md +20 -0
  71. data/docs/UpdatePlayerSuccessResponse.md +18 -0
  72. data/docs/UpdatePlayerTagsRequestBody.md +18 -0
  73. data/docs/UpdatePlayerTagsSuccessResponse.md +18 -0
  74. data/docs/UpdateSubscriptionRequestBody.md +18 -0
  75. data/docs/UpdateUserRequest.md +22 -0
  76. data/docs/User.md +24 -0
  77. data/docs/UserIdentityRequestBody.md +18 -0
  78. data/docs/UserIdentityResponse.md +18 -0
  79. data/docs/UserSubscriptionOptions.md +18 -0
  80. data/lib/onesignal/api/default_api.rb +2727 -0
  81. data/lib/onesignal/api_client.rb +393 -0
  82. data/lib/onesignal/api_error.rb +57 -0
  83. data/lib/onesignal/configuration.rb +245 -0
  84. data/lib/onesignal/models/app.rb +586 -0
  85. data/lib/onesignal/models/basic_notification.rb +1431 -0
  86. data/lib/onesignal/models/basic_notification_all_of.rb +1241 -0
  87. data/lib/onesignal/models/basic_notification_all_of_android_background_layout.rb +241 -0
  88. data/lib/onesignal/models/begin_live_activity_request.rb +238 -0
  89. data/lib/onesignal/models/button.rb +242 -0
  90. data/lib/onesignal/models/cancel_notification_success_response.rb +219 -0
  91. data/lib/onesignal/models/create_notification_success_response.rb +248 -0
  92. data/lib/onesignal/models/create_player_success_response.rb +228 -0
  93. data/lib/onesignal/models/create_segment_conflict_response.rb +230 -0
  94. data/lib/onesignal/models/create_segment_success_response.rb +229 -0
  95. data/lib/onesignal/models/create_subscription_request_body.rb +228 -0
  96. data/lib/onesignal/models/create_user_conflict_response.rb +221 -0
  97. data/lib/onesignal/models/create_user_conflict_response_errors_inner.rb +237 -0
  98. data/lib/onesignal/models/create_user_conflict_response_errors_items_meta.rb +219 -0
  99. data/lib/onesignal/models/delete_player_not_found_response.rb +219 -0
  100. data/lib/onesignal/models/delete_player_success_response.rb +219 -0
  101. data/lib/onesignal/models/delete_segment_not_found_response.rb +219 -0
  102. data/lib/onesignal/models/delete_segment_success_response.rb +219 -0
  103. data/lib/onesignal/models/delivery_data.rb +265 -0
  104. data/lib/onesignal/models/export_events_success_response.rb +219 -0
  105. data/lib/onesignal/models/export_players_request_body.rb +242 -0
  106. data/lib/onesignal/models/export_players_success_response.rb +219 -0
  107. data/lib/onesignal/models/filter.rb +294 -0
  108. data/lib/onesignal/models/filter_expressions.rb +336 -0
  109. data/lib/onesignal/models/generic_error.rb +221 -0
  110. data/lib/onesignal/models/generic_error_errors_inner.rb +228 -0
  111. data/lib/onesignal/models/get_notification_request_body.rb +273 -0
  112. data/lib/onesignal/models/inline_response200.rb +221 -0
  113. data/lib/onesignal/models/inline_response2003.rb +221 -0
  114. data/lib/onesignal/models/inline_response201.rb +219 -0
  115. data/lib/onesignal/models/inline_response202.rb +219 -0
  116. data/lib/onesignal/models/invalid_identifier_error.rb +234 -0
  117. data/lib/onesignal/models/notification.rb +1442 -0
  118. data/lib/onesignal/models/notification200_errors.rb +105 -0
  119. data/lib/onesignal/models/notification_all_of.rb +221 -0
  120. data/lib/onesignal/models/notification_history_success_response.rb +228 -0
  121. data/lib/onesignal/models/notification_slice.rb +248 -0
  122. data/lib/onesignal/models/notification_target.rb +429 -0
  123. data/lib/onesignal/models/notification_with_meta.rb +1546 -0
  124. data/lib/onesignal/models/notification_with_meta_all_of.rb +323 -0
  125. data/lib/onesignal/models/operator.rb +254 -0
  126. data/lib/onesignal/models/outcome_data.rb +286 -0
  127. data/lib/onesignal/models/outcomes_data.rb +221 -0
  128. data/lib/onesignal/models/platform_delivery_data.rb +285 -0
  129. data/lib/onesignal/models/platform_delivery_data_email_all_of.rb +287 -0
  130. data/lib/onesignal/models/platform_delivery_data_sms_all_of.rb +243 -0
  131. data/lib/onesignal/models/player.rb +494 -0
  132. data/lib/onesignal/models/player_notification_target.rb +385 -0
  133. data/lib/onesignal/models/player_notification_target_include_aliases.rb +221 -0
  134. data/lib/onesignal/models/player_slice.rb +248 -0
  135. data/lib/onesignal/models/properties_deltas.rb +239 -0
  136. data/lib/onesignal/models/properties_object.rb +313 -0
  137. data/lib/onesignal/models/purchase.rb +264 -0
  138. data/lib/onesignal/models/rate_limiter_error.rb +221 -0
  139. data/lib/onesignal/models/segment.rb +252 -0
  140. data/lib/onesignal/models/segment_notification_target.rb +234 -0
  141. data/lib/onesignal/models/string_map.rb +640 -0
  142. data/lib/onesignal/models/subscription_object.rb +397 -0
  143. data/lib/onesignal/models/transfer_subscription_request_body.rb +221 -0
  144. data/lib/onesignal/models/update_live_activity_request.rb +309 -0
  145. data/lib/onesignal/models/update_live_activity_success_response.rb +228 -0
  146. data/lib/onesignal/models/update_player_success_response.rb +219 -0
  147. data/lib/onesignal/models/update_player_tags_request_body.rb +220 -0
  148. data/lib/onesignal/models/update_player_tags_success_response.rb +219 -0
  149. data/lib/onesignal/models/update_subscription_request_body.rb +219 -0
  150. data/lib/onesignal/models/update_user_request.rb +239 -0
  151. data/lib/onesignal/models/user.rb +250 -0
  152. data/lib/onesignal/models/user_identity_request_body.rb +221 -0
  153. data/lib/onesignal/models/user_identity_response.rb +221 -0
  154. data/lib/onesignal/models/user_subscription_options.rb +219 -0
  155. data/lib/onesignal/version.rb +15 -0
  156. data/lib/onesignal.rb +111 -0
  157. data/onesignal.gemspec +38 -0
  158. data/spec/api/default_api_spec.rb +522 -0
  159. data/spec/api_client_spec.rb +226 -0
  160. data/spec/configuration_spec.rb +42 -0
  161. data/spec/models/app_spec.rb +236 -0
  162. data/spec/models/basic_notification_all_of_android_background_layout_spec.rb +46 -0
  163. data/spec/models/basic_notification_all_of_spec.rb +584 -0
  164. data/spec/models/basic_notification_spec.rb +672 -0
  165. data/spec/models/begin_live_activity_request_spec.rb +40 -0
  166. data/spec/models/button_spec.rb +46 -0
  167. data/spec/models/cancel_notification_success_response_spec.rb +34 -0
  168. data/spec/models/create_notification_success_response_spec.rb +52 -0
  169. data/spec/models/create_player_success_response_spec.rb +40 -0
  170. data/spec/models/create_segment_conflict_response_spec.rb +40 -0
  171. data/spec/models/create_segment_success_response_spec.rb +40 -0
  172. data/spec/models/create_subscription_request_body_spec.rb +40 -0
  173. data/spec/models/create_user_conflict_response_errors_inner_spec.rb +46 -0
  174. data/spec/models/create_user_conflict_response_errors_items_meta_spec.rb +34 -0
  175. data/spec/models/create_user_conflict_response_spec.rb +34 -0
  176. data/spec/models/delete_player_not_found_response_spec.rb +34 -0
  177. data/spec/models/delete_player_success_response_spec.rb +34 -0
  178. data/spec/models/delete_segment_not_found_response_spec.rb +34 -0
  179. data/spec/models/delete_segment_success_response_spec.rb +34 -0
  180. data/spec/models/delivery_data_spec.rb +58 -0
  181. data/spec/models/export_events_success_response_spec.rb +34 -0
  182. data/spec/models/export_players_request_body_spec.rb +46 -0
  183. data/spec/models/export_players_success_response_spec.rb +34 -0
  184. data/spec/models/filter_expressions_spec.rb +66 -0
  185. data/spec/models/filter_spec.rb +56 -0
  186. data/spec/models/generic_error_errors_inner_spec.rb +40 -0
  187. data/spec/models/generic_error_spec.rb +34 -0
  188. data/spec/models/get_notification_request_body_spec.rb +50 -0
  189. data/spec/models/inline_response2003_spec.rb +34 -0
  190. data/spec/models/inline_response200_spec.rb +34 -0
  191. data/spec/models/inline_response201_spec.rb +34 -0
  192. data/spec/models/inline_response202_spec.rb +34 -0
  193. data/spec/models/invalid_identifier_error_spec.rb +40 -0
  194. data/spec/models/notification200_errors_spec.rb +31 -0
  195. data/spec/models/notification_all_of_spec.rb +34 -0
  196. data/spec/models/notification_history_success_response_spec.rb +40 -0
  197. data/spec/models/notification_slice_spec.rb +52 -0
  198. data/spec/models/notification_spec.rb +678 -0
  199. data/spec/models/notification_target_spec.rb +116 -0
  200. data/spec/models/notification_with_meta_all_of_spec.rb +94 -0
  201. data/spec/models/notification_with_meta_spec.rb +738 -0
  202. data/spec/models/operator_spec.rb +38 -0
  203. data/spec/models/outcome_data_spec.rb +50 -0
  204. data/spec/models/outcomes_data_spec.rb +34 -0
  205. data/spec/models/platform_delivery_data_email_all_of_spec.rb +70 -0
  206. data/spec/models/platform_delivery_data_sms_all_of_spec.rb +46 -0
  207. data/spec/models/platform_delivery_data_spec.rb +76 -0
  208. data/spec/models/player_notification_target_include_aliases_spec.rb +34 -0
  209. data/spec/models/player_notification_target_spec.rb +104 -0
  210. data/spec/models/player_slice_spec.rb +52 -0
  211. data/spec/models/player_spec.rb +190 -0
  212. data/spec/models/properties_deltas_spec.rb +46 -0
  213. data/spec/models/properties_object_spec.rb +94 -0
  214. data/spec/models/purchase_spec.rb +52 -0
  215. data/spec/models/rate_limiter_error_spec.rb +34 -0
  216. data/spec/models/segment_notification_target_spec.rb +40 -0
  217. data/spec/models/segment_spec.rb +46 -0
  218. data/spec/models/string_map_spec.rb +286 -0
  219. data/spec/models/subscription_object_spec.rb +134 -0
  220. data/spec/models/transfer_subscription_request_body_spec.rb +34 -0
  221. data/spec/models/update_live_activity_request_spec.rb +60 -0
  222. data/spec/models/update_live_activity_success_response_spec.rb +40 -0
  223. data/spec/models/update_player_success_response_spec.rb +34 -0
  224. data/spec/models/update_player_tags_request_body_spec.rb +34 -0
  225. data/spec/models/update_player_tags_success_response_spec.rb +34 -0
  226. data/spec/models/update_subscription_request_body_spec.rb +34 -0
  227. data/spec/models/update_user_request_spec.rb +46 -0
  228. data/spec/models/user_identity_request_body_spec.rb +34 -0
  229. data/spec/models/user_identity_response_spec.rb +34 -0
  230. data/spec/models/user_spec.rb +52 -0
  231. data/spec/models/user_subscription_options_spec.rb +34 -0
  232. data/spec/spec_helper.rb +111 -0
  233. metadata +389 -0
@@ -0,0 +1,393 @@
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.2.2
7
+ Contact: devrel@onesignal.com
8
+ Generated by: https://openapi-generator.tech
9
+ OpenAPI Generator version: 6.0.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
+ opts[:header_params]['OS-Usage-Data'] = 'kind=sdk, sdk-name=onesignal-ruby, version=1.2.2'
94
+ header_params = @default_headers.merge(opts[:header_params] || {})
95
+ query_params = opts[:query_params] || {}
96
+ form_params = opts[:form_params] || {}
97
+ follow_location = opts[:follow_location] || true
98
+
99
+ update_params_for_auth! header_params, query_params, opts[:auth_names]
100
+
101
+ # set ssl_verifyhosts option based on @config.verify_ssl_host (true/false)
102
+ _verify_ssl_host = @config.verify_ssl_host ? 2 : 0
103
+
104
+ req_opts = {
105
+ :method => http_method,
106
+ :headers => header_params,
107
+ :params => query_params,
108
+ :params_encoding => @config.params_encoding,
109
+ :timeout => @config.timeout,
110
+ :ssl_verifypeer => @config.verify_ssl,
111
+ :ssl_verifyhost => _verify_ssl_host,
112
+ :sslcert => @config.cert_file,
113
+ :sslkey => @config.key_file,
114
+ :verbose => @config.debugging,
115
+ :followlocation => follow_location
116
+ }
117
+
118
+ # set custom cert, if provided
119
+ req_opts[:cainfo] = @config.ssl_ca_cert if @config.ssl_ca_cert
120
+
121
+ if [:post, :patch, :put, :delete].include?(http_method)
122
+ req_body = build_request_body(header_params, form_params, opts[:body])
123
+ req_opts.update :body => req_body
124
+ if @config.debugging
125
+ @config.logger.debug "HTTP request body param ~BEGIN~\n#{req_body}\n~END~\n"
126
+ end
127
+ end
128
+
129
+ request = Typhoeus::Request.new(url, req_opts)
130
+ download_file(request) if opts[:return_type] == 'File'
131
+ request
132
+ end
133
+
134
+ # Builds the HTTP request body
135
+ #
136
+ # @param [Hash] header_params Header parameters
137
+ # @param [Hash] form_params Query parameters
138
+ # @param [Object] body HTTP body (JSON/XML)
139
+ # @return [String] HTTP body data in the form of string
140
+ def build_request_body(header_params, form_params, body)
141
+ # http form
142
+ if header_params['Content-Type'] == 'application/x-www-form-urlencoded' ||
143
+ header_params['Content-Type'] == 'multipart/form-data'
144
+ data = {}
145
+ form_params.each do |key, value|
146
+ case value
147
+ when ::File, ::Array, nil
148
+ # let typhoeus handle File, Array and nil parameters
149
+ data[key] = value
150
+ else
151
+ data[key] = value.to_s
152
+ end
153
+ end
154
+ elsif body
155
+ data = body.is_a?(String) ? body : body.to_json
156
+ else
157
+ data = nil
158
+ end
159
+ data
160
+ end
161
+
162
+ # Save response body into a file in (the defined) temporary folder, using the filename
163
+ # from the "Content-Disposition" header if provided, otherwise a random filename.
164
+ # The response body is written to the file in chunks in order to handle files which
165
+ # size is larger than maximum Ruby String or even larger than the maximum memory a Ruby
166
+ # process can use.
167
+ #
168
+ # @see Configuration#temp_folder_path
169
+ def download_file(request)
170
+ tempfile = nil
171
+ encoding = nil
172
+ request.on_headers do |response|
173
+ content_disposition = response.headers['Content-Disposition']
174
+ if content_disposition && content_disposition =~ /filename=/i
175
+ filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1]
176
+ prefix = sanitize_filename(filename)
177
+ else
178
+ prefix = 'download-'
179
+ end
180
+ prefix = prefix + '-' unless prefix.end_with?('-')
181
+ encoding = response.body.encoding
182
+ tempfile = Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding)
183
+ @tempfile = tempfile
184
+ end
185
+ request.on_body do |chunk|
186
+ chunk.force_encoding(encoding)
187
+ tempfile.write(chunk)
188
+ end
189
+ request.on_complete do |response|
190
+ if tempfile
191
+ tempfile.close
192
+ @config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\
193
+ "with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
194
+ "will be deleted automatically with GC. It's also recommended to delete the temp file "\
195
+ "explicitly with `tempfile.delete`"
196
+ end
197
+ end
198
+ end
199
+
200
+ # Check if the given MIME is a JSON MIME.
201
+ # JSON MIME examples:
202
+ # application/json
203
+ # application/json; charset=UTF8
204
+ # APPLICATION/JSON
205
+ # */*
206
+ # @param [String] mime MIME
207
+ # @return [Boolean] True if the MIME is application/json
208
+ def json_mime?(mime)
209
+ (mime == '*/*') || !(mime =~ /Application\/.*json(?!p)(;.*)?/i).nil?
210
+ end
211
+
212
+ # Deserialize the response to the given return type.
213
+ #
214
+ # @param [Response] response HTTP response
215
+ # @param [String] return_type some examples: "User", "Array<User>", "Hash<String, Integer>"
216
+ def deserialize(response, return_type)
217
+ body = response.body
218
+
219
+ # handle file downloading - return the File instance processed in request callbacks
220
+ # note that response body is empty when the file is written in chunks in request on_body callback
221
+ return @tempfile if return_type == 'File'
222
+
223
+ return nil if body.nil? || body.empty?
224
+
225
+ # return response body directly for String return type
226
+ return body if return_type == 'String'
227
+
228
+ # ensuring a default content type
229
+ content_type = response.headers['Content-Type'] || 'application/json'
230
+
231
+ fail "Content-Type is not supported: #{content_type}" unless json_mime?(content_type)
232
+
233
+ begin
234
+ data = JSON.parse("[#{body}]", :symbolize_names => true)[0]
235
+ rescue JSON::ParserError => e
236
+ if %w(String Date Time).include?(return_type)
237
+ data = body
238
+ else
239
+ raise e
240
+ end
241
+ end
242
+
243
+ convert_to_type data, return_type
244
+ end
245
+
246
+ # Convert data to the given return type.
247
+ # @param [Object] data Data to be converted
248
+ # @param [String] return_type Return type
249
+ # @return [Mixed] Data in a particular type
250
+ def convert_to_type(data, return_type)
251
+ return nil if data.nil?
252
+ case return_type
253
+ when 'String'
254
+ data.to_s
255
+ when 'Integer'
256
+ data.to_i
257
+ when 'Float'
258
+ data.to_f
259
+ when 'Boolean'
260
+ data == true
261
+ when 'Time'
262
+ # parse date time (expecting ISO 8601 format)
263
+ Time.parse data
264
+ when 'Date'
265
+ # parse date time (expecting ISO 8601 format)
266
+ Date.parse data
267
+ when 'Object'
268
+ # generic object (usually a Hash), return directly
269
+ data
270
+ when /\AArray<(.+)>\z/
271
+ # e.g. Array<Pet>
272
+ sub_type = $1
273
+ data.map { |item| convert_to_type(item, sub_type) }
274
+ when /\AHash\<String, (.+)\>\z/
275
+ # e.g. Hash<String, Integer>
276
+ sub_type = $1
277
+ {}.tap do |hash|
278
+ data.each { |k, v| hash[k] = convert_to_type(v, sub_type) }
279
+ end
280
+ else
281
+ # models (e.g. Pet) or oneOf
282
+ klass = OneSignal.const_get(return_type)
283
+ klass.respond_to?(:openapi_one_of) ? klass.build(data) : klass.build_from_hash(data)
284
+ end
285
+ end
286
+
287
+ # Sanitize filename by removing path.
288
+ # e.g. ../../sun.gif becomes sun.gif
289
+ #
290
+ # @param [String] filename the filename to be sanitized
291
+ # @return [String] the sanitized filename
292
+ def sanitize_filename(filename)
293
+ filename.gsub(/.*[\/\\]/, '')
294
+ end
295
+
296
+ def build_request_url(path, opts = {})
297
+ # Add leading and trailing slashes to path
298
+ path = "/#{path}".gsub(/\/+/, '/')
299
+ @config.base_url(opts[:operation]) + path
300
+ end
301
+
302
+ # Update header and query params based on authentication settings.
303
+ #
304
+ # @param [Hash] header_params Header parameters
305
+ # @param [Hash] query_params Query parameters
306
+ # @param [String] auth_names Authentication scheme name
307
+ def update_params_for_auth!(header_params, query_params, auth_names)
308
+ Array(auth_names).each do |auth_name|
309
+ auth_setting = @config.auth_settings[auth_name]
310
+ next unless auth_setting
311
+ case auth_setting[:in]
312
+ when 'header' then header_params[auth_setting[:key]] = auth_setting[:value]
313
+ when 'query' then query_params[auth_setting[:key]] = auth_setting[:value]
314
+ else fail ArgumentError, 'Authentication token must be in `query` or `header`'
315
+ end
316
+ end
317
+ end
318
+
319
+ # Sets user agent in HTTP header
320
+ #
321
+ # @param [String] user_agent User agent (e.g. openapi-generator/ruby/1.0.0)
322
+ def user_agent=(user_agent)
323
+ @user_agent = user_agent
324
+ @default_headers['User-Agent'] = @user_agent
325
+ end
326
+
327
+ # Return Accept header based on an array of accepts provided.
328
+ # @param [Array] accepts array for Accept
329
+ # @return [String] the Accept header (e.g. application/json)
330
+ def select_header_accept(accepts)
331
+ return nil if accepts.nil? || accepts.empty?
332
+ # use JSON when present, otherwise use all of the provided
333
+ json_accept = accepts.find { |s| json_mime?(s) }
334
+ json_accept || accepts.join(',')
335
+ end
336
+
337
+ # Return Content-Type header based on an array of content types provided.
338
+ # @param [Array] content_types array for Content-Type
339
+ # @return [String] the Content-Type header (e.g. application/json)
340
+ def select_header_content_type(content_types)
341
+ # return nil by default
342
+ return if content_types.nil? || content_types.empty?
343
+ # use JSON when present, otherwise use the first one
344
+ json_content_type = content_types.find { |s| json_mime?(s) }
345
+ json_content_type || content_types.first
346
+ end
347
+
348
+ # Convert object (array, hash, object, etc) to JSON string.
349
+ # @param [Object] model object to be converted into JSON string
350
+ # @return [String] JSON string representation of the object
351
+ def object_to_http_body(model)
352
+ return model if model.nil? || model.is_a?(String)
353
+ local_body = nil
354
+ if model.is_a?(Array)
355
+ local_body = model.map { |m| object_to_hash(m) }
356
+ else
357
+ local_body = object_to_hash(model)
358
+ end
359
+ local_body.to_json
360
+ end
361
+
362
+ # Convert object(non-array) to hash.
363
+ # @param [Object] obj object to be converted into JSON string
364
+ # @return [String] JSON string representation of the object
365
+ def object_to_hash(obj)
366
+ if obj.respond_to?(:to_hash)
367
+ obj.to_hash
368
+ else
369
+ obj
370
+ end
371
+ end
372
+
373
+ # Build parameter value according to the given collection format.
374
+ # @param [String] collection_format one of :csv, :ssv, :tsv, :pipes and :multi
375
+ def build_collection_param(param, collection_format)
376
+ case collection_format
377
+ when :csv
378
+ param.join(',')
379
+ when :ssv
380
+ param.join(' ')
381
+ when :tsv
382
+ param.join("\t")
383
+ when :pipes
384
+ param.join('|')
385
+ when :multi
386
+ # return the array directly as typhoeus will handle it as expected
387
+ param
388
+ else
389
+ fail "unknown collection format: #{collection_format.inspect}"
390
+ end
391
+ end
392
+ end
393
+ 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.2.2
7
+ Contact: devrel@onesignal.com
8
+ Generated by: https://openapi-generator.tech
9
+ OpenAPI Generator version: 6.0.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,245 @@
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.2.2
7
+ Contact: devrel@onesignal.com
8
+ Generated by: https://openapi-generator.tech
9
+ OpenAPI Generator version: 6.0.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
+
114
+ attr_accessor :inject_format
115
+
116
+ attr_accessor :force_ending_format
117
+
118
+ def initialize
119
+ @scheme = 'https'
120
+ @host = 'onesignal.com'
121
+ @base_path = '/api/v1'
122
+ @server_index = 0
123
+ @server_operation_index = {}
124
+ @server_variables = {}
125
+ @server_operation_variables = {}
126
+ @timeout = 0
127
+ @client_side_validation = true
128
+ @verify_ssl = true
129
+ @verify_ssl_host = true
130
+ @cert_file = nil
131
+ @key_file = nil
132
+ @timeout = 0
133
+ @params_encoding = nil
134
+ @debugging = false
135
+ @inject_format = false
136
+ @force_ending_format = false
137
+ @logger = defined?(Rails) ? Rails.logger : Logger.new(STDOUT)
138
+
139
+ yield(self) if block_given?
140
+ end
141
+
142
+ # The default Configuration object.
143
+ def self.default
144
+ @@default ||= Configuration.new
145
+ end
146
+
147
+ def configure
148
+ yield(self) if block_given?
149
+ end
150
+
151
+ def scheme=(scheme)
152
+ # remove :// from scheme
153
+ @scheme = scheme.sub(/:\/\//, '')
154
+ end
155
+
156
+ def host=(host)
157
+ # remove http(s):// and anything after a slash
158
+ @host = host.sub(/https?:\/\//, '').split('/').first
159
+ end
160
+
161
+ def base_path=(base_path)
162
+ # Add leading and trailing slashes to base_path
163
+ @base_path = "/#{base_path}".gsub(/\/+/, '/')
164
+ @base_path = '' if @base_path == '/'
165
+ end
166
+
167
+ # Returns base URL for specified operation based on server settings
168
+ def base_url(operation = nil)
169
+ index = server_operation_index.fetch(operation, server_index)
170
+ return "#{scheme}://#{[host, base_path].join('/').gsub(/\/+/, '/')}".sub(/\/+\z/, '') if index == nil
171
+
172
+ server_url(index, server_operation_variables.fetch(operation, server_variables), operation_server_settings[operation])
173
+ end
174
+
175
+ # Returns Auth Settings hash for api client.
176
+ def auth_settings
177
+ {
178
+ 'app_key' =>
179
+ {
180
+ type: 'bearer',
181
+ in: 'header',
182
+ key: 'Authorization',
183
+ value: "Bearer token=\"#{ app_key }\""
184
+ },
185
+ 'user_key' =>
186
+ {
187
+ type: 'bearer',
188
+ in: 'header',
189
+ key: 'Authorization',
190
+ value: "Bearer token=\"#{ user_key }\""
191
+ },
192
+ }
193
+ end
194
+
195
+ # Returns an array of Server setting
196
+ def server_settings
197
+ [
198
+ {
199
+ url: "https://onesignal.com/api/v1",
200
+ description: "No description provided",
201
+ }
202
+ ]
203
+ end
204
+
205
+ def operation_server_settings
206
+ {
207
+ }
208
+ end
209
+
210
+ # Returns URL based on server settings
211
+ #
212
+ # @param index array index of the server settings
213
+ # @param variables hash of variable and the corresponding value
214
+ def server_url(index, variables = {}, servers = nil)
215
+ servers = server_settings if servers == nil
216
+
217
+ # check array index out of bound
218
+ if (index < 0 || index >= servers.size)
219
+ fail ArgumentError, "Invalid index #{index} when selecting the server. Must be less than #{servers.size}"
220
+ end
221
+
222
+ server = servers[index]
223
+ url = server[:url]
224
+
225
+ return url unless server.key? :variables
226
+
227
+ # go through variable and assign a value
228
+ server[:variables].each do |name, variable|
229
+ if variables.key?(name)
230
+ if (!server[:variables][name].key?(:enum_values) || server[:variables][name][:enum_values].include?(variables[name]))
231
+ url.gsub! "{" + name.to_s + "}", variables[name]
232
+ else
233
+ fail ArgumentError, "The variable `#{name}` in the server URL has invalid value #{variables[name]}. Must be #{server[:variables][name][:enum_values]}."
234
+ end
235
+ else
236
+ # use default value
237
+ url.gsub! "{" + name.to_s + "}", server[:variables][name][:default_value]
238
+ end
239
+ end
240
+
241
+ url
242
+ end
243
+
244
+ end
245
+ end