MailchimpMarketing 3.0.2 → 3.0.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +1 -1
  3. data/MailchimpMarketing.gemspec +2 -2
  4. data/README.md +55 -46
  5. data/lib/MailchimpMarketing.rb +5 -6
  6. data/lib/MailchimpMarketing/api/activity_feed_api.rb +12 -73
  7. data/lib/MailchimpMarketing/api/authorized_apps_api.rb +19 -119
  8. data/lib/MailchimpMarketing/api/automations_api.rb +129 -723
  9. data/lib/MailchimpMarketing/api/batch_webhooks_api.rb +32 -192
  10. data/lib/MailchimpMarketing/api/batches_api.rb +25 -154
  11. data/lib/MailchimpMarketing/api/campaign_folders_api.rb +32 -192
  12. data/lib/MailchimpMarketing/api/campaigns_api.rb +143 -847
  13. data/lib/MailchimpMarketing/api/connected_sites_api.rb +31 -189
  14. data/lib/MailchimpMarketing/api/conversations_api.rb +35 -215
  15. data/lib/MailchimpMarketing/api/dashboard_api.rb +31 -233
  16. data/lib/MailchimpMarketing/api/ecommerce_api.rb +446 -2430
  17. data/lib/MailchimpMarketing/api/external_auths_api.rb +19 -119
  18. data/lib/MailchimpMarketing/api/facebook_ads_api.rb +15 -87
  19. data/lib/MailchimpMarketing/api/file_manager_api.rb +70 -435
  20. data/lib/MailchimpMarketing/api/landing_pages_api.rb +50 -302
  21. data/lib/MailchimpMarketing/api/lists_api.rb +746 -3034
  22. data/lib/MailchimpMarketing/api/ping_api.rb +6 -35
  23. data/lib/MailchimpMarketing/api/postcards_api.rb +8 -43
  24. data/lib/MailchimpMarketing/api/reporting_api.rb +40 -249
  25. data/lib/MailchimpMarketing/api/reports_api.rb +152 -947
  26. data/lib/MailchimpMarketing/api/root_api.rb +6 -39
  27. data/lib/MailchimpMarketing/api/search_campaigns_api.rb +7 -41
  28. data/lib/MailchimpMarketing/api/search_members_api.rb +7 -43
  29. data/lib/MailchimpMarketing/api/template_folders_api.rb +32 -192
  30. data/lib/MailchimpMarketing/api/templates_api.rb +39 -246
  31. data/lib/MailchimpMarketing/api/verified_domains_api.rb +31 -180
  32. data/lib/MailchimpMarketing/api_client.rb +34 -157
  33. data/lib/MailchimpMarketing/api_error.rb +1 -1
  34. data/lib/MailchimpMarketing/configuration.rb +1 -1
  35. data/lib/MailchimpMarketing/version.rb +2 -2
  36. metadata +5 -11
@@ -3,7 +3,7 @@
3
3
 
4
4
  #No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen)
5
5
 
6
- OpenAPI spec version: 3.0.2
6
+ OpenAPI spec version: 3.0.9
7
7
  Contact: apihelp@mailchimp.com
8
8
  Generated by: https://github.com/swagger-api/swagger-codegen.git
9
9
  Swagger Codegen version: 2.4.12
@@ -11,26 +11,14 @@ Swagger Codegen version: 2.4.12
11
11
  =end
12
12
 
13
13
  require 'json'
14
- require 'faraday'
14
+ require 'excon'
15
15
 
16
16
  module MailchimpMarketing
17
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 = '')
18
+ def initialize(config = {})
25
19
  @host = "https://server.api.mailchimp.com/3.0"
26
20
  @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)
21
+ set_config(config)
34
22
  end
35
23
 
36
24
  def self.default
@@ -39,153 +27,58 @@ module MailchimpMarketing
39
27
 
40
28
  def get_server_from_api_key(api_key = '')
41
29
  begin
42
- split = api_key.split('-us', 1)
43
- server_prefix = 'us'
44
- server = server_prefix + api_key.split('-' + server_prefix, 1)[1]
30
+ split = api_key.split('-')
31
+ server = 'invalid-server'
32
+ if split.length == 2
33
+ server = split[1]
34
+ end
45
35
  server
46
36
  rescue
47
37
  ""
48
38
  end
49
39
  end
50
40
 
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
41
+ def set_config(config = {})
42
+ @api_key = config[:api_key] || ''
43
+ @is_basic_auth = @api_key.to_s.strip.empty? == false
55
44
 
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] || {}
45
+ @access_token = config[:access_token] || ''
46
+ @is_oauth = @access_token.to_s.strip.empty? == false
60
47
 
61
- body = {}
62
- if [:post, :patch, :put, :delete].include?(http_method.to_sym.downcase)
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
48
+ # If using Basic auth and no server is provided,
49
+ # attempt to extract it from the api_key directy.
50
+ @server = config[:server] || 'invalid-server'
51
+ if @server == 'invalid-server' && @is_basic_auth
52
+ @server = get_server_from_api_key(@api_key)
81
53
  end
82
54
  end
83
55
 
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
56
+ def call_api(http_method, path, opts = {})
57
+ headers = {'Content-Type' => "application/json"}
58
+ headers[:Authorization] = "Basic #{@api_key}" if @is_basic_auth
59
+ headers[:Authorization] = "Bearer #@access_token" if @is_oauth
87
60
 
88
- conn = Faraday.new(url) do |conn|
89
- conn.params = query_params
90
- conn.headers = header_params
91
- conn.basic_auth('user', @api_key)
92
- end
61
+ host = @server.length > 0 ? @host.sub('server', @server) : @host
62
+ conn = Excon.new(host + path, :headers => headers)
93
63
 
64
+ res = nil
94
65
  case http_method.to_sym.downcase
95
- when :delete
96
- conn.delete do |req|
97
- req.body = body.to_json
98
- end
66
+ when :post, :put, :delete
67
+ res = conn.request(:method => http_method, :body => opts[:body])
99
68
  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.to_json
108
- end
109
- when :put
110
- conn.put do |req|
111
- req.body = body.to_json
112
- end
113
- when :patch
114
- conn.patch do |req|
115
- req.body = body.to_json
116
- end
117
- else
118
- fail ApiError.new('Invalid http_method')
69
+ res = conn.get(:query => opts[:query_params])
119
70
  end
120
- end
121
-
122
- # Sanitize filename by removing path.
123
- # e.g. ../../sun.gif becomes sun.gif
124
- #
125
- # @param [String] filename the filename to be sanitized
126
- # @return [String] the sanitized filename
127
- def sanitize_filename(filename)
128
- filename.gsub(/.*[\/\\]/, '')
129
- end
130
-
131
- def build_request_url(path)
132
- # Add leading and trailing slashes to path
133
- path = "/#{path}".gsub(/\/+/, '/')
134
- URI.encode(@config.base_url + path)
135
- end
136
71
 
137
- # Builds the HTTP request body
138
- #
139
- # @param [Hash] header_params Header parameters
140
- # @param [Hash] form_params Query parameters
141
- # @param [Object] body HTTP body (JSON/XML)
142
- # @return [String] HTTP body data in the form of string
143
- def build_request_body(header_params, form_params, body)
144
- # http form
145
- if header_params['Content-Type'] == 'application/x-www-form-urlencoded' ||
146
- header_params['Content-Type'] == 'multipart/form-data'
147
- data = {}
148
- form_params.each do |key, value|
149
- case value
150
- when ::File, ::Array, nil
151
- # let typhoeus handle File, Array and nil parameters
152
- data[key] = value
153
- else
154
- data[key] = value.to_s
155
- end
156
- end
157
- elsif body
158
- data = body.is_a?(String) ? body : body.to_json
72
+ if res.status == 204
73
+ return "success"
74
+ elsif res.status == 200
75
+ return JSON.parse(res.body)
159
76
  else
160
- data = nil
77
+ return res.body
161
78
  end
162
- data
163
- end
164
-
165
- # Return Accept header based on an array of accepts provided.
166
- # @param [Array] accepts array for Accept
167
- # @return [String] the Accept header (e.g. application/json)
168
- def select_header_accept(accepts)
169
- return nil if accepts.nil? || accepts.empty?
170
- # use JSON when present, otherwise use all of the provided
171
- json_accept = accepts.find { |s| json_mime?(s) }
172
- json_accept || accepts.join(',')
173
- end
174
-
175
- # Return Content-Type header based on an array of content types provided.
176
- # @param [Array] content_types array for Content-Type
177
- # @return [String] the Content-Type header (e.g. application/json)
178
- def select_header_content_type(content_types)
179
- # use application/json by default
180
- return 'application/json' if content_types.nil? || content_types.empty?
181
- # use JSON when present, otherwise use the first one
182
- json_content_type = content_types.find { |s| json_mime?(s) }
183
- json_content_type || content_types.first
184
79
  end
185
80
 
186
81
  # Convert object (array, hash, object, etc) to JSON string.
187
- # @param [Object] model object to be converted into JSON string
188
- # @return [String] JSON string representation of the object
189
82
  def object_to_http_body(model)
190
83
  return model if model.nil? || model.is_a?(String)
191
84
  local_body = nil
@@ -198,8 +91,6 @@ module MailchimpMarketing
198
91
  end
199
92
 
200
93
  # Convert object(non-array) to hash.
201
- # @param [Object] obj object to be converted into JSON string
202
- # @return [String] JSON string representation of the object
203
94
  def object_to_hash(obj)
204
95
  if obj.respond_to?(:to_hash)
205
96
  obj.to_hash
@@ -209,7 +100,6 @@ module MailchimpMarketing
209
100
  end
210
101
 
211
102
  # Build parameter value according to the given collection format.
212
- # @param [String] collection_format one of :csv, :ssv, :tsv, :pipes and :multi
213
103
  def build_collection_param(param, collection_format)
214
104
  case collection_format
215
105
  when :csv
@@ -221,23 +111,10 @@ module MailchimpMarketing
221
111
  when :pipes
222
112
  param.join('|')
223
113
  when :multi
224
- # return the array directly as typhoeus will handle it as expected
225
114
  param
226
115
  else
227
116
  fail "unknown collection format: #{collection_format.inspect}"
228
117
  end
229
118
  end
230
-
231
- # Check if the given MIME is a JSON MIME.
232
- # JSON MIME examples:
233
- # application/json
234
- # application/json; charset=UTF8
235
- # APPLICATION/JSON
236
- # */*
237
- # @param [String] mime MIME
238
- # @return [Boolean] True if the MIME is application/json
239
- def json_mime?(mime)
240
- (mime == '*/*') || !(mime =~ /Application\/.*json(?!p)(;.*)?/i).nil?
241
- end
242
119
  end
243
120
  end
@@ -3,7 +3,7 @@
3
3
 
4
4
  #No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen)
5
5
 
6
- OpenAPI spec version: 3.0.2
6
+ OpenAPI spec version: 3.0.9
7
7
  Contact: apihelp@mailchimp.com
8
8
  Generated by: https://github.com/swagger-api/swagger-codegen.git
9
9
  Swagger Codegen version: 2.4.12
@@ -3,7 +3,7 @@
3
3
 
4
4
  #No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen)
5
5
 
6
- OpenAPI spec version: 3.0.2
6
+ OpenAPI spec version: 3.0.9
7
7
  Contact: apihelp@mailchimp.com
8
8
  Generated by: https://github.com/swagger-api/swagger-codegen.git
9
9
  Swagger Codegen version: 2.4.12
@@ -3,7 +3,7 @@
3
3
 
4
4
  #No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen)
5
5
 
6
- OpenAPI spec version: 3.0.2
6
+ OpenAPI spec version: 3.0.9
7
7
  Contact: apihelp@mailchimp.com
8
8
  Generated by: https://github.com/swagger-api/swagger-codegen.git
9
9
  Swagger Codegen version: 2.4.12
@@ -11,5 +11,5 @@ Swagger Codegen version: 2.4.12
11
11
  =end
12
12
 
13
13
  module MailchimpMarketing
14
- VERSION = '3.0.2'
14
+ VERSION = '3.0.9'
15
15
  end
metadata CHANGED
@@ -1,35 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: MailchimpMarketing
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.2
4
+ version: 3.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Swagger-Codegen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-07-10 00:00:00.000000000 Z
11
+ date: 2020-08-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: faraday
14
+ name: excon
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.0'
20
- - - ">="
21
- - !ruby/object:Gem::Version
22
- version: 1.0.1
19
+ version: 0.76.0
23
20
  type: :runtime
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
26
23
  requirements:
27
24
  - - "~>"
28
25
  - !ruby/object:Gem::Version
29
- version: '1.0'
30
- - - ">="
31
- - !ruby/object:Gem::Version
32
- version: 1.0.1
26
+ version: 0.76.0
33
27
  - !ruby/object:Gem::Dependency
34
28
  name: json
35
29
  requirement: !ruby/object:Gem::Requirement