snap_business 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. checksums.yaml +7 -0
  2. data/lib/snap_business/api/conversion_api.rb +244 -0
  3. data/lib/snap_business/api/default_api.rb +266 -0
  4. data/lib/snap_business/api_client.rb +428 -0
  5. data/lib/snap_business/api_error.rb +57 -0
  6. data/lib/snap_business/configuration.rb +318 -0
  7. data/lib/snap_business/models/capi_event.rb +590 -0
  8. data/lib/snap_business/models/capi_event_ext.rb +58 -0
  9. data/lib/snap_business/models/response.rb +237 -0
  10. data/lib/snap_business/models/response_error_records.rb +228 -0
  11. data/lib/snap_business/models/response_logs.rb +237 -0
  12. data/lib/snap_business/models/response_logs_log.rb +284 -0
  13. data/lib/snap_business/models/response_stats.rb +235 -0
  14. data/lib/snap_business/models/response_stats_data.rb +226 -0
  15. data/lib/snap_business/models/response_stats_test.rb +226 -0
  16. data/lib/snap_business/models/test_response.rb +259 -0
  17. data/lib/snap_business/models/validated_fields.rb +226 -0
  18. data/lib/snap_business/models/validated_fields_items.rb +262 -0
  19. data/lib/snap_business/models/validated_fields_validated_fields.rb +262 -0
  20. data/lib/snap_business/util/capi_hash.rb +61 -0
  21. data/lib/snap_business/util/constants.rb +16 -0
  22. data/lib/snap_business/version.rb +15 -0
  23. data/lib/snap_business.rb +52 -0
  24. data/spec/api/conversion_api_spec.rb +203 -0
  25. data/spec/api/default_api_spec.rb +45 -0
  26. data/spec/api_client_spec.rb +188 -0
  27. data/spec/configuration_spec.rb +42 -0
  28. data/spec/models/capi_event_spec.rb +127 -0
  29. data/spec/spec_helper.rb +111 -0
  30. data/spec/util/capi_hash_spec.rb +62 -0
  31. metadata +178 -0
@@ -0,0 +1,318 @@
1
+ =begin
2
+ #Snap Conversions API
3
+
4
+ #No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
5
+
6
+ The version of the OpenAPI document: 1.0.0
7
+
8
+ Generated by: https://openapi-generator.tech
9
+ OpenAPI Generator version: 6.0.1
10
+
11
+ =end
12
+
13
+ module SnapBusinessSDK
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
+ # Defines API keys used with API Key authentications.
37
+ #
38
+ # @return [Hash] key: parameter name, value: parameter value (API key)
39
+ #
40
+ # @example parameter name is "api_key", API key is "xxx" (e.g. "api_key=xxx" in query string)
41
+ # config.api_key['api_key'] = 'xxx'
42
+ attr_accessor :api_key
43
+
44
+ # Defines API key prefixes used with API Key authentications.
45
+ #
46
+ # @return [Hash] key: parameter name, value: API key prefix
47
+ #
48
+ # @example parameter name is "Authorization", API key prefix is "Token" (e.g. "Authorization: Token xxx" in headers)
49
+ # config.api_key_prefix['api_key'] = 'Token'
50
+ attr_accessor :api_key_prefix
51
+
52
+ # Defines the username used with HTTP basic authentication.
53
+ #
54
+ # @return [String]
55
+ attr_accessor :username
56
+
57
+ # Defines the password used with HTTP basic authentication.
58
+ #
59
+ # @return [String]
60
+ attr_accessor :password
61
+
62
+ # Defines the access token (Bearer) used with OAuth2.
63
+ attr_accessor :access_token
64
+
65
+ # Set this to enable/disable debugging. When enabled (set to true), HTTP request/response
66
+ # details will be logged with `logger.debug` (see the `logger` attribute).
67
+ # Default to false.
68
+ #
69
+ # @return [true, false]
70
+ attr_accessor :debugging
71
+
72
+ # Defines the logger used for debugging.
73
+ # Default to `Rails.logger` (when in Rails) or logging to STDOUT.
74
+ #
75
+ # @return [#debug]
76
+ attr_accessor :logger
77
+
78
+ # Defines the temporary folder to store downloaded files
79
+ # (for API endpoints that have file response).
80
+ # Default to use `Tempfile`.
81
+ #
82
+ # @return [String]
83
+ attr_accessor :temp_folder_path
84
+
85
+ # The time limit for HTTP request in seconds.
86
+ # Default to 0 (never times out).
87
+ attr_accessor :timeout
88
+
89
+ # Set this to false to skip client side validation in the operation.
90
+ # Default to true.
91
+ # @return [true, false]
92
+ attr_accessor :client_side_validation
93
+
94
+ ### TLS/SSL setting
95
+ # Set this to false to skip verifying SSL certificate when calling API from https server.
96
+ # Default to true.
97
+ #
98
+ # @note Do NOT set it to false in production code, otherwise you would face multiple types of cryptographic attacks.
99
+ #
100
+ # @return [true, false]
101
+ attr_accessor :ssl_verify
102
+
103
+ ### TLS/SSL setting
104
+ # Any `OpenSSL::SSL::` constant (see https://ruby-doc.org/stdlib-2.5.1/libdoc/openssl/rdoc/OpenSSL/SSL.html)
105
+ #
106
+ # @note Do NOT set it to false in production code, otherwise you would face multiple types of cryptographic attacks.
107
+ #
108
+ attr_accessor :ssl_verify_mode
109
+
110
+ ### TLS/SSL setting
111
+ # Set this to customize the certificate file to verify the peer.
112
+ #
113
+ # @return [String] the path to the certificate file
114
+ attr_accessor :ssl_ca_file
115
+
116
+ ### TLS/SSL setting
117
+ # Client certificate file (for client certificate)
118
+ attr_accessor :ssl_client_cert
119
+
120
+ ### TLS/SSL setting
121
+ # Client private key file (for client certificate)
122
+ attr_accessor :ssl_client_key
123
+
124
+ ### Proxy setting
125
+ # HTTP Proxy settings
126
+ attr_accessor :proxy
127
+
128
+ # Set this to customize parameters encoder of array parameter.
129
+ # Default to nil. Faraday uses NestedParamsEncoder when nil.
130
+ #
131
+ # @see The params_encoder option of Faraday. Related source code:
132
+ # https://github.com/lostisland/faraday/tree/main/lib/faraday/encoders
133
+ attr_accessor :params_encoder
134
+
135
+
136
+ attr_accessor :inject_format
137
+
138
+ attr_accessor :force_ending_format
139
+
140
+ def initialize
141
+ @scheme = 'https'
142
+ @host = 'tr.snapchat.com'
143
+ @base_path = ''
144
+ @server_index = 0
145
+ @server_operation_index = {}
146
+ @server_variables = {}
147
+ @server_operation_variables = {}
148
+ @api_key = {}
149
+ @api_key_prefix = {}
150
+ @client_side_validation = true
151
+ @ssl_verify = true
152
+ @ssl_verify_mode = nil
153
+ @ssl_ca_file = nil
154
+ @ssl_client_cert = nil
155
+ @ssl_client_key = nil
156
+ @middlewares = []
157
+ @request_middlewares = []
158
+ @response_middlewares = []
159
+ @timeout = 60
160
+ # return data as binary instead of file
161
+ @return_binary_data = false
162
+ @params_encoder = nil
163
+ @debugging = false
164
+ @inject_format = false
165
+ @force_ending_format = false
166
+ @logger = defined?(Rails) ? Rails.logger : Logger.new(STDOUT)
167
+
168
+ yield(self) if block_given?
169
+ end
170
+
171
+ # The default Configuration object.
172
+ def self.default
173
+ @@default ||= Configuration.new
174
+ end
175
+
176
+ def configure
177
+ yield(self) if block_given?
178
+ end
179
+
180
+ def scheme=(scheme)
181
+ # remove :// from scheme
182
+ @scheme = scheme.sub(/:\/\//, '')
183
+ end
184
+
185
+ def host=(host)
186
+ # remove http(s):// and anything after a slash
187
+ @host = host.sub(/https?:\/\//, '').split('/').first
188
+ end
189
+
190
+ def base_path=(base_path)
191
+ # Add leading and trailing slashes to base_path
192
+ @base_path = "/#{base_path}".gsub(/\/+/, '/')
193
+ @base_path = '' if @base_path == '/'
194
+ end
195
+
196
+ # Returns base URL for specified operation based on server settings
197
+ def base_url(operation = nil)
198
+ index = server_operation_index.fetch(operation, server_index)
199
+ return "#{scheme}://#{[host, base_path].join('/').gsub(/\/+/, '/')}".sub(/\/+\z/, '') if index == nil
200
+
201
+ server_url(index, server_operation_variables.fetch(operation, server_variables), operation_server_settings[operation])
202
+ end
203
+
204
+ # Gets API key (with prefix if set).
205
+ # @param [String] param_name the parameter name of API key auth
206
+ def api_key_with_prefix(param_name, param_alias = nil)
207
+ key = @api_key[param_name]
208
+ key = @api_key.fetch(param_alias, key) unless param_alias.nil?
209
+ if @api_key_prefix[param_name]
210
+ "#{@api_key_prefix[param_name]} #{key}"
211
+ else
212
+ key
213
+ end
214
+ end
215
+
216
+ # Gets Basic Auth token string
217
+ def basic_auth_token
218
+ 'Basic ' + ["#{username}:#{password}"].pack('m').delete("\r\n")
219
+ end
220
+
221
+ # Returns Auth Settings hash for api client.
222
+ def auth_settings
223
+ {
224
+ 'bearerAuth' =>
225
+ {
226
+ type: 'bearer',
227
+ in: 'header',
228
+ format: 'JWT',
229
+ key: 'Authorization',
230
+ value: "Bearer #{access_token}"
231
+ },
232
+ }
233
+ end
234
+
235
+ # Returns an array of Server setting
236
+ def server_settings
237
+ [
238
+ {
239
+ url: "https://tr.snapchat.com",
240
+ description: "Production server",
241
+ },
242
+ {
243
+ url: "https://tr-shadow.snapchat.com",
244
+ description: "Staging server",
245
+ }
246
+ ]
247
+ end
248
+
249
+ def operation_server_settings
250
+ {
251
+ }
252
+ end
253
+
254
+ # Returns URL based on server settings
255
+ #
256
+ # @param index array index of the server settings
257
+ # @param variables hash of variable and the corresponding value
258
+ def server_url(index, variables = {}, servers = nil)
259
+ servers = server_settings if servers == nil
260
+
261
+ # check array index out of bound
262
+ if (index < 0 || index >= servers.size)
263
+ fail ArgumentError, "Invalid index #{index} when selecting the server. Must be less than #{servers.size}"
264
+ end
265
+
266
+ server = servers[index]
267
+ url = server[:url]
268
+
269
+ return url unless server.key? :variables
270
+
271
+ # go through variable and assign a value
272
+ server[:variables].each do |name, variable|
273
+ if variables.key?(name)
274
+ if (!server[:variables][name].key?(:enum_values) || server[:variables][name][:enum_values].include?(variables[name]))
275
+ url.gsub! "{" + name.to_s + "}", variables[name]
276
+ else
277
+ fail ArgumentError, "The variable `#{name}` in the server URL has invalid value #{variables[name]}. Must be #{server[:variables][name][:enum_values]}."
278
+ end
279
+ else
280
+ # use default value
281
+ url.gsub! "{" + name.to_s + "}", server[:variables][name][:default_value]
282
+ end
283
+ end
284
+
285
+ url
286
+ end
287
+
288
+ # Adds middleware to the stack
289
+ def use(*middleware)
290
+ @middlewares << middleware
291
+ end
292
+
293
+ # Adds request middleware to the stack
294
+ def request(*middleware)
295
+ @request_middlewares << middleware
296
+ end
297
+
298
+ # Adds response middleware to the stack
299
+ def response(*middleware)
300
+ @response_middlewares << middleware
301
+ end
302
+
303
+ # Set up middleware on the connection
304
+ def configure_middleware(connection)
305
+ @middlewares.each do |middleware|
306
+ connection.use(*middleware)
307
+ end
308
+
309
+ @request_middlewares.each do |middleware|
310
+ connection.request(*middleware)
311
+ end
312
+
313
+ @response_middlewares.each do |middleware|
314
+ connection.response(*middleware)
315
+ end
316
+ end
317
+ end
318
+ end