Skip to content
This repository was archived by the owner on Feb 25, 2020. It is now read-only.

Commit de7530a

Browse files
committed
add beta to the available services
1 parent 72b152f commit de7530a

4 files changed

Lines changed: 48 additions & 33 deletions

File tree

precog/java/src/main/java/com/precog/api/Client.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ private static class Services {
4141
* virtual filesystem path to be used
4242
*/
4343
public Client(String apiKey) {
44-
this.service = Service.ProductionHttp;
44+
this.service = Service.ProductionHttps;
4545
this.apiKey = apiKey;
4646
this.rest = new Rest(service, apiKey);
4747
}

precog/java/src/main/java/com/precog/api/Service.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ public interface Service {
1515

1616
/**
1717
* The default production http service.
18+
* Deprecated, use https
1819
*/
20+
@Deprecated
1921
public static final Service ProductionHttp = new Service() {
2022
@Override public URL serviceUrl() {
2123
try {
@@ -31,15 +33,11 @@ public interface Service {
3133
/**
3234
* The default production https service.
3335
*/
34-
public static final Service ProductionHttps = new Service() {
35-
@Override public URL serviceUrl() {
36-
try {
37-
return new URL("https", "api.precog.com", 443, "/v1/");
38-
} catch (MalformedURLException ex) {
39-
Logger.getLogger(Service.class.getName()).log(Level.SEVERE, "Invalid client URL", ex);
40-
}
36+
public static final Service ProductionHttps = ServiceBuilder.service("api.precog.com");
37+
38+
/**
39+
* The default production https service.
40+
*/
41+
public static final Service BetaPrecogHttps = ServiceBuilder.service("beta.precog.com");
4142

42-
return null;
43-
}
44-
};
4543
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.precog.api;
2+
3+
import java.net.MalformedURLException;
4+
import java.net.URL;
5+
import java.util.logging.Level;
6+
import java.util.logging.Logger;
7+
8+
/**
9+
* User: gabriel
10+
* Date: 12/10/12
11+
*/
12+
public class ServiceBuilder {
13+
public static Service service(String url){
14+
final String fUrl=url;
15+
return new Service() {
16+
@Override public URL serviceUrl() {
17+
try {
18+
return new URL("https", fUrl, 443, "/v1/");
19+
} catch (MalformedURLException ex) {
20+
Logger.getLogger(Service.class.getName()).log(Level.SEVERE, "Invalid client URL", ex);
21+
}
22+
23+
return null;
24+
}
25+
};
26+
}
27+
}

precog/java/src/test/java/com/precog/api/ClientTest.java

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -47,21 +47,11 @@ public TestData(int testInt, String testStr, RawJson testRaw) {
4747
}
4848
}
4949

50-
public static final Service Local = new Service() {
51-
public URL serviceUrl() {
52-
try {
53-
return new URL("http", "beta.precog.com", 80, "/v1/");
54-
} catch (MalformedURLException ex) {
55-
throw new RuntimeException("Invalid client URL", ex);
56-
}
57-
}
58-
};
59-
6050
@BeforeClass
6151
public static void beforeAll() throws Exception {
6252
testId = "" + Double.valueOf(java.lang.Math.random() * 10000).intValue();
6353

64-
Client testClient = new Client(Local, null);
54+
Client testClient = new Client(Service.BetaPrecogHttps, null);
6555
String result = testClient.createAccount("java-test@precog.com", "password");
6656
AccountInfo res = GsonFromJson.of(new TypeToken<AccountInfo>() {
6757
}).deserialize(result);
@@ -77,7 +67,7 @@ public static void beforeAll() throws Exception {
7767
@Test
7868
public void testStore() throws IOException {
7969
ToJson<Object> toJson = new GsonToJson();
80-
Client testClient = new Client(Local, testApiKey);
70+
Client testClient = new Client(Service.BetaPrecogHttps, testApiKey);
8171

8272
RawJson testJson = new RawJson("{\"test\":[{\"v\": 1}, {\"v\": 2}]}");
8373
TestData testData = new TestData(42, "Hello\" World", testJson);
@@ -89,23 +79,23 @@ public void testStore() throws IOException {
8979
@Test
9080
public void testStoreStrToJson() throws IOException {
9181
ToJson<String> toJson = new RawStringToJson();
92-
Client testClient = new Client(Local, testApiKey);
82+
Client testClient = new Client(Service.BetaPrecogHttps, testApiKey);
9383

9484
Record<String> testRecord = new Record<String>("{\"test\":[{\"v\": 1}, {\"v\": 2}]}");
9585
testClient.store(testPath, testRecord, toJson);
9686
}
9787

9888
@Test
9989
public void testStoreRawString() throws IOException {
100-
Client testClient = new Client(Local, testApiKey);
90+
Client testClient = new Client(Service.BetaPrecogHttps, testApiKey);
10191

10292
String rawJson = "{\"test\":[{\"v\": 1}, {\"v\": 2}]}";
10393
testClient.store(testPath, rawJson);
10494
}
10595

10696
@Test
10797
public void testStoreRawUTF8() throws IOException {
108-
Client testClient = new Client(Local, testApiKey);
98+
Client testClient = new Client(Service.BetaPrecogHttps, testApiKey);
10999
String rawJson = "{\"test\":[{\"ดีลลิเชียส\": 1}, {\"v\": 2}]}";
110100
testClient.store(testPath, rawJson);
111101
}
@@ -117,7 +107,7 @@ public static Map<String, String> jsonToStrMap(String json) {
117107

118108
@Test
119109
public void testIngestCSV() throws IOException {
120-
Client testClient = new Client(Local, testApiKey);
110+
Client testClient = new Client(Service.BetaPrecogHttps, testApiKey);
121111
IngestOptions options = new CSVIngestOptions();
122112
String response = testClient.ingest(testPath, "blah,\n\n", options);
123113
IngestResult result = GsonFromJson.of(new TypeToken<IngestResult>() {
@@ -127,7 +117,7 @@ public void testIngestCSV() throws IOException {
127117

128118
@Test
129119
public void testIngestJSON() throws IOException {
130-
Client testClient = new Client(Local, testApiKey);
120+
Client testClient = new Client(Service.BetaPrecogHttps, testApiKey);
131121
IngestOptions options = new IngestOptions(ContentType.JSON);
132122
String rawJson = "{\"test\":[{\"v\": 1}, {\"v\": 2}]}";
133123
String response = testClient.ingest(testPath, rawJson, options);
@@ -138,7 +128,7 @@ public void testIngestJSON() throws IOException {
138128

139129
@Test
140130
public void testIngestCsvWithOptions() throws IOException {
141-
Client testClient = new Client(Local, testApiKey);
131+
Client testClient = new Client(Service.BetaPrecogHttps, testApiKey);
142132
CSVIngestOptions options = new CSVIngestOptions();
143133
options.setDelimiter(",");
144134
options.setQuote("'");
@@ -151,7 +141,7 @@ public void testIngestCsvWithOptions() throws IOException {
151141

152142
@Test
153143
public void testIngestAsync() throws IOException {
154-
Client testClient = new Client(Local, testApiKey);
144+
Client testClient = new Client(Service.BetaPrecogHttps, testApiKey);
155145
IngestOptions options = new CSVIngestOptions();
156146
options.setAsync(true);
157147
String response = testClient.ingest(testPath, "blah,\n\n", options);
@@ -200,7 +190,7 @@ public void testOddCharacters() throws IOException {
200190

201191
@Test
202192
public void testCreateAccount() throws IOException {
203-
Client testClient = new Client(Local, null);
193+
Client testClient = new Client(Service.BetaPrecogHttps, null);
204194
String result = testClient.createAccount("java-test@precog.com", "password");
205195
assertNotNull(result);
206196
AccountInfo res = GsonFromJson.of(new TypeToken<AccountInfo>() {
@@ -213,7 +203,7 @@ public void testCreateAccount() throws IOException {
213203

214204
@Test
215205
public void testDescribeAccount() throws IOException {
216-
Client testClient = new Client(Local, null);
206+
Client testClient = new Client(Service.BetaPrecogHttps, null);
217207
String result = testClient.describeAccount("java-test@precog.com", "password", testAccountId);
218208
assertNotNull(result);
219209
AccountInfo res = GsonFromJson.of(new TypeToken<AccountInfo>() {
@@ -224,7 +214,7 @@ public void testDescribeAccount() throws IOException {
224214
@Test
225215
public void testQuery() throws IOException {
226216
//just test the query was sent and executed successfully
227-
Client testClient = new Client(Local, testApiKey);
217+
Client testClient = new Client(Service.BetaPrecogHttps, testApiKey);
228218
String result = testClient.query(new Path(testAccountId), "count(//" + testAccountId + ")");
229219
assertNotNull(result);
230220
String[] res = GsonFromJson.of(String[].class).deserialize(result);

0 commit comments

Comments
 (0)