embulk-input-http 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +29 -6
- data/build.gradle +1 -1
- data/example/json-example.yml +1 -0
- data/src/main/java/org/embulk/input/BasicAuthConfig.java +39 -0
- data/src/main/java/org/embulk/input/HttpInputPlugin.java +41 -15
- data/src/main/java/org/embulk/input/ParamsConfig.java +9 -9
- data/src/main/java/org/embulk/input/QueryConfig.java +56 -15
- data/src/main/java/org/embulk/input/RetryHandler.java +3 -3
- data/src/test/java/org/embulk/input/TestParamsConfig.java +101 -0
- data/src/test/java/org/embulk/input/TestQueryConfig.java +125 -0
- metadata +16 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e0fd9d1c50eb1690a68282058341d8dfe47c2706
|
4
|
+
data.tar.gz: e64cca9c2d869cbd0a107331aad8ca91e4187441
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 72182010d6bb889cc86203e466d1cdcf35a64d47e4e38167414b7d204320558e7659aa3c09c0448e679c10a41a6e9884b278e63b545a4271d3b6f10571222760
|
7
|
+
data.tar.gz: cfe7a025c51abc126e4837578815b2139f7c938a0ee41e32f3a5d919589fdb1f03d18c61fa768b299bcd6d2258154dc764ff768c700de6c59c966d14e77bd782
|
data/README.md
CHANGED
@@ -29,11 +29,11 @@ in:
|
|
29
29
|
|
30
30
|
- **type**: specify this plugin as `http`
|
31
31
|
- **url**: base url something like api (required)
|
32
|
-
- **parser**: parser plugin to parse data in response (required)
|
33
32
|
- **params**: pair of name/value to specify query parameter (optional)
|
34
33
|
- **method**: http method, get is used by default (optional)
|
35
34
|
- **user_agent**: the usrr agent to specify request header (optional)
|
36
|
-
- **charset**:
|
35
|
+
- **charset**: charset to specify request header (optional, utf-8 is used by default)
|
36
|
+
- **basic_auth**: username/password for basic authentication (optional)
|
37
37
|
- **open_timeout**: timeout msec to open connection (optional, 2000 is used by default)
|
38
38
|
- **read_timeout**: timeout msec to read content via http (optional, 10000 is used by default)
|
39
39
|
- **max_retries**: max number of retry request if failed (optional, 5 is used by default)
|
@@ -42,15 +42,39 @@ in:
|
|
42
42
|
|
43
43
|
### Brace expansion style in params
|
44
44
|
|
45
|
-
In *params* section, you can specify also multilple
|
45
|
+
In *params* section, you can specify also multilple requests by using **values** or **brace expansion style** with set **expand** true.
|
46
|
+
|
47
|
+
The configuration using **values** is as below:
|
46
48
|
|
47
49
|
```yaml
|
48
|
-
params
|
50
|
+
params:
|
51
|
+
- {name: id, values: [5, 4, 3, 2, 1]}
|
52
|
+
- {name: name, values: ["John", "Paul", "George", "Ringo"], expand: true}
|
53
|
+
```
|
54
|
+
|
55
|
+
Also You can rewrite this configuration by using **brace expansion style** like as follows:
|
56
|
+
|
57
|
+
|
58
|
+
```yaml
|
59
|
+
params:
|
49
60
|
- {name: id, value "{5,4,3,2,1}", expand: true}
|
50
61
|
- {name: name, value "{John,Paul,George,Ringo}", expand: true}
|
51
62
|
```
|
52
63
|
|
53
|
-
|
64
|
+
Then all patterns of query will be called in a defferent request.
|
65
|
+
|
66
|
+
By default, **expand** is false. In this case, all values will be multiple params in one request.
|
67
|
+
|
68
|
+
|
69
|
+
### Use basic authentication
|
70
|
+
|
71
|
+
You can specify username/password for basic authentication.
|
72
|
+
|
73
|
+
```yaml
|
74
|
+
basic_auth:
|
75
|
+
- user: MyUser
|
76
|
+
- password: MyPassword
|
77
|
+
```
|
54
78
|
|
55
79
|
|
56
80
|
## Example
|
@@ -103,7 +127,6 @@ in:
|
|
103
127
|
```
|
104
128
|
|
105
129
|
## TODO
|
106
|
-
- BasicAuth
|
107
130
|
- HTTP-proxy
|
108
131
|
- Custom hedaers
|
109
132
|
- Guess
|
data/build.gradle
CHANGED
data/example/json-example.yml
CHANGED
@@ -0,0 +1,39 @@
|
|
1
|
+
package org.embulk.input;
|
2
|
+
|
3
|
+
import com.fasterxml.jackson.annotation.JsonCreator;
|
4
|
+
import com.fasterxml.jackson.annotation.JsonProperty;
|
5
|
+
import com.google.common.base.Objects;
|
6
|
+
|
7
|
+
public class BasicAuthConfig {
|
8
|
+
|
9
|
+
private final String user;
|
10
|
+
private final String password;
|
11
|
+
|
12
|
+
@JsonCreator
|
13
|
+
public BasicAuthConfig(
|
14
|
+
@JsonProperty("user") String user,
|
15
|
+
@JsonProperty("password") String password) {
|
16
|
+
this.user = user;
|
17
|
+
this.password = password;
|
18
|
+
}
|
19
|
+
|
20
|
+
@JsonProperty("user")
|
21
|
+
public String getUser() {
|
22
|
+
return user;
|
23
|
+
}
|
24
|
+
|
25
|
+
@JsonProperty("password")
|
26
|
+
public String getPassword() {
|
27
|
+
return password;
|
28
|
+
}
|
29
|
+
|
30
|
+
@Override
|
31
|
+
public int hashCode() {
|
32
|
+
return Objects.hashCode(user, password);
|
33
|
+
}
|
34
|
+
|
35
|
+
@Override
|
36
|
+
public String toString() {
|
37
|
+
return String.format("BasicAuthConfig[%s, %s]", getUser(), getPassword());
|
38
|
+
}
|
39
|
+
}
|
@@ -2,13 +2,14 @@ package org.embulk.input;
|
|
2
2
|
|
3
3
|
import com.google.common.base.Optional;
|
4
4
|
import com.google.common.base.Throwables;
|
5
|
+
import com.google.common.collect.Lists;
|
5
6
|
import org.apache.http.Header;
|
6
7
|
import org.apache.http.HttpException;
|
7
8
|
import org.apache.http.HttpResponse;
|
8
|
-
import org.apache.http.conn.HttpClientConnectionManager;
|
9
|
-
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
|
10
|
-
import org.apache.http.util.EntityUtils;
|
11
9
|
import org.apache.http.NameValuePair;
|
10
|
+
import org.apache.http.auth.AuthScope;
|
11
|
+
import org.apache.http.auth.UsernamePasswordCredentials;
|
12
|
+
import org.apache.http.client.CredentialsProvider;
|
12
13
|
import org.apache.http.client.HttpClient;
|
13
14
|
import org.apache.http.client.HttpRequestRetryHandler;
|
14
15
|
import org.apache.http.client.config.RequestConfig;
|
@@ -17,6 +18,7 @@ import org.apache.http.client.methods.HttpGet;
|
|
17
18
|
import org.apache.http.client.methods.HttpPost;
|
18
19
|
import org.apache.http.client.methods.HttpRequestBase;
|
19
20
|
import org.apache.http.client.utils.URIBuilder;
|
21
|
+
import org.apache.http.impl.client.BasicCredentialsProvider;
|
20
22
|
import org.apache.http.impl.client.HttpClientBuilder;
|
21
23
|
import org.apache.http.message.BasicHeader;
|
22
24
|
import org.apache.http.message.BasicNameValuePair;
|
@@ -31,7 +33,6 @@ import org.slf4j.Logger;
|
|
31
33
|
|
32
34
|
import java.io.IOException;
|
33
35
|
import java.io.InputStream;
|
34
|
-
import java.io.ByteArrayInputStream;
|
35
36
|
import java.io.UnsupportedEncodingException;
|
36
37
|
import java.net.URISyntaxException;
|
37
38
|
import java.util.ArrayList;
|
@@ -76,19 +77,26 @@ public class HttpInputPlugin implements FileInputPlugin {
|
|
76
77
|
@Config("sleep_before_request")
|
77
78
|
@ConfigDefault("0")
|
78
79
|
public int getSleepBeforeRequest();
|
80
|
+
|
79
81
|
public void setSleepBeforeRequest(int sleepBeforeRequest);
|
80
82
|
|
81
83
|
@Config("params")
|
82
84
|
@ConfigDefault("null")
|
83
85
|
public Optional<ParamsConfig> getParams();
|
84
86
|
|
87
|
+
@Config("basic_auth")
|
88
|
+
@ConfigDefault("null")
|
89
|
+
public Optional<BasicAuthConfig> getBasicAuth();
|
90
|
+
|
85
91
|
@ConfigInject
|
86
92
|
public BufferAllocator getBufferAllocator();
|
87
93
|
|
88
|
-
public List<
|
89
|
-
|
94
|
+
public List<List<QueryConfig.Query>> getQueries();
|
95
|
+
|
96
|
+
public void setQueries(List<List<QueryConfig.Query>> queries);
|
90
97
|
|
91
98
|
public HttpMethod getHttpMethod();
|
99
|
+
|
92
100
|
public void setHttpMethod(HttpMethod httpMethod);
|
93
101
|
}
|
94
102
|
|
@@ -103,11 +111,11 @@ public class HttpInputPlugin implements FileInputPlugin {
|
|
103
111
|
|
104
112
|
int numOfThreads = 1;
|
105
113
|
if (task.getParams().isPresent()) {
|
106
|
-
List<
|
114
|
+
List<List<QueryConfig.Query>> expandedQueries = task.getParams().get().expandQueries();
|
107
115
|
task.setQueries(expandedQueries);
|
108
116
|
numOfThreads = expandedQueries.size();
|
109
117
|
} else {
|
110
|
-
task.setQueries(
|
118
|
+
task.setQueries(Lists.<List<QueryConfig.Query>>newArrayList());
|
111
119
|
}
|
112
120
|
|
113
121
|
if (numOfThreads == 1) {
|
@@ -164,6 +172,11 @@ public class HttpInputPlugin implements FileInputPlugin {
|
|
164
172
|
builder.setRetryHandler(retryHandler);
|
165
173
|
}
|
166
174
|
|
175
|
+
if (task.getBasicAuth().isPresent()) {
|
176
|
+
builder.setDefaultCredentialsProvider(makeCredentialsProvider(task.getBasicAuth().get(),
|
177
|
+
request));
|
178
|
+
}
|
179
|
+
|
167
180
|
HttpClient client = builder.build();
|
168
181
|
|
169
182
|
if (task.getSleepBeforeRequest() > 0) {
|
@@ -190,26 +203,39 @@ public class HttpInputPlugin implements FileInputPlugin {
|
|
190
203
|
}
|
191
204
|
}
|
192
205
|
|
206
|
+
private CredentialsProvider makeCredentialsProvider(BasicAuthConfig config, HttpRequestBase scopeRequest) {
|
207
|
+
final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
|
208
|
+
final AuthScope authScope = new AuthScope(scopeRequest.getURI().getHost(),
|
209
|
+
scopeRequest.getURI().getPort());
|
210
|
+
credentialsProvider.setCredentials(authScope,
|
211
|
+
new UsernamePasswordCredentials(config.getUser(), config.getPassword()));
|
212
|
+
return credentialsProvider;
|
213
|
+
}
|
214
|
+
|
193
215
|
private HttpRequestBase makeRequest(PluginTask task, int taskIndex)
|
194
216
|
throws URISyntaxException, UnsupportedEncodingException {
|
195
|
-
final
|
217
|
+
final List<QueryConfig.Query> queries = (task.getQueries().isEmpty()) ?
|
196
218
|
null : task.getQueries().get(taskIndex);
|
197
219
|
if (task.getHttpMethod() == HttpMethod.GET) {
|
198
220
|
HttpGet request = new HttpGet(task.getUrl());
|
199
|
-
if (
|
221
|
+
if (queries != null) {
|
200
222
|
URIBuilder builder = new URIBuilder(request.getURI());
|
201
|
-
for (QueryConfig
|
202
|
-
|
223
|
+
for (QueryConfig.Query q : queries) {
|
224
|
+
for (String v : q.getValues()) {
|
225
|
+
builder.addParameter(q.getName(), v);
|
226
|
+
}
|
203
227
|
}
|
204
228
|
request.setURI(builder.build());
|
205
229
|
}
|
206
230
|
return request;
|
207
231
|
} else if (task.getHttpMethod() == HttpMethod.POST) {
|
208
232
|
HttpPost request = new HttpPost(task.getUrl());
|
209
|
-
if (
|
233
|
+
if (queries != null) {
|
210
234
|
List<NameValuePair> pairs = new ArrayList<>();
|
211
|
-
for (QueryConfig
|
212
|
-
|
235
|
+
for (QueryConfig.Query q : queries) {
|
236
|
+
for (String v : q.getValues()) {
|
237
|
+
pairs.add(new BasicNameValuePair(q.getName(), v));
|
238
|
+
}
|
213
239
|
}
|
214
240
|
request.setEntity(new UrlEncodedFormEntity(pairs));
|
215
241
|
}
|
@@ -21,26 +21,26 @@ public class ParamsConfig {
|
|
21
21
|
return queries;
|
22
22
|
}
|
23
23
|
|
24
|
-
public List<
|
25
|
-
List<List<QueryConfig>> base = new ArrayList<>(queries.size());
|
24
|
+
public List<List<QueryConfig.Query>> expandQueries() {
|
25
|
+
List<List<QueryConfig.Query>> base = new ArrayList<>(queries.size());
|
26
26
|
for (QueryConfig p : queries) {
|
27
27
|
base.add(p.expand());
|
28
28
|
}
|
29
29
|
|
30
30
|
int productSize = 1;
|
31
31
|
int baseSize = base.size();
|
32
|
-
for (int i = 0; i < baseSize; productSize *= base.get(i).size(), i++);
|
32
|
+
for (int i = 0; i < baseSize; productSize *= base.get(i).size(), i++) ;
|
33
33
|
|
34
|
-
List<
|
35
|
-
for(int i = 0; i < productSize; i++) {
|
34
|
+
List<List<QueryConfig.Query>> expands = new ArrayList<>(productSize);
|
35
|
+
for (int i = 0; i < productSize; i++) {
|
36
36
|
int j = 1;
|
37
|
-
List<QueryConfig> query = new ArrayList<>();
|
38
|
-
for(List<QueryConfig> list : base) {
|
39
|
-
QueryConfig pc = list.get((i / j) % list.size());
|
37
|
+
List<QueryConfig.Query> query = new ArrayList<>();
|
38
|
+
for (List<QueryConfig.Query> list : base) {
|
39
|
+
QueryConfig.Query pc = list.get((i / j) % list.size());
|
40
40
|
query.add(pc);
|
41
41
|
j *= list.size();
|
42
42
|
}
|
43
|
-
expands.add(
|
43
|
+
expands.add(query);
|
44
44
|
}
|
45
45
|
|
46
46
|
return expands;
|
@@ -1,8 +1,9 @@
|
|
1
1
|
package org.embulk.input;
|
2
2
|
|
3
|
-
import com.google.common.base.Objects;
|
4
3
|
import com.fasterxml.jackson.annotation.JsonCreator;
|
5
4
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
5
|
+
import com.google.common.base.Objects;
|
6
|
+
import com.google.common.base.Optional;
|
6
7
|
|
7
8
|
import java.util.ArrayList;
|
8
9
|
import java.util.List;
|
@@ -10,30 +11,48 @@ import java.util.List;
|
|
10
11
|
public class QueryConfig {
|
11
12
|
|
12
13
|
private final String name;
|
13
|
-
private final String value;
|
14
|
+
private final Optional<String> value;
|
15
|
+
private final Optional<List<String>> values;
|
14
16
|
private final boolean expand;
|
15
17
|
|
16
18
|
@JsonCreator
|
17
19
|
public QueryConfig(
|
18
20
|
@JsonProperty("name") String name,
|
19
|
-
@JsonProperty("value") String value,
|
21
|
+
@JsonProperty("value") Optional<String> value,
|
22
|
+
@JsonProperty("values") Optional<List<String>> values,
|
20
23
|
@JsonProperty("expand") boolean expand) {
|
21
24
|
this.name = name;
|
22
25
|
this.value = value;
|
26
|
+
this.values = values;
|
23
27
|
this.expand = expand;
|
24
28
|
}
|
25
29
|
|
26
|
-
public List<
|
27
|
-
List<
|
28
|
-
if (
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
30
|
+
public List<Query> expand() {
|
31
|
+
List<Query> dest;
|
32
|
+
if (value.isPresent()) {
|
33
|
+
if (expand) {
|
34
|
+
List<String> expanded = BraceExpansion.expand(value.get());
|
35
|
+
dest = new ArrayList<>(expanded.size());
|
36
|
+
for (String s : expanded) {
|
37
|
+
dest.add(new Query(name, s));
|
38
|
+
}
|
39
|
+
} else {
|
40
|
+
dest = new ArrayList<>(1);
|
41
|
+
dest.add(new Query(name, value.get()));
|
36
42
|
}
|
43
|
+
} else if (values.isPresent()) {
|
44
|
+
if (expand) {
|
45
|
+
dest = new ArrayList<>(values.get().size());
|
46
|
+
for (String s : values.get()) {
|
47
|
+
dest.add(new Query(name, s));
|
48
|
+
}
|
49
|
+
} else {
|
50
|
+
dest = new ArrayList<>(1);
|
51
|
+
final String[] valueArr = values.get().toArray(new String[values.get().size()]);
|
52
|
+
dest.add(new Query(name, valueArr));
|
53
|
+
}
|
54
|
+
} else {
|
55
|
+
throw new IllegalArgumentException("value or values must be specified to 'params'");
|
37
56
|
}
|
38
57
|
return dest;
|
39
58
|
}
|
@@ -44,7 +63,7 @@ public class QueryConfig {
|
|
44
63
|
}
|
45
64
|
|
46
65
|
@JsonProperty("value")
|
47
|
-
public String getValue() {
|
66
|
+
public Optional<String> getValue() {
|
48
67
|
return value;
|
49
68
|
}
|
50
69
|
|
@@ -78,6 +97,26 @@ public class QueryConfig {
|
|
78
97
|
getName(), getValue(), isExpand());
|
79
98
|
}
|
80
99
|
|
100
|
+
public static class Query {
|
101
|
+
private final String name;
|
102
|
+
private final String[] values;
|
103
|
+
|
104
|
+
public Query(
|
105
|
+
@JsonProperty("name") String name,
|
106
|
+
@JsonProperty("values") String... values) {
|
107
|
+
this.name = name;
|
108
|
+
this.values = values;
|
109
|
+
}
|
110
|
+
|
111
|
+
public String getName() {
|
112
|
+
return name;
|
113
|
+
}
|
114
|
+
|
115
|
+
public String[] getValues() {
|
116
|
+
return values;
|
117
|
+
}
|
118
|
+
}
|
119
|
+
|
81
120
|
private static class BraceExpansion {
|
82
121
|
|
83
122
|
public static List<String> expand(String s) {
|
@@ -112,7 +151,9 @@ public class QueryConfig {
|
|
112
151
|
if (suffix.length() > 0) {
|
113
152
|
expandRecursive(prefix + s, suffix, "", dest);
|
114
153
|
} else {
|
115
|
-
|
154
|
+
final String out = String.format("%s%s%s", prefix, s, suffix).
|
155
|
+
replaceAll("[\\\\]{2}", "\\").replaceAll("[\\\\]([,}{])", "$1");
|
156
|
+
dest.add(out);
|
116
157
|
}
|
117
158
|
} else {
|
118
159
|
for (String m : sb.substring(i1 + 1, i2).split("\u0000", -1)) {
|
@@ -31,14 +31,14 @@ public class RetryHandler extends DefaultHttpRequestRetryHandler
|
|
31
31
|
public boolean retryRequest(final IOException exception,
|
32
32
|
final int executionCount, final HttpContext context)
|
33
33
|
{
|
34
|
-
final boolean
|
35
|
-
if (
|
34
|
+
final boolean isRetriable = super.retryRequest(exception, executionCount, context);
|
35
|
+
if (isRetriable) {
|
36
36
|
try {
|
37
37
|
logger.info(String.format("Sleep %d msec before retry", interval));
|
38
38
|
Thread.sleep(interval);
|
39
39
|
} catch (InterruptedException e) {}
|
40
40
|
}
|
41
|
-
return
|
41
|
+
return isRetriable;
|
42
42
|
}
|
43
43
|
|
44
44
|
}
|
@@ -0,0 +1,101 @@
|
|
1
|
+
package org.embulk.input;
|
2
|
+
|
3
|
+
import com.google.common.base.Optional;
|
4
|
+
import com.google.common.collect.Lists;
|
5
|
+
import org.junit.Test;
|
6
|
+
|
7
|
+
import java.util.List;
|
8
|
+
|
9
|
+
import static org.junit.Assert.assertEquals;
|
10
|
+
|
11
|
+
public class TestParamsConfig {
|
12
|
+
|
13
|
+
@Test
|
14
|
+
public void testUnexpandQueriesSinglePair() throws Exception {
|
15
|
+
Optional<List<String>> nullValues = Optional.absent();
|
16
|
+
QueryConfig q1 = new QueryConfig("test1", Optional.of("awasome1"), nullValues, false);
|
17
|
+
QueryConfig q2 = new QueryConfig("test2", Optional.of("awasome2"), nullValues, false);
|
18
|
+
ParamsConfig paramsConfig = new ParamsConfig(Lists.newArrayList(q1, q2));
|
19
|
+
List<List<QueryConfig.Query>> dest = paramsConfig.expandQueries();
|
20
|
+
assertEquals(dest.size(), 1);
|
21
|
+
assertEquals(dest.get(0).size(), 2);
|
22
|
+
assertEquals(dest.get(0).get(0).getName(), "test1");
|
23
|
+
assertEquals(dest.get(0).get(0).getValues()[0], "awasome1");
|
24
|
+
assertEquals(dest.get(0).get(1).getName(), "test2");
|
25
|
+
assertEquals(dest.get(0).get(1).getValues()[0], "awasome2");
|
26
|
+
}
|
27
|
+
|
28
|
+
@Test
|
29
|
+
public void testUnexpandQueriesExpandPair() throws Exception {
|
30
|
+
Optional<String> nullValue = Optional.absent();
|
31
|
+
List<String> values1 = Lists.newArrayList("a", "b");
|
32
|
+
List<String> values2 = Lists.newArrayList("c", "d");
|
33
|
+
|
34
|
+
QueryConfig q1 = new QueryConfig("test1", nullValue, Optional.of(values1), false);
|
35
|
+
QueryConfig q2 = new QueryConfig("test2", nullValue, Optional.of(values2), false);
|
36
|
+
|
37
|
+
ParamsConfig paramsConfig = new ParamsConfig(Lists.newArrayList(q1, q2));
|
38
|
+
List<List<QueryConfig.Query>> dest = paramsConfig.expandQueries();
|
39
|
+
assertEquals(dest.size(), 1);
|
40
|
+
assertEquals(dest.get(0).size(), 2);
|
41
|
+
assertEquals(dest.get(0).get(0).getName(), "test1");
|
42
|
+
assertEquals(dest.get(0).get(0).getValues()[0], "a");
|
43
|
+
assertEquals(dest.get(0).get(0).getValues()[1], "b");
|
44
|
+
assertEquals(dest.get(0).get(1).getName(), "test2");
|
45
|
+
assertEquals(dest.get(0).get(1).getValues()[0], "c");
|
46
|
+
assertEquals(dest.get(0).get(1).getValues()[1], "d");
|
47
|
+
}
|
48
|
+
|
49
|
+
@Test
|
50
|
+
public void testExpandQueriesSinglePair() throws Exception {
|
51
|
+
Optional<List<String>> nullValues = Optional.absent();
|
52
|
+
QueryConfig q1 = new QueryConfig("test1", Optional.of("awasome1"), nullValues, true);
|
53
|
+
QueryConfig q2 = new QueryConfig("test2", Optional.of("awasome2"), nullValues, true);
|
54
|
+
ParamsConfig paramsConfig = new ParamsConfig(Lists.newArrayList(q1, q2));
|
55
|
+
List<List<QueryConfig.Query>> dest = paramsConfig.expandQueries();
|
56
|
+
assertEquals(dest.size(), 1);
|
57
|
+
assertEquals(dest.get(0).size(), 2);
|
58
|
+
assertEquals(dest.get(0).get(0).getName(), "test1");
|
59
|
+
assertEquals(dest.get(0).get(0).getValues()[0], "awasome1");
|
60
|
+
assertEquals(dest.get(0).get(1).getName(), "test2");
|
61
|
+
assertEquals(dest.get(0).get(1).getValues()[0], "awasome2");
|
62
|
+
}
|
63
|
+
|
64
|
+
@Test
|
65
|
+
public void testExpandQueriesExpandPair() throws Exception {
|
66
|
+
Optional<String> nullValue = Optional.absent();
|
67
|
+
List<String> values1 = Lists.newArrayList("a", "b");
|
68
|
+
List<String> values2 = Lists.newArrayList("c", "d");
|
69
|
+
|
70
|
+
QueryConfig q1 = new QueryConfig("test1", nullValue, Optional.of(values1), true);
|
71
|
+
QueryConfig q2 = new QueryConfig("test2", nullValue, Optional.of(values2), true);
|
72
|
+
|
73
|
+
ParamsConfig paramsConfig = new ParamsConfig(Lists.newArrayList(q1, q2));
|
74
|
+
List<List<QueryConfig.Query>> dest = paramsConfig.expandQueries();
|
75
|
+
assertEquals(dest.size(), 4);
|
76
|
+
|
77
|
+
assertEquals(dest.get(0).size(), 2);
|
78
|
+
assertEquals(dest.get(0).get(0).getName(), "test1");
|
79
|
+
assertEquals(dest.get(0).get(0).getValues()[0], "a");
|
80
|
+
assertEquals(dest.get(0).get(1).getName(), "test2");
|
81
|
+
assertEquals(dest.get(0).get(1).getValues()[0], "c");
|
82
|
+
|
83
|
+
assertEquals(dest.get(1).size(), 2);
|
84
|
+
assertEquals(dest.get(1).get(0).getName(), "test1");
|
85
|
+
assertEquals(dest.get(1).get(0).getValues()[0], "b");
|
86
|
+
assertEquals(dest.get(1).get(1).getName(), "test2");
|
87
|
+
assertEquals(dest.get(1).get(1).getValues()[0], "c");
|
88
|
+
|
89
|
+
assertEquals(dest.get(2).size(), 2);
|
90
|
+
assertEquals(dest.get(2).get(0).getName(), "test1");
|
91
|
+
assertEquals(dest.get(2).get(0).getValues()[0], "a");
|
92
|
+
assertEquals(dest.get(2).get(1).getName(), "test2");
|
93
|
+
assertEquals(dest.get(2).get(1).getValues()[0], "d");
|
94
|
+
|
95
|
+
assertEquals(dest.get(3).size(), 2);
|
96
|
+
assertEquals(dest.get(3).get(0).getName(), "test1");
|
97
|
+
assertEquals(dest.get(3).get(0).getValues()[0], "b");
|
98
|
+
assertEquals(dest.get(3).get(1).getName(), "test2");
|
99
|
+
assertEquals(dest.get(3).get(1).getValues()[0], "d");
|
100
|
+
}
|
101
|
+
}
|
@@ -0,0 +1,125 @@
|
|
1
|
+
package org.embulk.input;
|
2
|
+
|
3
|
+
import com.google.common.base.Optional;
|
4
|
+
import com.google.common.collect.Lists;
|
5
|
+
import org.junit.Test;
|
6
|
+
|
7
|
+
import java.util.List;
|
8
|
+
|
9
|
+
import static org.junit.Assert.assertEquals;
|
10
|
+
|
11
|
+
public class TestQueryConfig {
|
12
|
+
|
13
|
+
@Test
|
14
|
+
public void testUnexpandSingleValue() throws Exception {
|
15
|
+
Optional<List<String>> nullValues = Optional.absent();
|
16
|
+
QueryConfig config = new QueryConfig("test", Optional.of("awesome"), nullValues, false);
|
17
|
+
List<QueryConfig.Query> dest = config.expand();
|
18
|
+
assertEquals(dest.size(), 1);
|
19
|
+
assertEquals(dest.get(0).getName(), "test");
|
20
|
+
assertEquals(dest.get(0).getValues().length, 1);
|
21
|
+
assertEquals(dest.get(0).getValues()[0], "awesome");
|
22
|
+
}
|
23
|
+
|
24
|
+
@Test
|
25
|
+
public void testUnexpandMultiValue() throws Exception {
|
26
|
+
Optional<String> nullValue = Optional.absent();
|
27
|
+
List<String> values = Lists.newArrayList("a", "b", "c");
|
28
|
+
QueryConfig config = new QueryConfig("test", nullValue, Optional.of(values), false);
|
29
|
+
List<QueryConfig.Query> dest = config.expand();
|
30
|
+
assertEquals(dest.size(), 1);
|
31
|
+
assertEquals(dest.get(0).getName(), "test");
|
32
|
+
|
33
|
+
assertEquals(dest.get(0).getValues().length, 3);
|
34
|
+
assertEquals(dest.get(0).getValues()[0], "a");
|
35
|
+
assertEquals(dest.get(0).getValues()[1], "b");
|
36
|
+
assertEquals(dest.get(0).getValues()[2], "c");
|
37
|
+
}
|
38
|
+
|
39
|
+
@Test
|
40
|
+
public void testExpandSingleValue() throws Exception {
|
41
|
+
Optional<List<String>> nullValues = Optional.absent();
|
42
|
+
QueryConfig config = new QueryConfig("test", Optional.of("awesome"), nullValues, true);
|
43
|
+
List<QueryConfig.Query> dest = config.expand();
|
44
|
+
assertEquals(dest.size(), 1);
|
45
|
+
assertEquals(dest.get(0).getName(), "test");
|
46
|
+
assertEquals(dest.get(0).getValues()[0], "awesome");
|
47
|
+
}
|
48
|
+
|
49
|
+
@Test
|
50
|
+
public void testExpandMultiValue() throws Exception {
|
51
|
+
Optional<String> nullValue = Optional.absent();
|
52
|
+
List<String> values = Lists.newArrayList("a", "b", "c");
|
53
|
+
QueryConfig config = new QueryConfig("test", nullValue, Optional.of(values), true);
|
54
|
+
List<QueryConfig.Query> dest = config.expand();
|
55
|
+
assertEquals(dest.size(), 3);
|
56
|
+
assertEquals(dest.get(0).getName(), "test");
|
57
|
+
assertEquals(dest.get(0).getValues().length, 1);
|
58
|
+
assertEquals(dest.get(0).getValues()[0], "a");
|
59
|
+
|
60
|
+
assertEquals(dest.get(1).getValues().length, 1);
|
61
|
+
assertEquals(dest.get(1).getName(), "test");
|
62
|
+
assertEquals(dest.get(1).getValues()[0], "b");
|
63
|
+
|
64
|
+
assertEquals(dest.get(2).getValues().length, 1);
|
65
|
+
assertEquals(dest.get(2).getName(), "test");
|
66
|
+
assertEquals(dest.get(2).getValues()[0], "c");
|
67
|
+
}
|
68
|
+
|
69
|
+
@Test(expected = IllegalArgumentException.class)
|
70
|
+
public void testExpandRaisesExceptionWhenBothValuesAreNull() throws Exception {
|
71
|
+
Optional<List<String>> nullValues = Optional.absent();
|
72
|
+
Optional<String> nullValue = Optional.absent();
|
73
|
+
QueryConfig config = new QueryConfig("test", nullValue, nullValues, false);
|
74
|
+
config.expand();
|
75
|
+
}
|
76
|
+
|
77
|
+
@Test
|
78
|
+
public void testUnExpandBrace() throws Exception {
|
79
|
+
Optional<List<String>> nullValues = Optional.absent();
|
80
|
+
QueryConfig config = new QueryConfig("test", Optional.of("{awesome1,awesome2,awesome3}"), nullValues, false);
|
81
|
+
List<QueryConfig.Query> dest = config.expand();
|
82
|
+
assertEquals(dest.size(), 1);
|
83
|
+
assertEquals(dest.get(0).getName(), "test");
|
84
|
+
assertEquals(dest.get(0).getValues().length, 1);
|
85
|
+
assertEquals(dest.get(0).getValues()[0], "{awesome1,awesome2,awesome3}");
|
86
|
+
}
|
87
|
+
|
88
|
+
@Test
|
89
|
+
public void testExpandBrace() throws Exception {
|
90
|
+
Optional<List<String>> nullValues = Optional.absent();
|
91
|
+
QueryConfig config = new QueryConfig("test", Optional.of("{awesome1,awesome2,awesome3}"), nullValues, true);
|
92
|
+
List<QueryConfig.Query> dest = config.expand();
|
93
|
+
assertEquals(dest.size(), 3);
|
94
|
+
assertEquals(dest.get(0).getName(), "test");
|
95
|
+
assertEquals(dest.get(0).getValues().length, 1);
|
96
|
+
assertEquals(dest.get(0).getValues()[0], "awesome1");
|
97
|
+
assertEquals(dest.get(1).getName(), "test");
|
98
|
+
|
99
|
+
assertEquals(dest.get(1).getValues().length, 1);
|
100
|
+
assertEquals(dest.get(1).getValues()[0], "awesome2");
|
101
|
+
|
102
|
+
assertEquals(dest.get(2).getValues().length, 1);
|
103
|
+
assertEquals(dest.get(2).getName(), "test");
|
104
|
+
assertEquals(dest.get(2).getValues()[0], "awesome3");
|
105
|
+
}
|
106
|
+
|
107
|
+
@Test
|
108
|
+
public void testExpandEscapedBrace() throws Exception {
|
109
|
+
Optional<List<String>> nullValues = Optional.absent();
|
110
|
+
QueryConfig config = new QueryConfig("test", Optional.of("{awe\\,some1,awes\\{ome2,awes\\}ome3}"), nullValues, true);
|
111
|
+
List<QueryConfig.Query> dest = config.expand();
|
112
|
+
assertEquals(dest.get(0).getName(), "test");
|
113
|
+
assertEquals(dest.get(0).getValues().length, 1);
|
114
|
+
assertEquals(dest.get(0).getValues()[0], "awe,some1");
|
115
|
+
|
116
|
+
assertEquals(dest.get(1).getName(), "test");
|
117
|
+
assertEquals(dest.get(1).getValues().length, 1);
|
118
|
+
assertEquals(dest.get(1).getValues()[0], "awes{ome2");
|
119
|
+
|
120
|
+
assertEquals(dest.get(2).getName(), "test");
|
121
|
+
assertEquals(dest.get(2).getValues().length, 1);
|
122
|
+
assertEquals(dest.get(2).getValues()[0], "awes}ome3");
|
123
|
+
}
|
124
|
+
|
125
|
+
}
|
metadata
CHANGED
@@ -1,43 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: embulk-input-http
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Takuma kanari
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-07-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name: bundler
|
15
|
-
version_requirements: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - ~>
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '1.0'
|
20
14
|
requirement: !ruby/object:Gem::Requirement
|
21
15
|
requirements:
|
22
16
|
- - ~>
|
23
17
|
- !ruby/object:Gem::Version
|
24
18
|
version: '1.0'
|
19
|
+
name: bundler
|
25
20
|
prerelease: false
|
26
21
|
type: :development
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: rake
|
29
22
|
version_requirements: !ruby/object:Gem::Requirement
|
30
23
|
requirements:
|
31
|
-
- -
|
24
|
+
- - ~>
|
32
25
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
26
|
+
version: '1.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
34
28
|
requirement: !ruby/object:Gem::Requirement
|
35
29
|
requirements:
|
36
30
|
- - '>='
|
37
31
|
- !ruby/object:Gem::Version
|
38
32
|
version: '10.0'
|
33
|
+
name: rake
|
39
34
|
prerelease: false
|
40
35
|
type: :development
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
41
|
description: Fetch data via http
|
42
42
|
email:
|
43
43
|
- chemtrails.t@gmail.com
|
@@ -55,16 +55,19 @@ files:
|
|
55
55
|
- gradlew
|
56
56
|
- gradlew.bat
|
57
57
|
- lib/embulk/input/http.rb
|
58
|
+
- src/main/java/org/embulk/input/BasicAuthConfig.java
|
58
59
|
- src/main/java/org/embulk/input/HttpInputPlugin.java
|
59
60
|
- src/main/java/org/embulk/input/ParamsConfig.java
|
60
61
|
- src/main/java/org/embulk/input/QueryConfig.java
|
61
62
|
- src/main/java/org/embulk/input/RetryHandler.java
|
62
63
|
- src/test/java/org/embulk/input/TestHttpInputPlugin.java
|
63
|
-
-
|
64
|
+
- src/test/java/org/embulk/input/TestParamsConfig.java
|
65
|
+
- src/test/java/org/embulk/input/TestQueryConfig.java
|
64
66
|
- classpath/httpclient-4.4.jar
|
65
67
|
- classpath/commons-logging-1.2.jar
|
66
68
|
- classpath/httpcore-4.4.jar
|
67
69
|
- classpath/commons-codec-1.9.jar
|
70
|
+
- classpath/embulk-input-http-0.0.6.jar
|
68
71
|
homepage: https://github.com/takumakanari/embulk-input-http
|
69
72
|
licenses:
|
70
73
|
- MIT
|