diff --git a/README.md b/README.md
index 9cef60f..79cbf36 100644
--- a/README.md
+++ b/README.md
@@ -11,17 +11,17 @@ See https://www.semantics3.com for more information.
com.semantics3
Sem3Java
- 1.2.2
+ 1.2.4
```
-* For projects which don't use Maven each stable [release](https://github.com/Semantics3/semantics3-java/releases/download/Sem3Java-1.2.1/Sem3Java-1.2.1-jar-with-dependencies.jar) is also available as a fat jar.
+* For projects which don't use Maven each stable [release](https://github.com/Semantics3/semantics3-java/releases/download/Sem3Java-1.2.4/Sem3Java-1.2.4-jar-with-dependencies.jar) is also available as a fat jar.
## Getting Started
In order to use the client, you must have both an API key and an API secret. To obtain your key and secret, you need to first create an account at
https://www.semantics3.com/
-You can access your API access credentials from the user dashboard at https://www.semantics3.com/dashboard/applications
+You can access your API access credentials from the user dashboard at https://dashboard.semantics3.com.
### Setup Work
diff --git a/pom.xml b/pom.xml
index 3b98c0c..cea89bf 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,7 +4,7 @@
com.semantics3
Sem3Java
- 1.2.2
+ 1.2.5-SNAPSHOT
Semantics3 Java Library
https://github.com/Semantics3/semantics3-java
Java bindings for Semantics3 API
@@ -147,7 +147,7 @@
scm:git:git://github.com/Semantics3/semantics3-java.git
scm:git:git@github.com:Semantics3/semantics3-java.git
https://github.com/Semantics3/semantics3-java
- Sem3Java-1.2.2
+ HEAD
diff --git a/src/main/java/com/semantics3/api/Categories.java b/src/main/java/com/semantics3/api/Categories.java
index 22ad6aa..3c35149 100644
--- a/src/main/java/com/semantics3/api/Categories.java
+++ b/src/main/java/com/semantics3/api/Categories.java
@@ -1,13 +1,13 @@
package com.semantics3.api;
-import java.io.IOException;
-
import oauth.signpost.exception.OAuthCommunicationException;
import oauth.signpost.exception.OAuthExpectationFailedException;
import oauth.signpost.exception.OAuthMessageSignerException;
-
import org.json.JSONObject;
+import java.io.IOException;
+import java.net.URISyntaxException;
+
public class Categories extends Semantics3Request {
public Categories(String apiKey, String apiSecret) {
@@ -19,7 +19,7 @@ public Categories field(Object... fields) {
return this;
}
- public JSONObject getCategories() throws OAuthMessageSignerException, OAuthExpectationFailedException, OAuthCommunicationException, IOException {
+ public JSONObject getCategories() throws OAuthMessageSignerException, OAuthExpectationFailedException, OAuthCommunicationException, IOException, URISyntaxException {
return this.get();
}
diff --git a/src/main/java/com/semantics3/api/Offers.java b/src/main/java/com/semantics3/api/Offers.java
index f592351..ba22a5d 100644
--- a/src/main/java/com/semantics3/api/Offers.java
+++ b/src/main/java/com/semantics3/api/Offers.java
@@ -1,13 +1,13 @@
package com.semantics3.api;
-import java.io.IOException;
-
import oauth.signpost.exception.OAuthCommunicationException;
import oauth.signpost.exception.OAuthExpectationFailedException;
import oauth.signpost.exception.OAuthMessageSignerException;
-
import org.json.JSONObject;
+import java.io.IOException;
+import java.net.URISyntaxException;
+
public class Offers extends Semantics3Request {
public Offers(String apiKey, String apiSecret) {
@@ -19,7 +19,7 @@ public Offers field(Object... fields) {
return this;
}
- public JSONObject getOffers() throws OAuthMessageSignerException, OAuthExpectationFailedException, OAuthCommunicationException, IOException {
+ public JSONObject getOffers() throws OAuthMessageSignerException, OAuthExpectationFailedException, OAuthCommunicationException, IOException, URISyntaxException {
return this.get();
}
diff --git a/src/main/java/com/semantics3/api/Products.java b/src/main/java/com/semantics3/api/Products.java
index a52199e..711c834 100644
--- a/src/main/java/com/semantics3/api/Products.java
+++ b/src/main/java/com/semantics3/api/Products.java
@@ -1,14 +1,13 @@
package com.semantics3.api;
-import java.io.IOException;
-
+import com.semantics3.Util;
import oauth.signpost.exception.OAuthCommunicationException;
import oauth.signpost.exception.OAuthExpectationFailedException;
import oauth.signpost.exception.OAuthMessageSignerException;
-
import org.json.JSONObject;
-import com.semantics3.Util;
+import java.io.IOException;
+import java.net.URISyntaxException;
public class Products extends Semantics3Request {
@@ -17,13 +16,13 @@ public Products(String apiKey, String apiSecret) {
// TODO Auto-generated constructor stub
}
- public JSONObject getProducts() throws OAuthMessageSignerException, OAuthExpectationFailedException, OAuthCommunicationException, IOException {
+ public JSONObject getProducts() throws OAuthMessageSignerException, OAuthExpectationFailedException, OAuthCommunicationException, IOException, URISyntaxException {
return this.get();
}
- public JSONObject getOffers() throws OAuthMessageSignerException, OAuthExpectationFailedException, OAuthCommunicationException, IOException {
+ public JSONObject getOffers() throws OAuthMessageSignerException, OAuthExpectationFailedException, OAuthCommunicationException, IOException, URISyntaxException {
return this.get("offers");
}
- public JSONObject getCategories() throws OAuthMessageSignerException, OAuthExpectationFailedException, OAuthCommunicationException, IOException {
+ public JSONObject getCategories() throws OAuthMessageSignerException, OAuthExpectationFailedException, OAuthCommunicationException, IOException, URISyntaxException {
return this.get("categories");
}
diff --git a/src/main/java/com/semantics3/api/Semantics3Request.java b/src/main/java/com/semantics3/api/Semantics3Request.java
index afe0031..f3c3b87 100644
--- a/src/main/java/com/semantics3/api/Semantics3Request.java
+++ b/src/main/java/com/semantics3/api/Semantics3Request.java
@@ -13,6 +13,7 @@
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
+import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLEncoder;
import java.util.HashMap;
@@ -72,10 +73,10 @@ public Semantics3Request(String apiKey, String apiSecret) {
}
protected JSONObject fetch(String endpoint, String params) throws
- OAuthMessageSignerException,
- OAuthExpectationFailedException,
- OAuthCommunicationException,
- IOException {
+ OAuthMessageSignerException,
+ OAuthExpectationFailedException,
+ OAuthCommunicationException,
+ IOException, URISyntaxException {
String req = new StringBuffer()
.append(API_BASE)
.append(endpoint)
@@ -83,7 +84,7 @@ protected JSONObject fetch(String endpoint, String params) throws
.append(URLEncoder.encode(params, "UTF-8"))
.toString();
URL url = new URL(req);
-
+ url = url.toURI().normalize().toURL();
HttpURLConnection request = (HttpURLConnection) url.openConnection();
request.setRequestProperty("User-Agent", "Semantics3 Java Library");
consumer.sign(request);
@@ -98,7 +99,13 @@ protected JSONObject fetch(String endpoint, String params) throws
catch (IOException e) {
InputStream error = ((HttpURLConnection) request).getErrorStream();
JSONObject json = new JSONObject(new JSONTokener(error));
- json.put("code", "Error");
+ if (!json.has("code")) {
+ json.put("code", "Error");
+ }
+ else {
+ Object value = json.get("code");
+ json.put("code", value.toString());
+ }
return json;
}
}
@@ -107,13 +114,13 @@ protected JSONObject fetch(String endpoint, String method, HashMap 0, is(true));
- }
-
- @Test
- public void TestSKUQuery() throws OAuthExpectationFailedException, OAuthCommunicationException, OAuthMessageSignerException, IOException {
+ .categoriesField("cat_id", 4992); JSONObject results = products.getCategories(); JSONArray resultsArray = (JSONArray) results.get("results"); assertThat(resultsArray.length() > 0, is(true)); } @Test
+ public void TestSKUQuery() throws OAuthExpectationFailedException, OAuthCommunicationException, OAuthMessageSignerException, IOException, URISyntaxException {
Properties property = TestUtils.getConfig("api.config");
- Semantics3Request semantics3Request = new Semantics3Request(property.get("SKU_API_KEY").toString(), property.get("SKU_API_SECRET").toString());
+ Semantics3Request semantics3Request = new Semantics3Request(property.get("API_KEY").toString(), property.get("API_SECRET").toString());
HashMap params = new HashMap();
params.put("site", "abercrombie.com");
JSONObject jsonObject = semantics3Request.runQuery("skus", "GET", params);
JSONArray resultsArray = (JSONArray) jsonObject.get("results");
assertThat(resultsArray.length() > 0, is(true));
}
+
+ @Test(expected = Semantics3Exception.class)
+ public void TestSiteQuery() throws IOException, OAuthExpectationFailedException, OAuthCommunicationException, OAuthMessageSignerException, URISyntaxException {
+ Properties property = TestUtils.getConfig("api.config");
+ Products products = new Products(property.get("API_KEY").toString(), property.get("API_SECRET").toString());
+ products .productsField("url", "zsdfseobn.com/sdgeafg");
+ JSONObject results = products.getProducts();
+ }
+
+ @Ignore
+ public void TestPagination() throws IOException, OAuthCommunicationException, OAuthExpectationFailedException, OAuthMessageSignerException, URISyntaxException {
+ Properties property = TestUtils.getConfig("api.config");
+ Semantics3Request semantics3Request = new Semantics3Request(property.get("API_KEY").toString(), property.get("API_SECRET").toString());
+ HashMap params = new HashMap();
+ params.put("site", "macys.com");
+ JSONObject jsonObject = semantics3Request.runQuery("skus", "GET", params);
+ while(jsonObject.has("next")){
+ JSONObject next = (JSONObject)jsonObject.get("next");
+ String page = next.getString("page");
+ System.out.println(page);
+ params.remove("site");
+ params.put("page", page);
+ jsonObject = semantics3Request.runQuery("skus", "GET", params);
+ System.out.println(jsonObject.toString());
+ }
+ }
}
diff --git a/src/test/java/com/semantics3/api/Semantics3RequestTest.java b/src/test/java/com/semantics3/api/Semantics3RequestTest.java
index a08cdeb..135dc1f 100644
--- a/src/test/java/com/semantics3/api/Semantics3RequestTest.java
+++ b/src/test/java/com/semantics3/api/Semantics3RequestTest.java
@@ -9,10 +9,10 @@
import org.junit.Test;
import java.io.IOException;
+import java.net.URISyntaxException;
import java.util.HashMap;
import java.util.Properties;
-import static junit.framework.Assert.assertTrue;
import static org.hamcrest.CoreMatchers.anything;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.MatcherAssert.assertThat;
@@ -22,7 +22,7 @@
*/
public class Semantics3RequestTest {
@Test
- public void testRunQueryPost() throws IOException, OAuthCommunicationException, OAuthExpectationFailedException, OAuthMessageSignerException {
+ public void testRunQueryPost() throws IOException, OAuthCommunicationException, OAuthExpectationFailedException, OAuthMessageSignerException, URISyntaxException {
Properties property = TestUtils.getConfig("api.config");
Semantics3Request sem3 = new Semantics3Request(property.get("API_KEY").toString(), property.get("API_SECRET").toString());
HashMap params = new HashMap();
@@ -37,17 +37,17 @@ public void testRunQueryPost() throws IOException, OAuthCommunicationException,
}
@Test
- public void testRunQueryGet() throws IOException, OAuthCommunicationException, OAuthExpectationFailedException, OAuthMessageSignerException {
+ public void testRunQueryGet() throws IOException, OAuthCommunicationException, OAuthExpectationFailedException, OAuthMessageSignerException, URISyntaxException {
Properties property = TestUtils.getConfig("api.config");
Semantics3Request sem3 = new Semantics3Request(property.get("API_KEY").toString(), property.get("API_SECRET").toString());
HashMap params = new HashMap();
JSONObject result = sem3.runQuery("webhooks", "GET", params);
- assertTrue(result.getJSONArray("data").length() > 0);
+ assertThat(result.getString("code"), equalTo("OK"));
}
@Test
- public void testRunQueryDelete() throws IOException, OAuthCommunicationException, OAuthExpectationFailedException, OAuthMessageSignerException {
+ public void testRunQueryDelete() throws IOException, OAuthCommunicationException, OAuthExpectationFailedException, OAuthMessageSignerException, URISyntaxException {
Properties property = TestUtils.getConfig("api.config");
Semantics3Request sem3 = new Semantics3Request(property.get("API_KEY").toString(), property.get("API_SECRET").toString());
HashMap params = new HashMap();
@@ -61,4 +61,6 @@ public void testRunQueryDelete() throws IOException, OAuthCommunicationException
assertThat(response.getString("code"), equalTo("OK"));
}
}
+
+
}