embulk-input-marketo_extended 0.6.18
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/.github/PULL_REQUEST_TEMPLATE.md +37 -0
- data/.gitignore +14 -0
- data/.travis.yml +6 -0
- data/CHANGELOG.md +170 -0
- data/LICENSE.txt +21 -0
- data/README.md +213 -0
- data/build.gradle +103 -0
- data/config/checkstyle/checkstyle.xml +128 -0
- data/config/checkstyle/default.xml +108 -0
- data/gradle/wrapper/gradle-wrapper.jar +0 -0
- data/gradle/wrapper/gradle-wrapper.properties +6 -0
- data/gradlew +169 -0
- data/gradlew.bat +84 -0
- data/lib/embulk/input/marketo.rb +3 -0
- data/settings.gradle +1 -0
- data/src/main/java/org/embulk/input/marketo/CsvTokenizer.java +700 -0
- data/src/main/java/org/embulk/input/marketo/MarketoInputPlugin.java +15 -0
- data/src/main/java/org/embulk/input/marketo/MarketoInputPluginDelegate.java +100 -0
- data/src/main/java/org/embulk/input/marketo/MarketoService.java +38 -0
- data/src/main/java/org/embulk/input/marketo/MarketoServiceImpl.java +245 -0
- data/src/main/java/org/embulk/input/marketo/MarketoUtils.java +212 -0
- data/src/main/java/org/embulk/input/marketo/delegate/ActivityBulkExtractInputPlugin.java +167 -0
- data/src/main/java/org/embulk/input/marketo/delegate/CampaignInputPlugin.java +48 -0
- data/src/main/java/org/embulk/input/marketo/delegate/CustomObjectInputPlugin.java +75 -0
- data/src/main/java/org/embulk/input/marketo/delegate/CustomObjectResponseMapperBuilder.java +81 -0
- data/src/main/java/org/embulk/input/marketo/delegate/LeadBulkExtractInputPlugin.java +66 -0
- data/src/main/java/org/embulk/input/marketo/delegate/LeadServiceResponseMapperBuilder.java +85 -0
- data/src/main/java/org/embulk/input/marketo/delegate/LeadWithListInputPlugin.java +64 -0
- data/src/main/java/org/embulk/input/marketo/delegate/LeadWithProgramInputPlugin.java +60 -0
- data/src/main/java/org/embulk/input/marketo/delegate/MarketoBaseBulkExtractInputPlugin.java +441 -0
- data/src/main/java/org/embulk/input/marketo/delegate/MarketoBaseInputPluginDelegate.java +92 -0
- data/src/main/java/org/embulk/input/marketo/delegate/ProgramInputPlugin.java +228 -0
- data/src/main/java/org/embulk/input/marketo/exception/MarketoAPIException.java +30 -0
- data/src/main/java/org/embulk/input/marketo/model/BulkExtractRangeHeader.java +26 -0
- data/src/main/java/org/embulk/input/marketo/model/MarketoAccessTokenResponse.java +92 -0
- data/src/main/java/org/embulk/input/marketo/model/MarketoBulkExtractRequest.java +68 -0
- data/src/main/java/org/embulk/input/marketo/model/MarketoError.java +40 -0
- data/src/main/java/org/embulk/input/marketo/model/MarketoField.java +126 -0
- data/src/main/java/org/embulk/input/marketo/model/MarketoResponse.java +82 -0
- data/src/main/java/org/embulk/input/marketo/model/filter/DateRangeFilter.java +40 -0
- data/src/main/java/org/embulk/input/marketo/rest/MarketoBaseRestClient.java +306 -0
- data/src/main/java/org/embulk/input/marketo/rest/MarketoInputStreamResponseEntityReader.java +69 -0
- data/src/main/java/org/embulk/input/marketo/rest/MarketoRESTEndpoint.java +47 -0
- data/src/main/java/org/embulk/input/marketo/rest/MarketoResponseJetty92EntityReader.java +89 -0
- data/src/main/java/org/embulk/input/marketo/rest/MarketoRestClient.java +569 -0
- data/src/main/java/org/embulk/input/marketo/rest/RecordPagingIterable.java +180 -0
- data/src/test/java/org/embulk/input/marketo/MarketoServiceImplTest.java +140 -0
- data/src/test/java/org/embulk/input/marketo/MarketoUtilsTest.java +87 -0
- data/src/test/java/org/embulk/input/marketo/delegate/ActivityBulkExtractInputPluginTest.java +128 -0
- data/src/test/java/org/embulk/input/marketo/delegate/CampaignInputPluginTest.java +73 -0
- data/src/test/java/org/embulk/input/marketo/delegate/CustomObjectInputPluginTest.java +102 -0
- data/src/test/java/org/embulk/input/marketo/delegate/LeadBulkExtractInputPluginTest.java +99 -0
- data/src/test/java/org/embulk/input/marketo/delegate/LeadServiceResponseMapperBuilderTest.java +119 -0
- data/src/test/java/org/embulk/input/marketo/delegate/LeadWithListInputPluginTest.java +101 -0
- data/src/test/java/org/embulk/input/marketo/delegate/LeadWithProgramInputPluginTest.java +103 -0
- data/src/test/java/org/embulk/input/marketo/delegate/MarketoBaseBulkExtractInputPluginTest.java +169 -0
- data/src/test/java/org/embulk/input/marketo/delegate/ProgramInputPluginTest.java +343 -0
- data/src/test/java/org/embulk/input/marketo/rest/MarketoBaseRestClientTest.java +368 -0
- data/src/test/java/org/embulk/input/marketo/rest/MarketoRestClientTest.java +584 -0
- data/src/test/resources/config/activity_bulk_extract_config.yaml +7 -0
- data/src/test/resources/config/custom_object_config.yaml +8 -0
- data/src/test/resources/config/lead_bulk_extract_config.yaml +8 -0
- data/src/test/resources/config/rest_config.yaml +3 -0
- data/src/test/resources/fixtures/activity_extract1.csv +35 -0
- data/src/test/resources/fixtures/activity_extract2.csv +22 -0
- data/src/test/resources/fixtures/activity_types.json +22 -0
- data/src/test/resources/fixtures/all_program_full.json +53 -0
- data/src/test/resources/fixtures/campaign_response.json +38 -0
- data/src/test/resources/fixtures/campaign_response_full.json +102 -0
- data/src/test/resources/fixtures/custom_object_describe.json +124 -0
- data/src/test/resources/fixtures/custom_object_describe_marketo_fields_full.json +22 -0
- data/src/test/resources/fixtures/custom_object_expected.json +66 -0
- data/src/test/resources/fixtures/custom_object_response.json +24 -0
- data/src/test/resources/fixtures/custom_object_response_full.json +23 -0
- data/src/test/resources/fixtures/lead_by_list.json +33 -0
- data/src/test/resources/fixtures/lead_by_program_response.json +47 -0
- data/src/test/resources/fixtures/lead_describe.json +221 -0
- data/src/test/resources/fixtures/lead_describe_expected.json +66 -0
- data/src/test/resources/fixtures/lead_describe_marketo_fields_full.json +518 -0
- data/src/test/resources/fixtures/lead_extract1.csv +11 -0
- data/src/test/resources/fixtures/lead_response_full.json +2402 -0
- data/src/test/resources/fixtures/lead_with_program_full.json +17 -0
- data/src/test/resources/fixtures/leads_extract2.csv +10 -0
- data/src/test/resources/fixtures/list_reponse_full.json +191 -0
- data/src/test/resources/fixtures/lists_response.json +31 -0
- data/src/test/resources/fixtures/program_response.json +71 -0
- metadata +171 -0
@@ -0,0 +1,92 @@
|
|
1
|
+
package org.embulk.input.marketo.delegate;
|
2
|
+
|
3
|
+
import com.google.common.annotations.VisibleForTesting;
|
4
|
+
|
5
|
+
import org.embulk.base.restclient.DefaultServiceDataSplitter;
|
6
|
+
import org.embulk.base.restclient.RestClientInputPluginDelegate;
|
7
|
+
import org.embulk.base.restclient.RestClientInputTaskBase;
|
8
|
+
import org.embulk.base.restclient.ServiceDataSplitter;
|
9
|
+
import org.embulk.base.restclient.record.RecordImporter;
|
10
|
+
import org.embulk.base.restclient.record.ServiceRecord;
|
11
|
+
import org.embulk.config.Config;
|
12
|
+
import org.embulk.config.ConfigDefault;
|
13
|
+
import org.embulk.config.ConfigDiff;
|
14
|
+
import org.embulk.config.TaskReport;
|
15
|
+
import org.embulk.input.marketo.MarketoService;
|
16
|
+
import org.embulk.input.marketo.MarketoServiceImpl;
|
17
|
+
import org.embulk.input.marketo.rest.MarketoRestClient;
|
18
|
+
import org.embulk.spi.Exec;
|
19
|
+
import org.embulk.spi.PageBuilder;
|
20
|
+
import org.embulk.spi.Schema;
|
21
|
+
import org.joda.time.DateTime;
|
22
|
+
|
23
|
+
import java.util.Iterator;
|
24
|
+
import java.util.List;
|
25
|
+
|
26
|
+
/**
|
27
|
+
* Created by tai.khuu on 9/18/17.
|
28
|
+
*/
|
29
|
+
public abstract class MarketoBaseInputPluginDelegate<T extends MarketoBaseInputPluginDelegate.PluginTask> implements RestClientInputPluginDelegate<T>
|
30
|
+
{
|
31
|
+
public static final int PREVIEW_RECORD_LIMIT = 15;
|
32
|
+
public interface PluginTask
|
33
|
+
extends RestClientInputTaskBase, MarketoRestClient.PluginTask
|
34
|
+
{
|
35
|
+
@Config("schema_column_prefix")
|
36
|
+
@ConfigDefault("\"mk\"")
|
37
|
+
String getSchemaColumnPrefix();
|
38
|
+
|
39
|
+
@Config("incremental")
|
40
|
+
@ConfigDefault("true")
|
41
|
+
Boolean getIncremental();
|
42
|
+
|
43
|
+
DateTime getJobStartTime();
|
44
|
+
|
45
|
+
void setJobStartTime(DateTime dateTime);
|
46
|
+
}
|
47
|
+
|
48
|
+
@Override
|
49
|
+
public ConfigDiff buildConfigDiff(T task, Schema schema, int taskCount, List<TaskReport> taskReports)
|
50
|
+
{
|
51
|
+
return Exec.newConfigDiff();
|
52
|
+
}
|
53
|
+
|
54
|
+
@Override
|
55
|
+
public void validateInputTask(T task)
|
56
|
+
{
|
57
|
+
task.setJobStartTime(DateTime.now());
|
58
|
+
}
|
59
|
+
|
60
|
+
@Override
|
61
|
+
public TaskReport ingestServiceData(T task, RecordImporter recordImporter, int taskIndex, PageBuilder pageBuilder)
|
62
|
+
{
|
63
|
+
if (Exec.isPreview()) {
|
64
|
+
task.setBatchSize(PREVIEW_RECORD_LIMIT);
|
65
|
+
}
|
66
|
+
try (MarketoRestClient restClient = createMarketoRestClient(task)) {
|
67
|
+
MarketoService marketoService = new MarketoServiceImpl(restClient);
|
68
|
+
Iterator<ServiceRecord> serviceRecords = getServiceRecords(marketoService, task);
|
69
|
+
int imported = 0;
|
70
|
+
while (serviceRecords.hasNext() && (imported < PREVIEW_RECORD_LIMIT || !Exec.isPreview())) {
|
71
|
+
ServiceRecord next = serviceRecords.next();
|
72
|
+
recordImporter.importRecord(next, pageBuilder);
|
73
|
+
imported++;
|
74
|
+
}
|
75
|
+
return Exec.newTaskReport();
|
76
|
+
}
|
77
|
+
}
|
78
|
+
|
79
|
+
protected abstract Iterator<ServiceRecord> getServiceRecords(MarketoService marketoService, T task);
|
80
|
+
|
81
|
+
@VisibleForTesting
|
82
|
+
public MarketoRestClient createMarketoRestClient(PluginTask task)
|
83
|
+
{
|
84
|
+
return new MarketoRestClient(task);
|
85
|
+
}
|
86
|
+
|
87
|
+
@Override
|
88
|
+
public ServiceDataSplitter<T> buildServiceDataSplitter(T task)
|
89
|
+
{
|
90
|
+
return new DefaultServiceDataSplitter();
|
91
|
+
}
|
92
|
+
}
|
@@ -0,0 +1,228 @@
|
|
1
|
+
package org.embulk.input.marketo.delegate;
|
2
|
+
|
3
|
+
import com.fasterxml.jackson.annotation.JsonCreator;
|
4
|
+
import com.fasterxml.jackson.databind.node.ObjectNode;
|
5
|
+
import com.google.common.base.Optional;
|
6
|
+
import com.google.common.collect.FluentIterable;
|
7
|
+
|
8
|
+
import org.embulk.base.restclient.ServiceResponseMapper;
|
9
|
+
import org.embulk.base.restclient.jackson.JacksonServiceResponseMapper;
|
10
|
+
import org.embulk.base.restclient.record.RecordImporter;
|
11
|
+
import org.embulk.base.restclient.record.ServiceRecord;
|
12
|
+
import org.embulk.base.restclient.record.ValueLocator;
|
13
|
+
import org.embulk.config.Config;
|
14
|
+
import org.embulk.config.ConfigDefault;
|
15
|
+
import org.embulk.config.ConfigDiff;
|
16
|
+
import org.embulk.config.ConfigException;
|
17
|
+
import org.embulk.config.TaskReport;
|
18
|
+
import org.embulk.input.marketo.MarketoService;
|
19
|
+
import org.embulk.input.marketo.MarketoUtils;
|
20
|
+
import org.embulk.spi.Exec;
|
21
|
+
import org.embulk.spi.PageBuilder;
|
22
|
+
import org.embulk.spi.Schema;
|
23
|
+
import org.embulk.spi.type.Types;
|
24
|
+
import org.joda.time.DateTime;
|
25
|
+
import org.joda.time.Duration;
|
26
|
+
import org.joda.time.format.DateTimeFormat;
|
27
|
+
import org.joda.time.format.DateTimeFormatter;
|
28
|
+
import org.slf4j.Logger;
|
29
|
+
|
30
|
+
import java.util.Date;
|
31
|
+
import java.util.Iterator;
|
32
|
+
import java.util.List;
|
33
|
+
|
34
|
+
public class ProgramInputPlugin extends MarketoBaseInputPluginDelegate<ProgramInputPlugin.PluginTask>
|
35
|
+
{
|
36
|
+
private static final DateTimeFormatter DATE_FORMATTER = DateTimeFormat.forPattern(MarketoUtils.MARKETO_DATE_SIMPLE_DATE_FORMAT);
|
37
|
+
private final Logger logger = Exec.getLogger(getClass());
|
38
|
+
|
39
|
+
public interface PluginTask extends MarketoBaseInputPluginDelegate.PluginTask
|
40
|
+
{
|
41
|
+
@Config("query_by")
|
42
|
+
@ConfigDefault("null")
|
43
|
+
Optional<QueryBy> getQueryBy();
|
44
|
+
|
45
|
+
@Config("tag_type")
|
46
|
+
@ConfigDefault("null")
|
47
|
+
Optional<String> getTagType();
|
48
|
+
|
49
|
+
@Config("tag_value")
|
50
|
+
@ConfigDefault("null")
|
51
|
+
Optional<String> getTagVallue();
|
52
|
+
|
53
|
+
@Config("earliest_updated_at")
|
54
|
+
@ConfigDefault("null")
|
55
|
+
Optional<Date> getEarliestUpdatedAt();
|
56
|
+
|
57
|
+
@Config("latest_updated_at")
|
58
|
+
@ConfigDefault("null")
|
59
|
+
Optional<Date> getLatestUpdatedAt();
|
60
|
+
|
61
|
+
@Config("filter_type")
|
62
|
+
@ConfigDefault("null")
|
63
|
+
Optional<String> getFilterType();
|
64
|
+
|
65
|
+
@Config("filter_values")
|
66
|
+
@ConfigDefault("null")
|
67
|
+
Optional<List<String>> getFilterValues();
|
68
|
+
|
69
|
+
@Config("report_duration")
|
70
|
+
@ConfigDefault("null")
|
71
|
+
Optional<Long> getReportDuration();
|
72
|
+
|
73
|
+
void setLatestUpdatedAt(Optional<Date> latestUpdatedAt);
|
74
|
+
}
|
75
|
+
|
76
|
+
public ProgramInputPlugin()
|
77
|
+
{
|
78
|
+
}
|
79
|
+
|
80
|
+
@Override
|
81
|
+
public void validateInputTask(PluginTask task)
|
82
|
+
{
|
83
|
+
super.validateInputTask(task);
|
84
|
+
// validate if query_by is selected
|
85
|
+
if (task.getQueryBy().isPresent()) {
|
86
|
+
switch(task.getQueryBy().get()) {
|
87
|
+
case TAG_TYPE:
|
88
|
+
//make sure tag type and tag value are not empty
|
89
|
+
if (!task.getTagType().isPresent() || !task.getTagVallue().isPresent()) {
|
90
|
+
throw new ConfigException("tag_type and tag_value are required when query by Tag Type");
|
91
|
+
}
|
92
|
+
break;
|
93
|
+
case DATE_RANGE:
|
94
|
+
// make sure earliest_updated_at is not empty
|
95
|
+
if (!task.getEarliestUpdatedAt().isPresent()) {
|
96
|
+
throw new ConfigException("`earliest_updated_at` is required when query by Date Range");
|
97
|
+
}
|
98
|
+
|
99
|
+
DateTime earliest = new DateTime(task.getEarliestUpdatedAt().get());
|
100
|
+
if (task.getReportDuration().isPresent()) {
|
101
|
+
logger.info("`report_duration` is present, Prefer `report_duration` over `latest_updated_at`");
|
102
|
+
// Update the latestUpdatedAt for the config
|
103
|
+
DateTime latest = earliest.plus(task.getReportDuration().get());
|
104
|
+
task.setLatestUpdatedAt(Optional.of(latest.toDate()));
|
105
|
+
}
|
106
|
+
|
107
|
+
// latest_updated_at is required calculate time range
|
108
|
+
if (!task.getLatestUpdatedAt().isPresent()) {
|
109
|
+
throw new ConfigException("`latest_updated_at` is required when query by Date Range");
|
110
|
+
}
|
111
|
+
|
112
|
+
DateTime latest = new DateTime(task.getLatestUpdatedAt().get());
|
113
|
+
if (earliest.isAfter(DateTime.now())) {
|
114
|
+
throw new ConfigException(String.format("`earliest_updated_at` (%s) cannot precede the current date (%s)",
|
115
|
+
earliest.toString(DATE_FORMATTER),
|
116
|
+
(DateTime.now().toString(DATE_FORMATTER))));
|
117
|
+
}
|
118
|
+
|
119
|
+
if (earliest.isAfter(latest)) {
|
120
|
+
throw new ConfigException(String.format("Invalid date range. `earliest_updated_at` (%s) cannot precede the `latest_updated_at` (%s).",
|
121
|
+
earliest.toString(DATE_FORMATTER),
|
122
|
+
latest.toString(DATE_FORMATTER)));
|
123
|
+
}
|
124
|
+
// if filter type is selected, filter value must be presented
|
125
|
+
if (task.getFilterType().isPresent() && (!task.getFilterValues().isPresent() || task.getFilterValues().get().isEmpty())) {
|
126
|
+
throw new ConfigException("filter_value is required when selected filter_type");
|
127
|
+
}
|
128
|
+
}
|
129
|
+
}
|
130
|
+
}
|
131
|
+
|
132
|
+
@Override
|
133
|
+
public TaskReport ingestServiceData(PluginTask task, RecordImporter recordImporter, int taskIndex, PageBuilder pageBuilder)
|
134
|
+
{
|
135
|
+
// query by date range and incremental import and not preview
|
136
|
+
if (task.getQueryBy().isPresent() && task.getQueryBy().get() == QueryBy.DATE_RANGE && task.getIncremental() && !Exec.isPreview()) {
|
137
|
+
DateTime latestUpdateAt = new DateTime(task.getLatestUpdatedAt().get());
|
138
|
+
DateTime now = DateTime.now();
|
139
|
+
// Do not run incremental import if latest_updated_at precede current time
|
140
|
+
if (latestUpdateAt.isAfter(now)) {
|
141
|
+
logger.warn("`latest_updated_at` ({}) preceded current time ({}). Will try to import next run", latestUpdateAt.toString(DATE_FORMATTER), now.toString(DATE_FORMATTER));
|
142
|
+
|
143
|
+
TaskReport taskReport = Exec.newTaskReport();
|
144
|
+
taskReport.set("earliest_updated_at", new DateTime(task.getEarliestUpdatedAt().get()).toString(DATE_FORMATTER));
|
145
|
+
if (task.getReportDuration().isPresent()) {
|
146
|
+
taskReport.set("report_duration", task.getReportDuration().get());
|
147
|
+
}
|
148
|
+
return taskReport;
|
149
|
+
}
|
150
|
+
}
|
151
|
+
return super.ingestServiceData(task, recordImporter, taskIndex, pageBuilder);
|
152
|
+
}
|
153
|
+
|
154
|
+
@Override
|
155
|
+
protected Iterator<ServiceRecord> getServiceRecords(MarketoService marketoService, PluginTask task)
|
156
|
+
{
|
157
|
+
Iterable<ObjectNode> nodes = null;
|
158
|
+
if (task.getQueryBy().isPresent()) {
|
159
|
+
switch (task.getQueryBy().get()) {
|
160
|
+
case TAG_TYPE:
|
161
|
+
nodes = marketoService.getProgramsByTag(task.getTagType().get(), task.getTagVallue().get());
|
162
|
+
break;
|
163
|
+
case DATE_RANGE:
|
164
|
+
nodes = marketoService.getProgramsByDateRange(task.getEarliestUpdatedAt().get(),
|
165
|
+
task.getLatestUpdatedAt().get(),
|
166
|
+
task.getFilterType().orNull(),
|
167
|
+
task.getFilterValues().orNull());
|
168
|
+
}
|
169
|
+
}
|
170
|
+
else {
|
171
|
+
nodes = marketoService.getPrograms();
|
172
|
+
}
|
173
|
+
return FluentIterable.from(nodes).transform(MarketoUtils.TRANSFORM_OBJECT_TO_JACKSON_SERVICE_RECORD_FUNCTION).iterator();
|
174
|
+
}
|
175
|
+
|
176
|
+
@Override
|
177
|
+
public ConfigDiff buildConfigDiff(PluginTask task, Schema schema, int taskCount, List<TaskReport> taskReports)
|
178
|
+
{
|
179
|
+
ConfigDiff configDiff = super.buildConfigDiff(task, schema, taskCount, taskReports);
|
180
|
+
// set next next earliestUpdatedAt, latestUpdatedAt
|
181
|
+
if (task.getQueryBy().isPresent() && task.getQueryBy().get() == QueryBy.DATE_RANGE && task.getIncremental()) {
|
182
|
+
DateTime earliest = new DateTime(task.getEarliestUpdatedAt().get());
|
183
|
+
DateTime latest = new DateTime(task.getLatestUpdatedAt().get());
|
184
|
+
|
185
|
+
Duration d = new Duration(earliest, latest);
|
186
|
+
DateTime nextEarliestUpdatedAt = latest.plusSeconds(1);
|
187
|
+
|
188
|
+
configDiff.set("earliest_updated_at", nextEarliestUpdatedAt.toString(DATE_FORMATTER));
|
189
|
+
configDiff.set("report_duration", task.getReportDuration().or(d.getMillis()));
|
190
|
+
}
|
191
|
+
return configDiff;
|
192
|
+
}
|
193
|
+
|
194
|
+
@Override
|
195
|
+
public ServiceResponseMapper<? extends ValueLocator> buildServiceResponseMapper(PluginTask task)
|
196
|
+
{
|
197
|
+
JacksonServiceResponseMapper.Builder builder = JacksonServiceResponseMapper.builder();
|
198
|
+
builder.add("id", Types.LONG)
|
199
|
+
.add("name", Types.STRING)
|
200
|
+
.add("sfdcId", Types.STRING)
|
201
|
+
.add("sfdcName", Types.STRING)
|
202
|
+
.add("description", Types.STRING)
|
203
|
+
.add("createdAt", Types.TIMESTAMP, MarketoUtils.MARKETO_DATE_TIME_FORMAT)
|
204
|
+
.add("updatedAt", Types.TIMESTAMP, MarketoUtils.MARKETO_DATE_TIME_FORMAT)
|
205
|
+
.add("startDate", Types.TIMESTAMP, MarketoUtils.MARKETO_DATE_TIME_FORMAT)
|
206
|
+
.add("endDate", Types.TIMESTAMP, MarketoUtils.MARKETO_DATE_TIME_FORMAT)
|
207
|
+
.add("url", Types.STRING)
|
208
|
+
.add("type", Types.STRING)
|
209
|
+
.add("channel", Types.STRING)
|
210
|
+
.add("folder", Types.JSON)
|
211
|
+
.add("status", Types.STRING)
|
212
|
+
.add("costs", Types.JSON)
|
213
|
+
.add("tags", Types.JSON)
|
214
|
+
.add("workspace", Types.STRING);
|
215
|
+
return builder.build();
|
216
|
+
}
|
217
|
+
|
218
|
+
public enum QueryBy {
|
219
|
+
TAG_TYPE,
|
220
|
+
DATE_RANGE;
|
221
|
+
|
222
|
+
@JsonCreator
|
223
|
+
public static QueryBy of(String value)
|
224
|
+
{
|
225
|
+
return QueryBy.valueOf(value.toUpperCase());
|
226
|
+
}
|
227
|
+
}
|
228
|
+
}
|
@@ -0,0 +1,30 @@
|
|
1
|
+
package org.embulk.input.marketo.exception;
|
2
|
+
|
3
|
+
import org.embulk.input.marketo.model.MarketoError;
|
4
|
+
|
5
|
+
import java.util.List;
|
6
|
+
|
7
|
+
/**
|
8
|
+
* Exception class for all API Exception
|
9
|
+
* Created by tai.khuu on 9/5/17.
|
10
|
+
*/
|
11
|
+
public class MarketoAPIException extends Exception
|
12
|
+
{
|
13
|
+
private final List<MarketoError> marketoErrors;
|
14
|
+
public MarketoAPIException(List<MarketoError> marketoErrors)
|
15
|
+
{
|
16
|
+
this.marketoErrors = marketoErrors;
|
17
|
+
}
|
18
|
+
|
19
|
+
public List<MarketoError> getMarketoErrors()
|
20
|
+
{
|
21
|
+
return marketoErrors;
|
22
|
+
}
|
23
|
+
|
24
|
+
@Override
|
25
|
+
public String getMessage()
|
26
|
+
{
|
27
|
+
MarketoError error = getMarketoErrors().get(0);
|
28
|
+
return "Marketo API Error, code: " + error.getCode() + ", message: " + error.getMessage();
|
29
|
+
}
|
30
|
+
}
|
@@ -0,0 +1,26 @@
|
|
1
|
+
package org.embulk.input.marketo.model;
|
2
|
+
|
3
|
+
/**
|
4
|
+
* Created by tai.khuu on 10/12/17.
|
5
|
+
*/
|
6
|
+
public class BulkExtractRangeHeader
|
7
|
+
{
|
8
|
+
private Long start;
|
9
|
+
private Long end;
|
10
|
+
|
11
|
+
public BulkExtractRangeHeader(long start)
|
12
|
+
{
|
13
|
+
this.start = start;
|
14
|
+
}
|
15
|
+
|
16
|
+
public BulkExtractRangeHeader(long start, long end)
|
17
|
+
{
|
18
|
+
this.start = start;
|
19
|
+
this.end = end;
|
20
|
+
}
|
21
|
+
|
22
|
+
public String toRangeHeaderValue()
|
23
|
+
{
|
24
|
+
return "bytes=" + start + "-" + (end != null ? end : "");
|
25
|
+
}
|
26
|
+
}
|
@@ -0,0 +1,92 @@
|
|
1
|
+
package org.embulk.input.marketo.model;
|
2
|
+
|
3
|
+
import com.fasterxml.jackson.annotation.JsonProperty;
|
4
|
+
|
5
|
+
/**
|
6
|
+
* Created by tai.khuu on 8/25/17.
|
7
|
+
*/
|
8
|
+
public class MarketoAccessTokenResponse
|
9
|
+
{
|
10
|
+
@JsonProperty("error")
|
11
|
+
private String error;
|
12
|
+
|
13
|
+
@JsonProperty("error_description")
|
14
|
+
private String errorDescription;
|
15
|
+
|
16
|
+
@JsonProperty("access_token")
|
17
|
+
private String accessToken;
|
18
|
+
|
19
|
+
@JsonProperty("token_type")
|
20
|
+
private String tokenType;
|
21
|
+
|
22
|
+
@JsonProperty("expires_in")
|
23
|
+
private Integer expiresIn;
|
24
|
+
|
25
|
+
@JsonProperty("scope")
|
26
|
+
private String scope;
|
27
|
+
|
28
|
+
public String getError()
|
29
|
+
{
|
30
|
+
return error;
|
31
|
+
}
|
32
|
+
|
33
|
+
public void setError(String error)
|
34
|
+
{
|
35
|
+
this.error = error;
|
36
|
+
}
|
37
|
+
|
38
|
+
public String getErrorDescription()
|
39
|
+
{
|
40
|
+
return errorDescription;
|
41
|
+
}
|
42
|
+
|
43
|
+
public void setErrorDescription(String errorDescription)
|
44
|
+
{
|
45
|
+
this.errorDescription = errorDescription;
|
46
|
+
}
|
47
|
+
|
48
|
+
public String getAccessToken()
|
49
|
+
{
|
50
|
+
return accessToken;
|
51
|
+
}
|
52
|
+
|
53
|
+
public void setAccessToken(String accessToken)
|
54
|
+
{
|
55
|
+
this.accessToken = accessToken;
|
56
|
+
}
|
57
|
+
|
58
|
+
public String getTokenType()
|
59
|
+
{
|
60
|
+
return tokenType;
|
61
|
+
}
|
62
|
+
|
63
|
+
public void setTokenType(String tokenType)
|
64
|
+
{
|
65
|
+
this.tokenType = tokenType;
|
66
|
+
}
|
67
|
+
|
68
|
+
public Integer getExpiresIn()
|
69
|
+
{
|
70
|
+
return expiresIn;
|
71
|
+
}
|
72
|
+
|
73
|
+
public void setExpiresIn(Integer expiresIn)
|
74
|
+
{
|
75
|
+
this.expiresIn = expiresIn;
|
76
|
+
}
|
77
|
+
|
78
|
+
public String getScope()
|
79
|
+
{
|
80
|
+
return scope;
|
81
|
+
}
|
82
|
+
|
83
|
+
public void setScope(String scope)
|
84
|
+
{
|
85
|
+
this.scope = scope;
|
86
|
+
}
|
87
|
+
|
88
|
+
public boolean hasError()
|
89
|
+
{
|
90
|
+
return error != null;
|
91
|
+
}
|
92
|
+
}
|