MailchimpMarketing 3.0.8 → 3.0.13
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 +4 -4
- data/LICENSE +53 -0
- data/MailchimpMarketing.gemspec +2 -2
- data/README.md +2 -2
- data/lib/MailchimpMarketing.rb +1 -1
- data/lib/MailchimpMarketing/api/activity_feed_api.rb +5 -10
- data/lib/MailchimpMarketing/api/authorized_apps_api.rb +7 -14
- data/lib/MailchimpMarketing/api/automations_api.rb +39 -78
- data/lib/MailchimpMarketing/api/batch_webhooks_api.rb +11 -22
- data/lib/MailchimpMarketing/api/batches_api.rb +9 -18
- data/lib/MailchimpMarketing/api/campaign_folders_api.rb +11 -22
- data/lib/MailchimpMarketing/api/campaigns_api.rb +45 -90
- data/lib/MailchimpMarketing/api/connected_sites_api.rb +11 -22
- data/lib/MailchimpMarketing/api/conversations_api.rb +11 -22
- data/lib/MailchimpMarketing/api/dashboard_api.rb +13 -26
- data/lib/MailchimpMarketing/api/ecommerce_api.rb +119 -238
- data/lib/MailchimpMarketing/api/external_auths_api.rb +7 -14
- data/lib/MailchimpMarketing/api/facebook_ads_api.rb +5 -10
- data/lib/MailchimpMarketing/api/file_manager_api.rb +23 -46
- data/lib/MailchimpMarketing/api/landing_pages_api.rb +17 -34
- data/lib/MailchimpMarketing/api/lists_api.rb +136 -268
- data/lib/MailchimpMarketing/api/ping_api.rb +3 -6
- data/lib/MailchimpMarketing/api/postcards_api.rb +3 -6
- data/lib/MailchimpMarketing/api/reporting_api.rb +13 -26
- data/lib/MailchimpMarketing/api/reports_api.rb +45 -90
- data/lib/MailchimpMarketing/api/root_api.rb +3 -6
- data/lib/MailchimpMarketing/api/search_campaigns_api.rb +3 -6
- data/lib/MailchimpMarketing/api/search_members_api.rb +3 -6
- data/lib/MailchimpMarketing/api/template_folders_api.rb +11 -22
- data/lib/MailchimpMarketing/api/templates_api.rb +13 -26
- data/lib/MailchimpMarketing/api/verified_domains_api.rb +11 -22
- data/lib/MailchimpMarketing/api_client.rb +17 -117
- data/lib/MailchimpMarketing/api_error.rb +1 -1
- data/lib/MailchimpMarketing/configuration.rb +1 -1
- data/lib/MailchimpMarketing/version.rb +2 -2
- metadata +6 -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.
|
6
|
+
OpenAPI spec version: 3.0.13
|
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,7 +11,6 @@ Swagger Codegen version: 2.4.12
|
|
11
11
|
=end
|
12
12
|
|
13
13
|
require 'uri'
|
14
|
-
require 'json'
|
15
14
|
|
16
15
|
module MailchimpMarketing
|
17
16
|
class RootApi
|
@@ -27,15 +26,13 @@ module MailchimpMarketing
|
|
27
26
|
query_params = {}
|
28
27
|
query_params[:'fields'] = @api_client.build_collection_param(opts[:'fields'], :csv) if !opts[:'fields'].nil?
|
29
28
|
query_params[:'exclude_fields'] = @api_client.build_collection_param(opts[:'exclude_fields'], :csv) if !opts[:'exclude_fields'].nil?
|
30
|
-
form_params = {}
|
31
29
|
post_body = nil
|
32
30
|
|
33
31
|
local_var_path = '/'
|
34
|
-
data
|
32
|
+
data = @api_client.call_api(:GET, local_var_path,
|
35
33
|
:query_params => query_params,
|
36
|
-
:form_params => form_params,
|
37
34
|
:body => post_body)
|
38
|
-
return data
|
35
|
+
return data
|
39
36
|
end
|
40
37
|
end
|
41
38
|
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.
|
6
|
+
OpenAPI spec version: 3.0.13
|
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,7 +11,6 @@ Swagger Codegen version: 2.4.12
|
|
11
11
|
=end
|
12
12
|
|
13
13
|
require 'uri'
|
14
|
-
require 'json'
|
15
14
|
|
16
15
|
module MailchimpMarketing
|
17
16
|
class SearchCampaignsApi
|
@@ -29,15 +28,13 @@ module MailchimpMarketing
|
|
29
28
|
query_params[:'query'] = query
|
30
29
|
query_params[:'fields'] = @api_client.build_collection_param(opts[:'fields'], :csv) if !opts[:'fields'].nil?
|
31
30
|
query_params[:'exclude_fields'] = @api_client.build_collection_param(opts[:'exclude_fields'], :csv) if !opts[:'exclude_fields'].nil?
|
32
|
-
form_params = {}
|
33
31
|
post_body = nil
|
34
32
|
|
35
33
|
local_var_path = '/search-campaigns'
|
36
|
-
data
|
34
|
+
data = @api_client.call_api(:GET, local_var_path,
|
37
35
|
:query_params => query_params,
|
38
|
-
:form_params => form_params,
|
39
36
|
:body => post_body)
|
40
|
-
return data
|
37
|
+
return data
|
41
38
|
end
|
42
39
|
end
|
43
40
|
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.
|
6
|
+
OpenAPI spec version: 3.0.13
|
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,7 +11,6 @@ Swagger Codegen version: 2.4.12
|
|
11
11
|
=end
|
12
12
|
|
13
13
|
require 'uri'
|
14
|
-
require 'json'
|
15
14
|
|
16
15
|
module MailchimpMarketing
|
17
16
|
class SearchMembersApi
|
@@ -30,15 +29,13 @@ module MailchimpMarketing
|
|
30
29
|
query_params[:'fields'] = @api_client.build_collection_param(opts[:'fields'], :csv) if !opts[:'fields'].nil?
|
31
30
|
query_params[:'exclude_fields'] = @api_client.build_collection_param(opts[:'exclude_fields'], :csv) if !opts[:'exclude_fields'].nil?
|
32
31
|
query_params[:'list_id'] = opts[:'list_id'] if !opts[:'list_id'].nil?
|
33
|
-
form_params = {}
|
34
32
|
post_body = nil
|
35
33
|
|
36
34
|
local_var_path = '/search-members'
|
37
|
-
data
|
35
|
+
data = @api_client.call_api(:GET, local_var_path,
|
38
36
|
:query_params => query_params,
|
39
|
-
:form_params => form_params,
|
40
37
|
:body => post_body)
|
41
|
-
return data
|
38
|
+
return data
|
42
39
|
end
|
43
40
|
end
|
44
41
|
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.
|
6
|
+
OpenAPI spec version: 3.0.13
|
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,7 +11,6 @@ Swagger Codegen version: 2.4.12
|
|
11
11
|
=end
|
12
12
|
|
13
13
|
require 'uri'
|
14
|
-
require 'json'
|
15
14
|
|
16
15
|
module MailchimpMarketing
|
17
16
|
class TemplateFoldersApi
|
@@ -26,15 +25,13 @@ module MailchimpMarketing
|
|
26
25
|
fail ArgumentError, "Missing required param: 'folder_id'" if folder_id.nil?
|
27
26
|
|
28
27
|
query_params = {}
|
29
|
-
form_params = {}
|
30
28
|
post_body = nil
|
31
29
|
|
32
30
|
local_var_path = '/template-folders/{folder_id}'.sub('{' + 'folder_id' + '}', folder_id.to_s)
|
33
|
-
data
|
31
|
+
data = @api_client.call_api(:DELETE, local_var_path,
|
34
32
|
:query_params => query_params,
|
35
|
-
:form_params => form_params,
|
36
33
|
:body => post_body)
|
37
|
-
return data
|
34
|
+
return data
|
38
35
|
end
|
39
36
|
|
40
37
|
# List template folders
|
@@ -46,15 +43,13 @@ module MailchimpMarketing
|
|
46
43
|
query_params[:'exclude_fields'] = @api_client.build_collection_param(opts[:'exclude_fields'], :csv) if !opts[:'exclude_fields'].nil?
|
47
44
|
query_params[:'count'] = opts[:'count'] if !opts[:'count'].nil?
|
48
45
|
query_params[:'offset'] = opts[:'offset'] if !opts[:'offset'].nil?
|
49
|
-
form_params = {}
|
50
46
|
post_body = nil
|
51
47
|
|
52
48
|
local_var_path = '/template-folders'
|
53
|
-
data
|
49
|
+
data = @api_client.call_api(:GET, local_var_path,
|
54
50
|
:query_params => query_params,
|
55
|
-
:form_params => form_params,
|
56
51
|
:body => post_body)
|
57
|
-
return data
|
52
|
+
return data
|
58
53
|
end
|
59
54
|
|
60
55
|
# Get template folder
|
@@ -64,15 +59,13 @@ module MailchimpMarketing
|
|
64
59
|
query_params = {}
|
65
60
|
query_params[:'fields'] = @api_client.build_collection_param(opts[:'fields'], :csv) if !opts[:'fields'].nil?
|
66
61
|
query_params[:'exclude_fields'] = @api_client.build_collection_param(opts[:'exclude_fields'], :csv) if !opts[:'exclude_fields'].nil?
|
67
|
-
form_params = {}
|
68
62
|
post_body = nil
|
69
63
|
|
70
64
|
local_var_path = '/template-folders/{folder_id}'.sub('{' + 'folder_id' + '}', folder_id.to_s)
|
71
|
-
data
|
65
|
+
data = @api_client.call_api(:GET, local_var_path,
|
72
66
|
:query_params => query_params,
|
73
|
-
:form_params => form_params,
|
74
67
|
:body => post_body)
|
75
|
-
return data
|
68
|
+
return data
|
76
69
|
end
|
77
70
|
|
78
71
|
# Update template folder
|
@@ -81,15 +74,13 @@ module MailchimpMarketing
|
|
81
74
|
fail ArgumentError, "Missing required param: 'body'" if body.nil?
|
82
75
|
|
83
76
|
query_params = {}
|
84
|
-
form_params = {}
|
85
77
|
post_body = @api_client.object_to_http_body(body)
|
86
78
|
|
87
79
|
local_var_path = '/template-folders/{folder_id}'.sub('{' + 'folder_id' + '}', folder_id.to_s)
|
88
|
-
data
|
80
|
+
data = @api_client.call_api(:PATCH, local_var_path,
|
89
81
|
:query_params => query_params,
|
90
|
-
:form_params => form_params,
|
91
82
|
:body => post_body)
|
92
|
-
return data
|
83
|
+
return data
|
93
84
|
end
|
94
85
|
|
95
86
|
# Add template folder
|
@@ -97,15 +88,13 @@ module MailchimpMarketing
|
|
97
88
|
fail ArgumentError, "Missing required param: 'body'" if body.nil?
|
98
89
|
|
99
90
|
query_params = {}
|
100
|
-
form_params = {}
|
101
91
|
post_body = @api_client.object_to_http_body(body)
|
102
92
|
|
103
93
|
local_var_path = '/template-folders'
|
104
|
-
data
|
94
|
+
data = @api_client.call_api(:POST, local_var_path,
|
105
95
|
:query_params => query_params,
|
106
|
-
:form_params => form_params,
|
107
96
|
:body => post_body)
|
108
|
-
return data
|
97
|
+
return data
|
109
98
|
end
|
110
99
|
end
|
111
100
|
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.
|
6
|
+
OpenAPI spec version: 3.0.13
|
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,7 +11,6 @@ Swagger Codegen version: 2.4.12
|
|
11
11
|
=end
|
12
12
|
|
13
13
|
require 'uri'
|
14
|
-
require 'json'
|
15
14
|
|
16
15
|
module MailchimpMarketing
|
17
16
|
class TemplatesApi
|
@@ -26,15 +25,13 @@ module MailchimpMarketing
|
|
26
25
|
fail ArgumentError, "Missing required param: 'template_id'" if template_id.nil?
|
27
26
|
|
28
27
|
query_params = {}
|
29
|
-
form_params = {}
|
30
28
|
post_body = nil
|
31
29
|
|
32
30
|
local_var_path = '/templates/{template_id}'.sub('{' + 'template_id' + '}', template_id.to_s)
|
33
|
-
data
|
31
|
+
data = @api_client.call_api(:DELETE, local_var_path,
|
34
32
|
:query_params => query_params,
|
35
|
-
:form_params => form_params,
|
36
33
|
:body => post_body)
|
37
|
-
return data
|
34
|
+
return data
|
38
35
|
end
|
39
36
|
|
40
37
|
# List templates
|
@@ -54,15 +51,13 @@ module MailchimpMarketing
|
|
54
51
|
query_params[:'category'] = opts[:'category'] if !opts[:'category'].nil?
|
55
52
|
query_params[:'folder_id'] = opts[:'folder_id'] if !opts[:'folder_id'].nil?
|
56
53
|
query_params[:'sort_field'] = opts[:'sort_field'] if !opts[:'sort_field'].nil?
|
57
|
-
form_params = {}
|
58
54
|
post_body = nil
|
59
55
|
|
60
56
|
local_var_path = '/templates'
|
61
|
-
data
|
57
|
+
data = @api_client.call_api(:GET, local_var_path,
|
62
58
|
:query_params => query_params,
|
63
|
-
:form_params => form_params,
|
64
59
|
:body => post_body)
|
65
|
-
return data
|
60
|
+
return data
|
66
61
|
end
|
67
62
|
|
68
63
|
# Get template info
|
@@ -72,15 +67,13 @@ module MailchimpMarketing
|
|
72
67
|
query_params = {}
|
73
68
|
query_params[:'fields'] = @api_client.build_collection_param(opts[:'fields'], :csv) if !opts[:'fields'].nil?
|
74
69
|
query_params[:'exclude_fields'] = @api_client.build_collection_param(opts[:'exclude_fields'], :csv) if !opts[:'exclude_fields'].nil?
|
75
|
-
form_params = {}
|
76
70
|
post_body = nil
|
77
71
|
|
78
72
|
local_var_path = '/templates/{template_id}'.sub('{' + 'template_id' + '}', template_id.to_s)
|
79
|
-
data
|
73
|
+
data = @api_client.call_api(:GET, local_var_path,
|
80
74
|
:query_params => query_params,
|
81
|
-
:form_params => form_params,
|
82
75
|
:body => post_body)
|
83
|
-
return data
|
76
|
+
return data
|
84
77
|
end
|
85
78
|
|
86
79
|
# View default content
|
@@ -90,15 +83,13 @@ module MailchimpMarketing
|
|
90
83
|
query_params = {}
|
91
84
|
query_params[:'fields'] = @api_client.build_collection_param(opts[:'fields'], :csv) if !opts[:'fields'].nil?
|
92
85
|
query_params[:'exclude_fields'] = @api_client.build_collection_param(opts[:'exclude_fields'], :csv) if !opts[:'exclude_fields'].nil?
|
93
|
-
form_params = {}
|
94
86
|
post_body = nil
|
95
87
|
|
96
88
|
local_var_path = '/templates/{template_id}/default-content'.sub('{' + 'template_id' + '}', template_id.to_s)
|
97
|
-
data
|
89
|
+
data = @api_client.call_api(:GET, local_var_path,
|
98
90
|
:query_params => query_params,
|
99
|
-
:form_params => form_params,
|
100
91
|
:body => post_body)
|
101
|
-
return data
|
92
|
+
return data
|
102
93
|
end
|
103
94
|
|
104
95
|
# Update template
|
@@ -107,15 +98,13 @@ module MailchimpMarketing
|
|
107
98
|
fail ArgumentError, "Missing required param: 'body'" if body.nil?
|
108
99
|
|
109
100
|
query_params = {}
|
110
|
-
form_params = {}
|
111
101
|
post_body = @api_client.object_to_http_body(body)
|
112
102
|
|
113
103
|
local_var_path = '/templates/{template_id}'.sub('{' + 'template_id' + '}', template_id.to_s)
|
114
|
-
data
|
104
|
+
data = @api_client.call_api(:PATCH, local_var_path,
|
115
105
|
:query_params => query_params,
|
116
|
-
:form_params => form_params,
|
117
106
|
:body => post_body)
|
118
|
-
return data
|
107
|
+
return data
|
119
108
|
end
|
120
109
|
|
121
110
|
# Add template
|
@@ -123,15 +112,13 @@ module MailchimpMarketing
|
|
123
112
|
fail ArgumentError, "Missing required param: 'body'" if body.nil?
|
124
113
|
|
125
114
|
query_params = {}
|
126
|
-
form_params = {}
|
127
115
|
post_body = @api_client.object_to_http_body(body)
|
128
116
|
|
129
117
|
local_var_path = '/templates'
|
130
|
-
data
|
118
|
+
data = @api_client.call_api(:POST, local_var_path,
|
131
119
|
:query_params => query_params,
|
132
|
-
:form_params => form_params,
|
133
120
|
:body => post_body)
|
134
|
-
return data
|
121
|
+
return data
|
135
122
|
end
|
136
123
|
end
|
137
124
|
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.
|
6
|
+
OpenAPI spec version: 3.0.13
|
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,7 +11,6 @@ Swagger Codegen version: 2.4.12
|
|
11
11
|
=end
|
12
12
|
|
13
13
|
require 'uri'
|
14
|
-
require 'json'
|
15
14
|
|
16
15
|
module MailchimpMarketing
|
17
16
|
class VerifiedDomainsApi
|
@@ -26,15 +25,13 @@ module MailchimpMarketing
|
|
26
25
|
fail ArgumentError, "Missing required param: 'body'" if body.nil?
|
27
26
|
|
28
27
|
query_params = {}
|
29
|
-
form_params = {}
|
30
28
|
post_body = @api_client.object_to_http_body(body)
|
31
29
|
|
32
30
|
local_var_path = '/verified-domains'
|
33
|
-
data
|
31
|
+
data = @api_client.call_api(:POST, local_var_path,
|
34
32
|
:query_params => query_params,
|
35
|
-
:form_params => form_params,
|
36
33
|
:body => post_body)
|
37
|
-
return data
|
34
|
+
return data
|
38
35
|
end
|
39
36
|
|
40
37
|
# Delete domain
|
@@ -42,15 +39,13 @@ module MailchimpMarketing
|
|
42
39
|
fail ArgumentError, "Missing required param: 'domain_name'" if domain_name.nil?
|
43
40
|
|
44
41
|
query_params = {}
|
45
|
-
form_params = {}
|
46
42
|
post_body = nil
|
47
43
|
|
48
44
|
local_var_path = '/verified-domains/{domain_name}'.sub('{' + 'domain_name' + '}', domain_name.to_s)
|
49
|
-
data
|
45
|
+
data = @api_client.call_api(:DELETE, local_var_path,
|
50
46
|
:query_params => query_params,
|
51
|
-
:form_params => form_params,
|
52
47
|
:body => post_body)
|
53
|
-
return data
|
48
|
+
return data
|
54
49
|
end
|
55
50
|
|
56
51
|
# Get domain info
|
@@ -58,30 +53,26 @@ module MailchimpMarketing
|
|
58
53
|
fail ArgumentError, "Missing required param: 'domain_name'" if domain_name.nil?
|
59
54
|
|
60
55
|
query_params = {}
|
61
|
-
form_params = {}
|
62
56
|
post_body = nil
|
63
57
|
|
64
58
|
local_var_path = '/verified-domains/{domain_name}'.sub('{' + 'domain_name' + '}', domain_name.to_s)
|
65
|
-
data
|
59
|
+
data = @api_client.call_api(:GET, local_var_path,
|
66
60
|
:query_params => query_params,
|
67
|
-
:form_params => form_params,
|
68
61
|
:body => post_body)
|
69
|
-
return data
|
62
|
+
return data
|
70
63
|
end
|
71
64
|
|
72
65
|
# List sending domains
|
73
66
|
def get_verified_domains_all(opts = {})
|
74
67
|
|
75
68
|
query_params = {}
|
76
|
-
form_params = {}
|
77
69
|
post_body = nil
|
78
70
|
|
79
71
|
local_var_path = '/verified-domains'
|
80
|
-
data
|
72
|
+
data = @api_client.call_api(:GET, local_var_path,
|
81
73
|
:query_params => query_params,
|
82
|
-
:form_params => form_params,
|
83
74
|
:body => post_body)
|
84
|
-
return data
|
75
|
+
return data
|
85
76
|
end
|
86
77
|
|
87
78
|
# Verify domain
|
@@ -90,15 +81,13 @@ module MailchimpMarketing
|
|
90
81
|
fail ArgumentError, "Missing required param: 'body'" if body.nil?
|
91
82
|
|
92
83
|
query_params = {}
|
93
|
-
form_params = {}
|
94
84
|
post_body = @api_client.object_to_http_body(body)
|
95
85
|
|
96
86
|
local_var_path = '/verified-domains/{domain_name}/actions/verify'.sub('{' + 'domain_name' + '}', domain_name.to_s)
|
97
|
-
data
|
87
|
+
data = @api_client.call_api(:POST, local_var_path,
|
98
88
|
:query_params => query_params,
|
99
|
-
:form_params => form_params,
|
100
89
|
:body => post_body)
|
101
|
-
return data
|
90
|
+
return data
|
102
91
|
end
|
103
92
|
end
|
104
93
|
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.
|
6
|
+
OpenAPI spec version: 3.0.13
|
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,7 +11,7 @@ Swagger Codegen version: 2.4.12
|
|
11
11
|
=end
|
12
12
|
|
13
13
|
require 'json'
|
14
|
-
require '
|
14
|
+
require 'excon'
|
15
15
|
|
16
16
|
module MailchimpMarketing
|
17
17
|
class ApiClient
|
@@ -41,6 +41,7 @@ module MailchimpMarketing
|
|
41
41
|
def set_config(config = {})
|
42
42
|
@api_key = config[:api_key] || ''
|
43
43
|
@is_basic_auth = @api_key.to_s.strip.empty? == false
|
44
|
+
|
44
45
|
@access_token = config[:access_token] || ''
|
45
46
|
@is_oauth = @access_token.to_s.strip.empty? == false
|
46
47
|
|
@@ -53,126 +54,30 @@ module MailchimpMarketing
|
|
53
54
|
end
|
54
55
|
|
55
56
|
def call_api(http_method, path, opts = {})
|
56
|
-
|
57
|
-
|
58
|
-
|
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)
|
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
|
69
60
|
|
70
|
-
data = nil
|
71
|
-
if res.headers['content-type'] && res.headers['content-type'].include?('application/json')
|
72
|
-
data = JSON.parse(res.body)
|
73
|
-
else
|
74
|
-
data = res.body
|
75
|
-
end
|
76
|
-
|
77
|
-
if data
|
78
|
-
if res.status <= 200
|
79
|
-
data
|
80
|
-
else
|
81
|
-
fail ApiError.new(res.body)
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
def request(http_method, path, query_params = nil, header_params = nil, body = nil)
|
87
61
|
host = @server.length > 0 ? @host.sub('server', @server) : @host
|
88
|
-
|
89
|
-
|
90
|
-
# Apply Authentication
|
91
|
-
conn = Faraday.new(url) do |conn|
|
92
|
-
conn.headers = header_params
|
93
|
-
conn.params = query_params
|
94
|
-
|
95
|
-
if @is_basic_auth
|
96
|
-
conn.basic_auth('user', @api_key)
|
97
|
-
elsif @is_oauth
|
98
|
-
conn.headers["Authorization"] = "Bearer #{@access_token}"
|
99
|
-
end
|
100
|
-
end
|
62
|
+
conn = Excon.new(host + path, :headers => headers)
|
101
63
|
|
64
|
+
res = nil
|
102
65
|
case http_method.to_sym.downcase
|
103
|
-
when :delete
|
104
|
-
conn.
|
105
|
-
req.body = body.to_json
|
106
|
-
end
|
66
|
+
when :post, :put, :delete
|
67
|
+
res = conn.request(:method => http_method, :body => opts[:body])
|
107
68
|
when :get
|
108
|
-
conn.get
|
109
|
-
when :head
|
110
|
-
conn.head
|
111
|
-
when :options
|
112
|
-
conn.options
|
113
|
-
when :post
|
114
|
-
conn.post do |req|
|
115
|
-
req.body = body.to_json
|
116
|
-
end
|
117
|
-
when :put
|
118
|
-
conn.put do |req|
|
119
|
-
req.body = body.to_json
|
120
|
-
end
|
121
|
-
when :patch
|
122
|
-
conn.patch do |req|
|
123
|
-
req.body = body.to_json
|
124
|
-
end
|
125
|
-
else
|
126
|
-
fail ApiError.new('Invalid http_method')
|
69
|
+
res = conn.get(:query => opts[:query_params])
|
127
70
|
end
|
128
|
-
end
|
129
71
|
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
filename.gsub(/.*[\/\\]/, '')
|
134
|
-
end
|
135
|
-
|
136
|
-
# Add leading and trailing slashes to path
|
137
|
-
def build_request_url(path)
|
138
|
-
path = "/#{path}".gsub(/\/+/, '/')
|
139
|
-
URI.encode(@config.base_url + path)
|
140
|
-
end
|
72
|
+
data = nil
|
73
|
+
data = JSON.parse(res.body) if res.status == 200
|
74
|
+
data = "success" if res.status == 204
|
141
75
|
|
142
|
-
|
143
|
-
|
144
|
-
if header_params['Content-Type'] == 'application/x-www-form-urlencoded' ||
|
145
|
-
header_params['Content-Type'] == 'multipart/form-data'
|
146
|
-
data = {}
|
147
|
-
form_params.each do |key, value|
|
148
|
-
case value
|
149
|
-
when ::File, ::Array, nil
|
150
|
-
data[key] = value
|
151
|
-
else
|
152
|
-
data[key] = value.to_s
|
153
|
-
end
|
154
|
-
end
|
155
|
-
elsif body
|
156
|
-
data = body.is_a?(String) ? body : body.to_json
|
157
|
-
else
|
158
|
-
data = nil
|
76
|
+
if (!data)
|
77
|
+
fail ApiError.new(:status => res.status, :response_body => res.body)
|
159
78
|
end
|
160
|
-
data
|
161
|
-
end
|
162
|
-
|
163
|
-
# Return Accept header based on an array of accepts provided.
|
164
|
-
def select_header_accept(accepts)
|
165
|
-
return nil if accepts.nil? || accepts.empty?
|
166
|
-
json_accept = accepts.find { |s| json_mime?(s) }
|
167
|
-
json_accept || accepts.join(',')
|
168
|
-
end
|
169
|
-
|
170
|
-
# Return Content-Type header based on an array of content types provided.
|
171
|
-
def select_header_content_type(content_types)
|
172
|
-
return 'application/json' if content_types.nil? || content_types.empty?
|
173
79
|
|
174
|
-
|
175
|
-
json_content_type || content_types.first
|
80
|
+
return data
|
176
81
|
end
|
177
82
|
|
178
83
|
# Convert object (array, hash, object, etc) to JSON string.
|
@@ -213,10 +118,5 @@ module MailchimpMarketing
|
|
213
118
|
fail "unknown collection format: #{collection_format.inspect}"
|
214
119
|
end
|
215
120
|
end
|
216
|
-
|
217
|
-
# Check if the given MIME is a JSON MIME.
|
218
|
-
def json_mime?(mime)
|
219
|
-
(mime == '*/*') || !(mime =~ /Application\/.*json(?!p)(;.*)?/i).nil?
|
220
|
-
end
|
221
121
|
end
|
222
122
|
end
|