embulk-output-mailchimp 0.3.18 → 0.3.19
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/README.md +1 -0
- data/build.gradle +1 -1
- data/classpath/embulk-output-mailchimp-0.3.19.jar +0 -0
- data/src/main/java/org/embulk/output/mailchimp/MailChimpClient.java +13 -0
- data/src/main/java/org/embulk/output/mailchimp/MailChimpHttpClient.java +38 -0
- metadata +17 -17
- data/classpath/embulk-output-mailchimp-0.3.18.jar +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c09e4eb035f05f307279f2ecf2ce11c3050b1cf6
|
4
|
+
data.tar.gz: c38bcf2a895c5c87cdb8d075867fac68cda8b15c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fbe4afd20c07d7863ae67c5cd35617b12de3bcedea65b7cc271689ef65f7ca84a1d0f8c508bceac15531407739c220eb868afc78c35d773ce68608ca7291f68a
|
7
|
+
data.tar.gz: 8ade98e5dde219c3e43e2711bd50c71ff23c32c38e6510235cb44c320f09c2094832e33ea4bd4a6cd88fe041c6a0f947553468889d2ae66f7797223e315fb4e0
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
## 0.3.19 - 2017-10-10
|
2
|
+
- Fixed bug can not parse invalid JSON response and added request timeout to avoid flush MailChimp API [#35](https://github.com/treasure-data/embulk-output-mailchimp/pull/35)
|
3
|
+
|
1
4
|
## 0.3.18 - 2017-09-19
|
2
5
|
- Fixed error parsing MailChimp API response JSON when push the large data [#34](https://github.com/treasure-data/embulk-output-mailchimp/pull/34)
|
3
6
|
|
data/README.md
CHANGED
@@ -25,6 +25,7 @@ add e-mail to List in MailChimp.
|
|
25
25
|
- **grouping_columns**: Array for group names in MailChimp dashboard(array, default: nil)
|
26
26
|
- **language_column**: column name for language (string, optional, default: nil)
|
27
27
|
- **double_optin**: control whether to send an opt-in confirmation email (boolean, default: true)
|
28
|
+
- **max_records_per_request**: The max records per batch request. MailChimp API enables max records is 500 per batch request (int, default: 500)
|
28
29
|
|
29
30
|
## Example
|
30
31
|
|
data/build.gradle
CHANGED
Binary file
|
@@ -5,6 +5,7 @@ import com.fasterxml.jackson.core.JsonProcessingException;
|
|
5
5
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
6
6
|
import com.fasterxml.jackson.databind.JsonNode;
|
7
7
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
8
|
+
import com.fasterxml.jackson.databind.node.MissingNode;
|
8
9
|
import com.fasterxml.jackson.databind.node.ObjectNode;
|
9
10
|
import com.google.common.base.Function;
|
10
11
|
import com.google.common.base.Joiner;
|
@@ -31,6 +32,7 @@ import org.slf4j.Logger;
|
|
31
32
|
import javax.annotation.Nullable;
|
32
33
|
|
33
34
|
import java.text.MessageFormat;
|
35
|
+
import java.util.ArrayList;
|
34
36
|
import java.util.HashMap;
|
35
37
|
import java.util.List;
|
36
38
|
import java.util.Map;
|
@@ -80,6 +82,14 @@ public class MailChimpClient
|
|
80
82
|
task.getListId());
|
81
83
|
|
82
84
|
JsonNode response = client.sendRequest(endpoint, HttpMethod.POST, node.toString(), task);
|
85
|
+
client.avoidFlushAPI("Pushing next request");
|
86
|
+
|
87
|
+
if (response instanceof MissingNode) {
|
88
|
+
ReportResponse reportResponse = new ReportResponse();
|
89
|
+
reportResponse.setErrors(new ArrayList<ErrorResponse>());
|
90
|
+
return reportResponse;
|
91
|
+
}
|
92
|
+
|
83
93
|
return mapper.treeToValue(response, ReportResponse.class);
|
84
94
|
}
|
85
95
|
|
@@ -153,6 +163,9 @@ public class MailChimpClient
|
|
153
163
|
task.getListId(),
|
154
164
|
categoriesResponse.getId());
|
155
165
|
response = client.sendRequest(detailEndpoint, HttpMethod.GET, task);
|
166
|
+
|
167
|
+
// Avoid flush MailChimp API
|
168
|
+
client.avoidFlushAPI("Fetching next category's interests");
|
156
169
|
InterestsResponse interestsResponse = mapper.treeToValue(response, InterestsResponse.class);
|
157
170
|
categories.put(categoriesResponse.getTitle().toLowerCase(),
|
158
171
|
convertInterestCategoryToMap(interestsResponse.getInterests()));
|
@@ -24,6 +24,7 @@ import org.slf4j.Logger;
|
|
24
24
|
|
25
25
|
import java.io.IOException;
|
26
26
|
import java.util.concurrent.ExecutionException;
|
27
|
+
import java.util.concurrent.TimeUnit;
|
27
28
|
import java.util.concurrent.TimeoutException;
|
28
29
|
|
29
30
|
/**
|
@@ -66,6 +67,7 @@ public class MailChimpHttpClient
|
|
66
67
|
{
|
67
68
|
Request request = client
|
68
69
|
.newRequest(endpoint)
|
70
|
+
.timeout(task.getTimeoutMillis(), TimeUnit.MILLISECONDS)
|
69
71
|
.accept("application/json")
|
70
72
|
.method(method);
|
71
73
|
if (method == HttpMethod.POST || method == HttpMethod.PUT) {
|
@@ -117,11 +119,47 @@ public class MailChimpHttpClient
|
|
117
119
|
try {
|
118
120
|
return this.jsonMapper.readTree(json);
|
119
121
|
}
|
122
|
+
catch (IOException ex) {
|
123
|
+
// Try to parse invalid json before throwing exception
|
124
|
+
return parseInvalidJsonString(json);
|
125
|
+
}
|
126
|
+
}
|
127
|
+
|
128
|
+
// Sometimes, the MailChimp API returns invalid JSON when we pushed a large of data. ObjectMapper can not read string json.
|
129
|
+
// So we have to use this method to parse string and build a json string as ReportResponse
|
130
|
+
// E.g invalid json response from MailChimp https://gist.github.com/thangnc/dc94026e4b13b728b7303f402b458b05
|
131
|
+
private JsonNode parseInvalidJsonString(final String json)
|
132
|
+
{
|
133
|
+
int totalCreatedIndex = json.indexOf("\"total_created\"");
|
134
|
+
int totalUpdatedIndex = json.indexOf("\"total_updated\"");
|
135
|
+
int errorCountIndex = json.indexOf("\"error_count\"");
|
136
|
+
int errorsIndex = json.indexOf("\"errors\"");
|
137
|
+
|
138
|
+
StringBuilder validJson = new StringBuilder();
|
139
|
+
validJson.append("{").append(json.substring(errorsIndex, totalCreatedIndex - 1)).append(",");
|
140
|
+
validJson.append(json.substring(totalCreatedIndex, totalCreatedIndex + "\"total_created\"".length() + 2)).append(",");
|
141
|
+
validJson.append(json.substring(totalUpdatedIndex, totalUpdatedIndex + "\"total_updated\"".length() + 2)).append(",");
|
142
|
+
validJson.append(json.substring(errorCountIndex, errorCountIndex + "\"error_count\"".length() + 2)).append("}");
|
143
|
+
|
144
|
+
try {
|
145
|
+
return this.jsonMapper.readTree(validJson.toString());
|
146
|
+
}
|
120
147
|
catch (IOException ex) {
|
121
148
|
throw new DataException(ex);
|
122
149
|
}
|
123
150
|
}
|
124
151
|
|
152
|
+
public void avoidFlushAPI(String reason)
|
153
|
+
{
|
154
|
+
try {
|
155
|
+
LOG.info("{} in 5s...", reason);
|
156
|
+
Thread.sleep(5000);
|
157
|
+
}
|
158
|
+
catch (InterruptedException e) {
|
159
|
+
LOG.warn("Failed to sleep: {}", e.getMessage());
|
160
|
+
}
|
161
|
+
}
|
162
|
+
|
125
163
|
/**
|
126
164
|
* MailChimp API v3 supports non expires access_token. Then no need refresh_token
|
127
165
|
*
|
metadata
CHANGED
@@ -1,43 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: embulk-output-mailchimp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.19
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thang Nguyen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-10-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
|
14
|
+
name: bundler
|
15
|
+
version_requirements: !ruby/object:Gem::Requirement
|
15
16
|
requirements:
|
16
17
|
- - ~>
|
17
18
|
- !ruby/object:Gem::Version
|
18
19
|
version: '1.0'
|
19
|
-
|
20
|
-
prerelease: false
|
21
|
-
type: :development
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirement: !ruby/object:Gem::Requirement
|
23
21
|
requirements:
|
24
22
|
- - ~>
|
25
23
|
- !ruby/object:Gem::Version
|
26
24
|
version: '1.0'
|
25
|
+
prerelease: false
|
26
|
+
type: :development
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
|
28
|
+
name: rake
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
29
30
|
requirements:
|
30
31
|
- - '>='
|
31
32
|
- !ruby/object:Gem::Version
|
32
33
|
version: '10.0'
|
33
|
-
|
34
|
-
prerelease: false
|
35
|
-
type: :development
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
34
|
+
requirement: !ruby/object:Gem::Requirement
|
37
35
|
requirements:
|
38
36
|
- - '>='
|
39
37
|
- !ruby/object:Gem::Version
|
40
38
|
version: '10.0'
|
39
|
+
prerelease: false
|
40
|
+
type: :development
|
41
41
|
description: Dumps records to MailChimp.
|
42
42
|
email:
|
43
43
|
- thang@treasure-data.com
|
@@ -88,13 +88,13 @@ files:
|
|
88
88
|
- test/embulk/output/test_mailchimp.rb
|
89
89
|
- test/override_assert_raise.rb
|
90
90
|
- test/run-test.rb
|
91
|
-
- classpath/embulk-base-restclient-0.5.3.jar
|
92
|
-
- classpath/embulk-output-mailchimp-0.3.18.jar
|
93
|
-
- classpath/embulk-util-retryhelper-jetty92-0.5.3.jar
|
94
|
-
- classpath/jetty-client-9.2.14.v20151106.jar
|
95
|
-
- classpath/jetty-http-9.2.14.v20151106.jar
|
96
91
|
- classpath/jetty-io-9.2.14.v20151106.jar
|
92
|
+
- classpath/embulk-output-mailchimp-0.3.19.jar
|
97
93
|
- classpath/jetty-util-9.2.14.v20151106.jar
|
94
|
+
- classpath/jetty-http-9.2.14.v20151106.jar
|
95
|
+
- classpath/jetty-client-9.2.14.v20151106.jar
|
96
|
+
- classpath/embulk-base-restclient-0.5.3.jar
|
97
|
+
- classpath/embulk-util-retryhelper-jetty92-0.5.3.jar
|
98
98
|
homepage: https://github.com/treasure-data/embulk-output-mailchimp
|
99
99
|
licenses:
|
100
100
|
- MIT
|
Binary file
|