MailchimpMarketing 3.0.7

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 (36) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +7 -0
  3. data/MailchimpMarketing.gemspec +45 -0
  4. data/README.md +378 -0
  5. data/lib/MailchimpMarketing.rb +162 -0
  6. data/lib/MailchimpMarketing/api/activity_feed_api.rb +57 -0
  7. data/lib/MailchimpMarketing/api/authorized_apps_api.rb +78 -0
  8. data/lib/MailchimpMarketing/api/automations_api.rb +351 -0
  9. data/lib/MailchimpMarketing/api/batch_webhooks_api.rb +111 -0
  10. data/lib/MailchimpMarketing/api/batches_api.rb +94 -0
  11. data/lib/MailchimpMarketing/api/campaign_folders_api.rb +111 -0
  12. data/lib/MailchimpMarketing/api/campaigns_api.rb +414 -0
  13. data/lib/MailchimpMarketing/api/connected_sites_api.rb +110 -0
  14. data/lib/MailchimpMarketing/api/conversations_api.rb +124 -0
  15. data/lib/MailchimpMarketing/api/dashboard_api.rb +128 -0
  16. data/lib/MailchimpMarketing/api/ecommerce_api.rb +1139 -0
  17. data/lib/MailchimpMarketing/api/external_auths_api.rb +78 -0
  18. data/lib/MailchimpMarketing/api/facebook_ads_api.rb +66 -0
  19. data/lib/MailchimpMarketing/api/file_manager_api.rb +224 -0
  20. data/lib/MailchimpMarketing/api/landing_pages_api.rb +164 -0
  21. data/lib/MailchimpMarketing/api/lists_api.rb +1302 -0
  22. data/lib/MailchimpMarketing/api/ping_api.rb +39 -0
  23. data/lib/MailchimpMarketing/api/postcards_api.rb +45 -0
  24. data/lib/MailchimpMarketing/api/reporting_api.rb +142 -0
  25. data/lib/MailchimpMarketing/api/reports_api.rb +464 -0
  26. data/lib/MailchimpMarketing/api/root_api.rb +41 -0
  27. data/lib/MailchimpMarketing/api/search_campaigns_api.rb +43 -0
  28. data/lib/MailchimpMarketing/api/search_members_api.rb +44 -0
  29. data/lib/MailchimpMarketing/api/template_folders_api.rb +111 -0
  30. data/lib/MailchimpMarketing/api/templates_api.rb +137 -0
  31. data/lib/MailchimpMarketing/api/verified_domains_api.rb +104 -0
  32. data/lib/MailchimpMarketing/api_client.rb +214 -0
  33. data/lib/MailchimpMarketing/api_error.rb +38 -0
  34. data/lib/MailchimpMarketing/configuration.rb +209 -0
  35. data/lib/MailchimpMarketing/version.rb +15 -0
  36. metadata +257 -0
@@ -0,0 +1,214 @@
1
+ =begin
2
+ #Mailchimp Marketing API
3
+
4
+ #No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen)
5
+
6
+ OpenAPI spec version: 3.0.7
7
+ Contact: apihelp@mailchimp.com
8
+ Generated by: https://github.com/swagger-api/swagger-codegen.git
9
+ Swagger Codegen version: 2.4.12
10
+
11
+ =end
12
+
13
+ require 'json'
14
+ require 'faraday'
15
+
16
+ module MailchimpMarketing
17
+ class ApiClient
18
+ def initialize(config = {})
19
+ @host = "https://server.api.mailchimp.com/3.0"
20
+ @user_agent = "Swagger-Codegen/#{VERSION}/ruby"
21
+ set_config(config)
22
+ end
23
+
24
+ def self.default
25
+ @@default ||= ApiClient.new
26
+ end
27
+
28
+ def get_server_from_api_key(api_key = '')
29
+ begin
30
+ split = api_key.split('-')
31
+ server = 'invalid-server'
32
+ if split.length == 2
33
+ server = split[1]
34
+ end
35
+ server
36
+ rescue
37
+ ""
38
+ end
39
+ end
40
+
41
+ def set_config(config = {})
42
+ @api_key = config[:api_key] || ''
43
+ @is_basic_auth = @api_key.to_s.strip.empty? == false
44
+ @access_token = config[:access_token] || ''
45
+ @is_oauth = @access_token.to_s.strip.empty? == false
46
+
47
+ # If using Basic auth and no server is provided,
48
+ # attempt to extract it from the api_key directy.
49
+ @server = config[:server] || 'invalid-server'
50
+ if @server == 'invalid-server' && @is_basic_auth
51
+ @server = get_server_from_api_key(@api_key)
52
+ end
53
+ end
54
+
55
+ def call_api(http_method, path, opts = {})
56
+ header_params = {
57
+ 'Content-Type' => 'application/json',
58
+ 'User-Agent' => @user_agent
59
+ }
60
+ query_params = opts[:query_params] || {}
61
+ form_params = opts[:form_params] || {}
62
+
63
+ body = {}
64
+ if [:post, :patch, :put, :delete].include?(http_method.to_sym.downcase)
65
+ body = build_request_body(header_params, form_params, opts[:body])
66
+ end
67
+
68
+ res = request(http_method, path, query_params, header_params, body)
69
+
70
+ if res.status <= 200
71
+ data = JSON.parse(res.body)
72
+ data
73
+ else
74
+ fail ApiError.new(res.body)
75
+ end
76
+ end
77
+
78
+ def request(http_method, path, query_params = nil, header_params = nil, body = nil)
79
+ host = @server.length > 0 ? @host.sub('server', @server) : @host
80
+ url = host + path
81
+
82
+ # Apply Authentication
83
+ conn = Faraday.new(url) do |conn|
84
+ conn.headers = header_params
85
+ conn.params = query_params
86
+
87
+ if @is_basic_auth
88
+ conn.basic_auth('user', @api_key)
89
+ elsif @is_oauth
90
+ conn.headers["Authorization"] = "Bearer #{@access_token}"
91
+ end
92
+ end
93
+
94
+ case http_method.to_sym.downcase
95
+ when :delete
96
+ conn.delete do |req|
97
+ req.body = body
98
+ end
99
+ when :get
100
+ conn.get
101
+ when :head
102
+ conn.head
103
+ when :options
104
+ conn.options
105
+ when :post
106
+ conn.post do |req|
107
+ req.body = body
108
+ end
109
+ when :put
110
+ conn.put do |req|
111
+ req.body = body
112
+ end
113
+ when :patch
114
+ conn.patch do |req|
115
+ req.body = body
116
+ end
117
+ else
118
+ fail ApiError.new('Invalid http_method')
119
+ end
120
+ end
121
+
122
+ # Sanitize filename by removing path.
123
+ # e.g. ../../sun.gif becomes sun.gif
124
+ def sanitize_filename(filename)
125
+ filename.gsub(/.*[\/\\]/, '')
126
+ end
127
+
128
+ # Add leading and trailing slashes to path
129
+ def build_request_url(path)
130
+ path = "/#{path}".gsub(/\/+/, '/')
131
+ URI.encode(@config.base_url + path)
132
+ end
133
+
134
+ # Format HTTP request body
135
+ def build_request_body(header_params, form_params, body)
136
+ if header_params['Content-Type'] == 'application/x-www-form-urlencoded' ||
137
+ header_params['Content-Type'] == 'multipart/form-data'
138
+ data = {}
139
+ form_params.each do |key, value|
140
+ case value
141
+ when ::File, ::Array, nil
142
+ data[key] = value
143
+ else
144
+ data[key] = value.to_s
145
+ end
146
+ end
147
+ elsif body
148
+ data = body.is_a?(String) ? body : body.to_json
149
+ else
150
+ data = nil
151
+ end
152
+ data
153
+ end
154
+
155
+ # Return Accept header based on an array of accepts provided.
156
+ def select_header_accept(accepts)
157
+ return nil if accepts.nil? || accepts.empty?
158
+ json_accept = accepts.find { |s| json_mime?(s) }
159
+ json_accept || accepts.join(',')
160
+ end
161
+
162
+ # Return Content-Type header based on an array of content types provided.
163
+ def select_header_content_type(content_types)
164
+ return 'application/json' if content_types.nil? || content_types.empty?
165
+
166
+ json_content_type = content_types.find { |s| json_mime?(s) }
167
+ json_content_type || content_types.first
168
+ end
169
+
170
+ # Convert object (array, hash, object, etc) to JSON string.
171
+ def object_to_http_body(model)
172
+ return model if model.nil? || model.is_a?(String)
173
+ local_body = nil
174
+ if model.is_a?(Array)
175
+ local_body = model.map { |m| object_to_hash(m) }
176
+ else
177
+ local_body = object_to_hash(model)
178
+ end
179
+ local_body.to_json
180
+ end
181
+
182
+ # Convert object(non-array) to hash.
183
+ def object_to_hash(obj)
184
+ if obj.respond_to?(:to_hash)
185
+ obj.to_hash
186
+ else
187
+ obj
188
+ end
189
+ end
190
+
191
+ # Build parameter value according to the given collection format.
192
+ def build_collection_param(param, collection_format)
193
+ case collection_format
194
+ when :csv
195
+ param.join(',')
196
+ when :ssv
197
+ param.join(' ')
198
+ when :tsv
199
+ param.join("\t")
200
+ when :pipes
201
+ param.join('|')
202
+ when :multi
203
+ param
204
+ else
205
+ fail "unknown collection format: #{collection_format.inspect}"
206
+ end
207
+ end
208
+
209
+ # Check if the given MIME is a JSON MIME.
210
+ def json_mime?(mime)
211
+ (mime == '*/*') || !(mime =~ /Application\/.*json(?!p)(;.*)?/i).nil?
212
+ end
213
+ end
214
+ end
@@ -0,0 +1,38 @@
1
+ =begin
2
+ #Mailchimp Marketing API
3
+
4
+ #No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen)
5
+
6
+ OpenAPI spec version: 3.0.7
7
+ Contact: apihelp@mailchimp.com
8
+ Generated by: https://github.com/swagger-api/swagger-codegen.git
9
+ Swagger Codegen version: 2.4.12
10
+
11
+ =end
12
+
13
+ module MailchimpMarketing
14
+ class ApiError < StandardError
15
+ attr_reader :status, :type, :title, :detail, :instance, :errors
16
+
17
+ # Usage examples:
18
+ # ApiError.new
19
+ # ApiError.new("message")
20
+ # ApiError.new(:status => 500, :response_headers => {}, :response_body => "")
21
+ # ApiError.new(:status => 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
+ end
38
+ end
@@ -0,0 +1,209 @@
1
+ =begin
2
+ #Mailchimp Marketing API
3
+
4
+ #No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen)
5
+
6
+ OpenAPI spec version: 3.0.7
7
+ Contact: apihelp@mailchimp.com
8
+ Generated by: https://github.com/swagger-api/swagger-codegen.git
9
+ Swagger Codegen version: 2.4.12
10
+
11
+ =end
12
+
13
+ require 'uri'
14
+
15
+ module MailchimpMarketing
16
+ class Configuration
17
+ # Defines url scheme
18
+ attr_accessor :scheme
19
+
20
+ # Defines url host
21
+ attr_accessor :host
22
+
23
+ # Defines url base path
24
+ attr_accessor :base_path
25
+
26
+ # Defines API keys used with API Key authentications.
27
+ #
28
+ # @return [Hash] key: parameter name, value: parameter value (API key)
29
+ #
30
+ # @example parameter name is "api_key", API key is "xxx" (e.g. "api_key=xxx" in query string)
31
+ # config.api_key['api_key'] = 'xxx'
32
+ attr_accessor :api_key
33
+
34
+ # Defines API key prefixes used with API Key authentications.
35
+ #
36
+ # @return [Hash] key: parameter name, value: API key prefix
37
+ #
38
+ # @example parameter name is "Authorization", API key prefix is "Token" (e.g. "Authorization: Token xxx" in headers)
39
+ # config.api_key_prefix['api_key'] = 'Token'
40
+ attr_accessor :api_key_prefix
41
+
42
+ # Defines the username used with HTTP basic authentication.
43
+ #
44
+ # @return [String]
45
+ attr_accessor :username
46
+
47
+ # Defines the password used with HTTP basic authentication.
48
+ #
49
+ # @return [String]
50
+ attr_accessor :password
51
+
52
+ # Defines the access token (Bearer) used with OAuth2.
53
+ attr_accessor :access_token
54
+
55
+ # Set this to enable/disable debugging. When enabled (set to true), HTTP request/response
56
+ # details will be logged with `logger.debug` (see the `logger` attribute).
57
+ # Default to false.
58
+ #
59
+ # @return [true, false]
60
+ attr_accessor :debugging
61
+
62
+ # Defines the logger used for debugging.
63
+ # Default to `Rails.logger` (when in Rails) or logging to STDOUT.
64
+ #
65
+ # @return [#debug]
66
+ attr_accessor :logger
67
+
68
+ # Defines the temporary folder to store downloaded files
69
+ # (for API endpoints that have file response).
70
+ # Default to use `Tempfile`.
71
+ #
72
+ # @return [String]
73
+ attr_accessor :temp_folder_path
74
+
75
+ # The time limit for HTTP request in seconds.
76
+ # Default to 0 (never times out).
77
+ attr_accessor :timeout
78
+
79
+ # Set this to false to skip client side validation in the operation.
80
+ # Default to true.
81
+ # @return [true, false]
82
+ attr_accessor :client_side_validation
83
+
84
+ ### TLS/SSL setting
85
+ # Set this to false to skip verifying SSL certificate when calling API from https server.
86
+ # Default to true.
87
+ #
88
+ # @note Do NOT set it to false in production code, otherwise you would face multiple types of cryptographic attacks.
89
+ #
90
+ # @return [true, false]
91
+ attr_accessor :verify_ssl
92
+
93
+ ### TLS/SSL setting
94
+ # Set this to false to skip verifying SSL host name
95
+ # Default to true.
96
+ #
97
+ # @note Do NOT set it to false in production code, otherwise you would face multiple types of cryptographic attacks.
98
+ #
99
+ # @return [true, false]
100
+ attr_accessor :verify_ssl_host
101
+
102
+ ### TLS/SSL setting
103
+ # Set this to customize the certificate file to verify the peer.
104
+ #
105
+ # @return [String] the path to the certificate file
106
+ #
107
+ # @see The `cainfo` option of Typhoeus, `--cert` option of libcurl. Related source code:
108
+ # https://github.com/typhoeus/typhoeus/blob/master/lib/typhoeus/easy_factory.rb#L145
109
+ attr_accessor :ssl_ca_cert
110
+
111
+ ### TLS/SSL setting
112
+ # Client certificate file (for client certificate)
113
+ attr_accessor :cert_file
114
+
115
+ ### TLS/SSL setting
116
+ # Client private key file (for client certificate)
117
+ attr_accessor :key_file
118
+
119
+ # Set this to customize parameters encoding of array parameter with multi collectionFormat.
120
+ # Default to nil.
121
+ #
122
+ # @see The params_encoding option of Ethon. Related source code:
123
+ # https://github.com/typhoeus/ethon/blob/master/lib/ethon/easy/queryable.rb#L96
124
+ attr_accessor :params_encoding
125
+
126
+ attr_accessor :inject_format
127
+
128
+ attr_accessor :force_ending_format
129
+
130
+ def initialize
131
+ @scheme = 'https'
132
+ @host = 'server.api.mailchimp.com'
133
+ @base_path = '/3.0'
134
+ @api_key = {}
135
+ @api_key_prefix = {}
136
+ @timeout = 0
137
+ @client_side_validation = true
138
+ @verify_ssl = true
139
+ @verify_ssl_host = true
140
+ @params_encoding = nil
141
+ @cert_file = nil
142
+ @key_file = nil
143
+ @debugging = false
144
+ @inject_format = false
145
+ @force_ending_format = false
146
+ @logger = defined?(Rails) ? Rails.logger : Logger.new(STDOUT)
147
+
148
+ yield(self) if block_given?
149
+ end
150
+
151
+ # The default Configuration object.
152
+ def self.default
153
+ @@default ||= Configuration.new
154
+ end
155
+
156
+ def configure
157
+ yield(self) if block_given?
158
+ end
159
+
160
+ def scheme=(scheme)
161
+ # remove :// from scheme
162
+ @scheme = scheme.sub(/:\/\//, '')
163
+ end
164
+
165
+ def host=(host)
166
+ # remove http(s):// and anything after a slash
167
+ @host = host.sub(/https?:\/\//, '').split('/').first
168
+ end
169
+
170
+ def base_path=(base_path)
171
+ # Add leading and trailing slashes to base_path
172
+ @base_path = "/#{base_path}".gsub(/\/+/, '/')
173
+ @base_path = '' if @base_path == '/'
174
+ end
175
+
176
+ def base_url
177
+ url = "#{scheme}://#{[host, base_path].join('/').gsub(/\/+/, '/')}".sub(/\/+\z/, '')
178
+ URI.encode(url)
179
+ end
180
+
181
+ # Gets API key (with prefix if set).
182
+ # @param [String] param_name the parameter name of API key auth
183
+ def api_key_with_prefix(param_name)
184
+ if @api_key_prefix[param_name]
185
+ "#{@api_key_prefix[param_name]} #{@api_key[param_name]}"
186
+ else
187
+ @api_key[param_name]
188
+ end
189
+ end
190
+
191
+ # Gets Basic Auth token string
192
+ def basic_auth_token
193
+ 'Basic ' + ["#{username}:#{password}"].pack('m').delete("\r\n")
194
+ end
195
+
196
+ # Returns Auth Settings hash for api client.
197
+ def auth_settings
198
+ {
199
+ 'basicAuth' =>
200
+ {
201
+ type: 'basic',
202
+ in: 'header',
203
+ key: 'Authorization',
204
+ value: basic_auth_token
205
+ },
206
+ }
207
+ end
208
+ end
209
+ end