embulk-input-yelp 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/build.gradle +3 -2
- data/classpath/embulk-base-restclient-0.5.0.jar +0 -0
- data/classpath/embulk-input-yelp-0.2.0.jar +0 -0
- data/classpath/embulk-util-retryhelper-jaxrs-0.5.0.jar +0 -0
- data/src/main/java/org/embulk/input/yelp/YelpInputPluginDelegate.java +69 -44
- metadata +5 -4
- data/classpath/embulk-base-restclient-0.2.3.jar +0 -0
- data/classpath/embulk-input-yelp-0.1.0.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: 7c512afdcd58e854fe161d5bf3a4515b3a82626f
|
4
|
+
data.tar.gz: d4763db55ffcd4f4c8bb3cee6c47956874d3b0c9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f1508770e8b35eff5639e559c0bcb312b4490f001a270589878cf604ede3526089e8a9a0ca4c38b1691c4275e479a55d0b985d7799c10f0f105cc1cc5f6f718c
|
7
|
+
data.tar.gz: 0b5463a4096d0f43e06deede02cc801683dbba031d7b7da639ba5fa3b3598cb54a6aa50d708455b459b8a160853fe422656852a55fc8442eecc164a547d4f68d
|
data/build.gradle
CHANGED
@@ -17,7 +17,7 @@ configurations {
|
|
17
17
|
provided
|
18
18
|
}
|
19
19
|
|
20
|
-
version = "0.
|
20
|
+
version = "0.2.0"
|
21
21
|
|
22
22
|
sourceCompatibility = 1.7
|
23
23
|
targetCompatibility = 1.7
|
@@ -25,7 +25,8 @@ targetCompatibility = 1.7
|
|
25
25
|
dependencies {
|
26
26
|
compile "org.embulk:embulk-core:0.8.17"
|
27
27
|
provided "org.embulk:embulk-core:0.8.17"
|
28
|
-
compile "org.embulk.base.restclient:embulk-base-restclient:0.
|
28
|
+
compile "org.embulk.base.restclient:embulk-base-restclient:0.5.0"
|
29
|
+
compile "org.embulk.base.restclient:embulk-util-retryhelper-jaxrs:0.5.0"
|
29
30
|
compile "org.glassfish.jersey.core:jersey-client:2.25.1"
|
30
31
|
testCompile "junit:junit:4.+"
|
31
32
|
}
|
Binary file
|
Binary file
|
Binary file
|
@@ -4,16 +4,19 @@ import java.util.List;
|
|
4
4
|
import java.util.Locale;
|
5
5
|
|
6
6
|
import javax.ws.rs.core.Response;
|
7
|
+
import javax.ws.rs.client.WebTarget;
|
7
8
|
|
8
9
|
import com.fasterxml.jackson.databind.JsonNode;
|
9
10
|
import com.fasterxml.jackson.databind.node.ArrayNode;
|
10
11
|
import com.fasterxml.jackson.databind.node.ObjectNode;
|
11
12
|
|
13
|
+
import com.google.common.base.Optional;
|
12
14
|
import com.google.common.collect.Ordering;
|
13
15
|
|
14
16
|
import org.embulk.config.Config;
|
15
17
|
import org.embulk.config.ConfigDefault;
|
16
18
|
import org.embulk.config.ConfigDiff;
|
19
|
+
import org.embulk.config.ConfigException;
|
17
20
|
import org.embulk.config.TaskReport;
|
18
21
|
import org.embulk.spi.DataException;
|
19
22
|
import org.embulk.spi.Exec;
|
@@ -21,16 +24,20 @@ import org.embulk.spi.PageBuilder;
|
|
21
24
|
import org.embulk.spi.Schema;
|
22
25
|
import org.embulk.spi.type.Types;
|
23
26
|
|
27
|
+
import org.embulk.base.restclient.DefaultServiceDataSplitter;
|
24
28
|
import org.embulk.base.restclient.RestClientInputPluginDelegate;
|
25
29
|
import org.embulk.base.restclient.RestClientInputTaskBase;
|
30
|
+
import org.embulk.base.restclient.ServiceDataSplitter;
|
26
31
|
import org.embulk.base.restclient.jackson.JacksonJsonPointerValueLocator;
|
27
32
|
import org.embulk.base.restclient.jackson.JacksonServiceRecord;
|
28
33
|
import org.embulk.base.restclient.jackson.JacksonServiceResponseMapper;
|
29
34
|
import org.embulk.base.restclient.jackson.StringJsonParser;
|
30
35
|
import org.embulk.base.restclient.record.RecordImporter;
|
31
|
-
|
32
|
-
import org.embulk.
|
33
|
-
import org.embulk.
|
36
|
+
|
37
|
+
import org.embulk.util.retryhelper.jaxrs.JAXRSClientCreator;
|
38
|
+
import org.embulk.util.retryhelper.jaxrs.JAXRSRetryHelper;
|
39
|
+
import org.embulk.util.retryhelper.jaxrs.JAXRSSingleRequester;
|
40
|
+
import org.embulk.util.retryhelper.jaxrs.StringJAXRSResponseEntityReader;
|
34
41
|
|
35
42
|
import org.slf4j.Logger;
|
36
43
|
|
@@ -44,7 +51,16 @@ public class YelpInputPluginDelegate
|
|
44
51
|
public String getAccessToken();
|
45
52
|
|
46
53
|
@Config("location")
|
47
|
-
|
54
|
+
@ConfigDefault("null")
|
55
|
+
public Optional<String> getLocation();
|
56
|
+
|
57
|
+
@Config("latitude")
|
58
|
+
@ConfigDefault("null")
|
59
|
+
public Optional<String> getLatitude();
|
60
|
+
|
61
|
+
@Config("longitude")
|
62
|
+
@ConfigDefault("null")
|
63
|
+
public Optional<String> getLongitude();
|
48
64
|
|
49
65
|
@Config("maximum_retries")
|
50
66
|
@ConfigDefault("7")
|
@@ -61,9 +77,19 @@ public class YelpInputPluginDelegate
|
|
61
77
|
|
62
78
|
private final StringJsonParser jsonParser = new StringJsonParser();
|
63
79
|
|
64
|
-
@Override // Overridden from |
|
65
|
-
public void
|
80
|
+
@Override // Overridden from |InputTaskValidatable|
|
81
|
+
public void validateInputTask(PluginTask task)
|
66
82
|
{
|
83
|
+
if (!task.getLocation().isPresent() &&
|
84
|
+
!(task.getLatitude().isPresent() && task.getLongitude().isPresent())) {
|
85
|
+
throw new ConfigException("'location' or 'latitude'/'longitude' are required.");
|
86
|
+
}
|
87
|
+
}
|
88
|
+
|
89
|
+
@Override // Overridden from |InputTaskValidatable|
|
90
|
+
public ServiceDataSplitter buildServiceDataSplitter(PluginTask task)
|
91
|
+
{
|
92
|
+
return new DefaultServiceDataSplitter();
|
67
93
|
}
|
68
94
|
|
69
95
|
@Override // Overridden from |ServiceResponseMapperBuildable|
|
@@ -95,7 +121,6 @@ public class YelpInputPluginDelegate
|
|
95
121
|
|
96
122
|
@Override // Overridden from |ServiceDataIngestable|
|
97
123
|
public TaskReport ingestServiceData(final PluginTask task,
|
98
|
-
RetryHelper retryHelper,
|
99
124
|
RecordImporter recordImporter,
|
100
125
|
int taskIndex,
|
101
126
|
PageBuilder pageBuilder)
|
@@ -103,11 +128,25 @@ public class YelpInputPluginDelegate
|
|
103
128
|
TaskReport report = Exec.newTaskReport();
|
104
129
|
for (int offset = 0; offset < 1000; ) {
|
105
130
|
final int limit = Exec.isPreview() ? 5 : (Ordering.natural().min(50, 1000 - offset));
|
106
|
-
String content
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
131
|
+
final String content;
|
132
|
+
try (JAXRSRetryHelper retryHelper = new JAXRSRetryHelper(
|
133
|
+
task.getMaximumRetries(),
|
134
|
+
task.getInitialRetryIntervalMillis(),
|
135
|
+
task.getMaximumRetryIntervalMillis(),
|
136
|
+
new JAXRSClientCreator() {
|
137
|
+
@Override
|
138
|
+
public javax.ws.rs.client.Client create() {
|
139
|
+
return javax.ws.rs.client.ClientBuilder.newBuilder().build();
|
140
|
+
}
|
141
|
+
})) {
|
142
|
+
content = fetchFromYelp(retryHelper,
|
143
|
+
task.getAccessToken(),
|
144
|
+
task.getLocation(),
|
145
|
+
task.getLatitude(),
|
146
|
+
task.getLongitude(),
|
147
|
+
limit,
|
148
|
+
offset);
|
149
|
+
}
|
111
150
|
ArrayNode records = extractArrayField(content);
|
112
151
|
|
113
152
|
for (JsonNode record : records) {
|
@@ -151,23 +190,34 @@ public class YelpInputPluginDelegate
|
|
151
190
|
}
|
152
191
|
}
|
153
192
|
|
154
|
-
private String fetchFromYelp(
|
193
|
+
private String fetchFromYelp(JAXRSRetryHelper retryHelper,
|
155
194
|
final String bearerToken,
|
156
|
-
final String location,
|
195
|
+
final Optional<String> location,
|
196
|
+
final Optional<String> latitude,
|
197
|
+
final Optional<String> longitude,
|
157
198
|
final int limit,
|
158
199
|
final int offset)
|
159
200
|
{
|
160
201
|
return retryHelper.requestWithRetry(
|
161
|
-
new
|
162
|
-
new
|
202
|
+
new StringJAXRSResponseEntityReader(),
|
203
|
+
new JAXRSSingleRequester() {
|
163
204
|
@Override
|
164
205
|
public Response requestOnce(javax.ws.rs.client.Client client)
|
165
206
|
{
|
166
|
-
|
207
|
+
WebTarget webTarget = client
|
167
208
|
.target("https://api.yelp.com/v3/businesses/search")
|
168
|
-
.queryParam("location", location)
|
169
209
|
.queryParam("limit", String.valueOf(limit))
|
170
|
-
.queryParam("offset", String.valueOf(offset))
|
210
|
+
.queryParam("offset", String.valueOf(offset));
|
211
|
+
if (location.isPresent()) {
|
212
|
+
webTarget = webTarget.queryParam("location", location.get());
|
213
|
+
} else if (latitude.isPresent() && longitude.isPresent()) {
|
214
|
+
webTarget = webTarget.queryParam("latitude", latitude.get())
|
215
|
+
.queryParam("longitude", longitude.get());
|
216
|
+
} else {
|
217
|
+
throw new ConfigException(
|
218
|
+
"FATAL: 'location' or 'latitude'/'longitude' are required.");
|
219
|
+
}
|
220
|
+
Response response = webTarget
|
171
221
|
.request()
|
172
222
|
.header("Authorization", "Bearer " + bearerToken)
|
173
223
|
.get();
|
@@ -186,30 +236,5 @@ public class YelpInputPluginDelegate
|
|
186
236
|
});
|
187
237
|
}
|
188
238
|
|
189
|
-
@Override // Overridden from |ClientCreatable|
|
190
|
-
public javax.ws.rs.client.Client createClient(PluginTask task)
|
191
|
-
{
|
192
|
-
// TODO(dmikurube): Configure org.glassfish.jersey.client.ClientProperties.CONNECT_TIMEOUT and READ_TIMEOUT.
|
193
|
-
return javax.ws.rs.client.ClientBuilder.newBuilder().build();
|
194
|
-
}
|
195
|
-
|
196
|
-
@Override // Overridden from |RetryConfigurable|
|
197
|
-
public int configureMaximumRetries(PluginTask task)
|
198
|
-
{
|
199
|
-
return task.getMaximumRetries();
|
200
|
-
}
|
201
|
-
|
202
|
-
@Override // Overridden from |RetryConfigurable|
|
203
|
-
public int configureInitialRetryIntervalMillis(PluginTask task)
|
204
|
-
{
|
205
|
-
return task.getInitialRetryIntervalMillis();
|
206
|
-
}
|
207
|
-
|
208
|
-
@Override // Overridden from |RetryConfigurable|
|
209
|
-
public int configureMaximumRetryIntervalMillis(PluginTask task)
|
210
|
-
{
|
211
|
-
return task.getMaximumRetryIntervalMillis();
|
212
|
-
}
|
213
|
-
|
214
239
|
private final Logger logger = Exec.getLogger(YelpInputPluginDelegate.class);
|
215
240
|
}
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: embulk-input-yelp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dai MIKURUBE
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-05-
|
11
|
+
date: 2017-05-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -60,8 +60,9 @@ files:
|
|
60
60
|
- src/main/java/org/embulk/input/yelp/YelpInputPluginDelegate.java
|
61
61
|
- src/test/java/org/embulk/input/yelp/TestYelpInputPlugin.java
|
62
62
|
- classpath/aopalliance-repackaged-2.5.0-b32.jar
|
63
|
-
- classpath/embulk-base-restclient-0.
|
64
|
-
- classpath/embulk-input-yelp-0.
|
63
|
+
- classpath/embulk-base-restclient-0.5.0.jar
|
64
|
+
- classpath/embulk-input-yelp-0.2.0.jar
|
65
|
+
- classpath/embulk-util-retryhelper-jaxrs-0.5.0.jar
|
65
66
|
- classpath/hk2-api-2.5.0-b32.jar
|
66
67
|
- classpath/hk2-locator-2.5.0-b32.jar
|
67
68
|
- classpath/hk2-utils-2.5.0-b32.jar
|
Binary file
|
Binary file
|