MailchimpMarketing 3.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.
- checksums.yaml +7 -0
- data/Gemfile +7 -0
- data/MailchimpMarketing.gemspec +45 -0
- data/README.md +369 -0
- data/lib/MailchimpMarketing.rb +163 -0
- data/lib/MailchimpMarketing/api/activity_feed_api.rb +113 -0
- data/lib/MailchimpMarketing/api/authorized_apps_api.rb +171 -0
- data/lib/MailchimpMarketing/api/automations_api.rb +906 -0
- data/lib/MailchimpMarketing/api/batch_webhooks_api.rb +260 -0
- data/lib/MailchimpMarketing/api/batches_api.rb +214 -0
- data/lib/MailchimpMarketing/api/campaign_folders_api.rb +260 -0
- data/lib/MailchimpMarketing/api/campaigns_api.rb +1073 -0
- data/lib/MailchimpMarketing/api/connected_sites_api.rb +257 -0
- data/lib/MailchimpMarketing/api/conversations_api.rb +293 -0
- data/lib/MailchimpMarketing/api/dashboard_api.rb +317 -0
- data/lib/MailchimpMarketing/api/ecommerce_api.rb +3004 -0
- data/lib/MailchimpMarketing/api/external_auths_api.rb +171 -0
- data/lib/MailchimpMarketing/api/facebook_ads_api.rb +133 -0
- data/lib/MailchimpMarketing/api/file_manager_api.rb +566 -0
- data/lib/MailchimpMarketing/api/landing_pages_api.rb +399 -0
- data/lib/MailchimpMarketing/api/lists_api.rb +3457 -0
- data/lib/MailchimpMarketing/api/ping_api.rb +65 -0
- data/lib/MailchimpMarketing/api/postcards_api.rb +77 -0
- data/lib/MailchimpMarketing/api/reporting_api.rb +338 -0
- data/lib/MailchimpMarketing/api/reports_api.rb +1214 -0
- data/lib/MailchimpMarketing/api/root_api.rb +71 -0
- data/lib/MailchimpMarketing/api/search_campaigns_api.rb +74 -0
- data/lib/MailchimpMarketing/api/search_members_api.rb +77 -0
- data/lib/MailchimpMarketing/api/template_folders_api.rb +260 -0
- data/lib/MailchimpMarketing/api/templates_api.rb +331 -0
- data/lib/MailchimpMarketing/api/verified_domains_api.rb +242 -0
- data/lib/MailchimpMarketing/api_client.rb +192 -0
- data/lib/MailchimpMarketing/api_error.rb +38 -0
- data/lib/MailchimpMarketing/configuration.rb +209 -0
- data/lib/MailchimpMarketing/version.rb +15 -0
- metadata +257 -0
@@ -0,0 +1,192 @@
|
|
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.1
|
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
|
+
# Defines the headers to be used in HTTP requests of all API calls by default.
|
19
|
+
#
|
20
|
+
# @return [Hash]
|
21
|
+
attr_accessor :default_headers
|
22
|
+
|
23
|
+
# Initializes the ApiClient
|
24
|
+
def initialize(api_key, server = '')
|
25
|
+
@host = "https://server.api.mailchimp.com/3.0"
|
26
|
+
@user_agent = "Swagger-Codegen/#{VERSION}/ruby"
|
27
|
+
@default_headers = {
|
28
|
+
'Content-Type' => 'application/json',
|
29
|
+
'User-Agent' => @user_agent
|
30
|
+
}
|
31
|
+
|
32
|
+
@api_key = api_key
|
33
|
+
@server = server || get_server_from_api_key(api_key)
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.default
|
37
|
+
@@default ||= ApiClient.new
|
38
|
+
end
|
39
|
+
|
40
|
+
def get_server_from_api_key(api_key = '')
|
41
|
+
begin
|
42
|
+
split = api_key.split('-us', 1)
|
43
|
+
server_prefix = 'us'
|
44
|
+
server = server_prefix + api_key.split('-' + server_prefix, 1)[1]
|
45
|
+
server
|
46
|
+
rescue
|
47
|
+
""
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def set_config(api_key = '', server = '')
|
52
|
+
@api_key = api_key || @api_key
|
53
|
+
@server = server || get_server_from_api_key(api_key) || @server
|
54
|
+
end
|
55
|
+
|
56
|
+
def call_api(http_method, path, opts = {})
|
57
|
+
header_params = @default_headers.merge(opts[:header_params] || {})
|
58
|
+
query_params = opts[:query_params] || {}
|
59
|
+
form_params = opts[:form_params] || {}
|
60
|
+
|
61
|
+
body = nil
|
62
|
+
if [:post, :patch, :put, :delete].include?(http_method)
|
63
|
+
body = build_request_body(header_params, form_params, opts[:body])
|
64
|
+
end
|
65
|
+
|
66
|
+
res = request(http_method, path, query_params, header_params, body)
|
67
|
+
|
68
|
+
data = nil
|
69
|
+
if res.headers['content-type'] && res.headers['content-type'].include?('application/json')
|
70
|
+
data = JSON.parse(res.body)
|
71
|
+
else
|
72
|
+
data = res.body
|
73
|
+
end
|
74
|
+
|
75
|
+
if data
|
76
|
+
if res.status <= 200
|
77
|
+
data
|
78
|
+
else
|
79
|
+
fail ApiError.new(res.body)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def request(http_method, path, query_params = nil, header_params = nil, body = nil)
|
85
|
+
host = @server.length > 0 ? @host.sub('server', @server) : @host
|
86
|
+
url = host + path
|
87
|
+
|
88
|
+
conn = Faraday.new(url, params: query_params, headers: header_params) do |conn|
|
89
|
+
conn.basic_auth('user', @api_key)
|
90
|
+
end
|
91
|
+
|
92
|
+
case http_method.to_sym.downcase
|
93
|
+
when :delete
|
94
|
+
conn.delete(body: body.to_json)
|
95
|
+
when :get
|
96
|
+
conn.get()
|
97
|
+
when :head
|
98
|
+
conn.head()
|
99
|
+
when :options
|
100
|
+
conn.options()
|
101
|
+
when :post
|
102
|
+
conn.post(body: body.to_json)
|
103
|
+
when :put
|
104
|
+
conn.put(body: body.to_json)
|
105
|
+
when :patch
|
106
|
+
conn.patch(body: body.to_json)
|
107
|
+
else
|
108
|
+
fail ApiError.new('http_method must be :post')
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
# Sanitize filename by removing path.
|
113
|
+
# e.g. ../../sun.gif becomes sun.gif
|
114
|
+
#
|
115
|
+
# @param [String] filename the filename to be sanitized
|
116
|
+
# @return [String] the sanitized filename
|
117
|
+
def sanitize_filename(filename)
|
118
|
+
filename.gsub(/.*[\/\\]/, '')
|
119
|
+
end
|
120
|
+
|
121
|
+
def build_request_url(path)
|
122
|
+
# Add leading and trailing slashes to path
|
123
|
+
path = "/#{path}".gsub(/\/+/, '/')
|
124
|
+
URI.encode(@config.base_url + path)
|
125
|
+
end
|
126
|
+
|
127
|
+
# Builds the HTTP request body
|
128
|
+
#
|
129
|
+
# @param [Hash] header_params Header parameters
|
130
|
+
# @param [Hash] form_params Query parameters
|
131
|
+
# @param [Object] body HTTP body (JSON/XML)
|
132
|
+
# @return [String] HTTP body data in the form of string
|
133
|
+
def build_request_body(header_params, form_params, body)
|
134
|
+
# http form
|
135
|
+
if header_params['Content-Type'] == 'application/x-www-form-urlencoded' ||
|
136
|
+
header_params['Content-Type'] == 'multipart/form-data'
|
137
|
+
data = {}
|
138
|
+
form_params.each do |key, value|
|
139
|
+
case value
|
140
|
+
when ::File, ::Array, nil
|
141
|
+
# let typhoeus handle File, Array and nil parameters
|
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
|
+
# @param [Array] accepts array for Accept
|
157
|
+
# @return [String] the Accept header (e.g. application/json)
|
158
|
+
def select_header_accept(accepts)
|
159
|
+
return nil if accepts.nil? || accepts.empty?
|
160
|
+
# use JSON when present, otherwise use all of the provided
|
161
|
+
json_accept = accepts.find { |s| json_mime?(s) }
|
162
|
+
json_accept || accepts.join(',')
|
163
|
+
end
|
164
|
+
|
165
|
+
# Return Content-Type header based on an array of content types provided.
|
166
|
+
# @param [Array] content_types array for Content-Type
|
167
|
+
# @return [String] the Content-Type header (e.g. application/json)
|
168
|
+
def select_header_content_type(content_types)
|
169
|
+
# use application/json by default
|
170
|
+
return 'application/json' if content_types.nil? || content_types.empty?
|
171
|
+
# use JSON when present, otherwise use the first one
|
172
|
+
json_content_type = content_types.find { |s| json_mime?(s) }
|
173
|
+
json_content_type || content_types.first
|
174
|
+
end
|
175
|
+
|
176
|
+
# Check if the given MIME is a JSON MIME.
|
177
|
+
# JSON MIME examples:
|
178
|
+
# application/json
|
179
|
+
# application/json; charset=UTF8
|
180
|
+
# APPLICATION/JSON
|
181
|
+
# */*
|
182
|
+
# @param [String] mime MIME
|
183
|
+
# @return [Boolean] True if the MIME is application/json
|
184
|
+
def json_mime?(mime)
|
185
|
+
(mime == '*/*') || !(mime =~ /Application\/.*json(?!p)(;.*)?/i).nil?
|
186
|
+
end
|
187
|
+
|
188
|
+
|
189
|
+
|
190
|
+
|
191
|
+
end
|
192
|
+
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.1
|
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 :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
|
+
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.1
|
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
|
@@ -0,0 +1,15 @@
|
|
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.1
|
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
|
+
VERSION = '3.0.1'
|
15
|
+
end
|