diff --git a/CHANGES.md b/CHANGES.md index b34f19a..bc0a89a 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,9 @@ # Release History +## 1.2.0 +* Added Messages API (new) +* Message API (V1) is now fully depricated + ## 1.1.1 * Add optional parameter to support pagination in getTrayByType diff --git a/README.md b/README.md index aa413e6..b11d93a 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ These are the supported API resources: * Job and Freelancer Profile * Search Jobs and Freelancers * Organization -* MC +* Messages * Time and Financial Reporting * Metadata * Snapshot diff --git a/doc/java-upwork-javadoc.zip b/doc/java-upwork-javadoc.zip index 462de80..bf14716 100644 Binary files a/doc/java-upwork-javadoc.zip and b/doc/java-upwork-javadoc.zip differ diff --git a/example-android/app/libs/java-upwork.jar b/example-android/app/libs/java-upwork.jar index 576651c..1780f21 100644 Binary files a/example-android/app/libs/java-upwork.jar and b/example-android/app/libs/java-upwork.jar differ diff --git a/example/src/TestApi.java b/example/src/TestApi.java index 64fc898..8eb58dd 100644 --- a/example/src/TestApi.java +++ b/example/src/TestApi.java @@ -1,6 +1,5 @@ import com.Upwork.api.*; import com.Upwork.api.Routers.Organization.Users; -import com.Upwork.api.Routers.Mc; import com.Upwork.api.Routers.Reports.Time; import java.util.HashMap; @@ -82,19 +81,6 @@ public static void main(String[] args) { params2.put("tq", "select task where worked_on >= '2014-06-01' AND worked_on <= '2014-06-03' order by worked_on"); Time report = new Time(client); json2 = report.getByFreelancerLimited(myId, params2); - - // post a new message - /*HashMap params2 = new HashMap(); - params2.put("recipients", "invalid"); - params2.put("body", "body of the message"); - Mc mc = new Mc(client); - json2 = mc.startNewThread(myId, params2);*/ - - // mark thread as read - HashMap params3 = new HashMap(); - params3.put("read", "true"); - Mc mc = new Mc(client); - json3 = mc.markThread(myId, "8888888", params3); } catch (JSONException e) { e.printStackTrace(); @@ -102,6 +88,5 @@ public static void main(String[] args) { System.out.println(json1); System.out.println(json2); - System.out.println(json3); } } diff --git a/lib/java-upwork.jar b/lib/java-upwork.jar index 576651c..1780f21 100644 Binary files a/lib/java-upwork.jar and b/lib/java-upwork.jar differ diff --git a/pom.xml b/pom.xml index efc4e6d..dd9f715 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.Upwork api - 1.1.0 + 1.2.0 jar java-upwork JAVA bindings for Upwork API diff --git a/src/com/Upwork/api/Routers/Mc.java b/src/com/Upwork/api/Routers/Mc.java deleted file mode 100644 index 6bf6577..0000000 --- a/src/com/Upwork/api/Routers/Mc.java +++ /dev/null @@ -1,169 +0,0 @@ -package com.Upwork.api.Routers; - -import java.util.HashMap; - -import com.Upwork.ClassPreamble; -import com.Upwork.api.OAuthClient; - -import org.json.JSONException; -import org.json.JSONObject; - -@ClassPreamble ( - author = "Maksym Novozhylov ", - date = "6/3/2014", - currentRevision = 1, - lastModified = "6/3/2014", - lastModifiedBy = "Maksym Novozhylov", - reviewers = {"Yiota Tsakiri"} - ) -public final class Mc { - - final static String ENTRY_POINT = "api"; - - private OAuthClient oClient = null; - - public Mc(OAuthClient client) { - oClient = client; - oClient.setEntryPoint(ENTRY_POINT); - } - - /** - * Get trays - * - * @throws JSONException If error occurred - * @return {@link JSONObject} - */ - public JSONObject getTrays() throws JSONException { - return oClient.get("/mc/v1/trays"); - } - - /** - * Get tray by type - * - * @param username Username - * @param type Tray type/name - * @throws JSONException If error occurred - * @return {@link JSONObject} - */ - public JSONObject getTrayByType(String username, String type) throws JSONException { - return oClient.get("/mc/v1/trays/" + username + "/" + type); - } - - /** - * Get tray by type - * - * @param username Username - * @param type Tray type/name - * @param params Parameters - * @throws JSONException If error occurred - * @return {@link JSONObject} - */ - public JSONObject getTrayByType(String username, String type, HashMap params) throws JSONException { - return oClient.get("/mc/v1/trays/" + username + "/" + type, params); - } - - /** - * List thread details based on thread id - * - * @param username Username - * @param threadId Thread ID - * @throws JSONException If error occurred - * @return {@link JSONObject} - */ - public JSONObject getThreadDetails(String username, String threadId) throws JSONException { - return oClient.get("/mc/v1/threads/" + username + "/" + threadId); - } - - /** - * Get a specific thread by "Interview" context - * - * @param username Username - * @param jobKey Job key - * @param applicationId Application ID - * @throws JSONException If error occurred - * @return {@link JSONObject} - */ - public JSONObject getThreadByContext(String username, String jobKey, String applicationId) throws JSONException { - return oClient.get("/mc/v1/contexts/" + username + "/Interviews:" + jobKey + ":" + applicationId); - } - - /** - * Get a specific thread by context - * - * @param username Username - * @param jobKey Job key - * @param applicationId Application ID - * @param context Context - * @throws JSONException If error occurred - * @return {@link JSONObject} - */ - public JSONObject getThreadByContext(String username, String jobKey, String applicationId, String context) throws JSONException { - return oClient.get("/mc/v1/contexts/" + username + "/" + context + ":" + jobKey + ":" + applicationId); - } - - /** - * Get a specific thread by context (last message content) - * - * @param username Username - * @param jobKey Job key - * @param applicationId Application ID - * @throws JSONException If error occurred - * @return {@link JSONObject} - */ - public JSONObject getThreadByContextLastPosts(String username, String jobKey, String applicationId) throws JSONException { - return oClient.get("/mc/v1/contexts/" + username + "/Interviews:" + jobKey + ":" + applicationId + "/last_posts"); - } - - /** - * Get a specific thread by context (last message content) - * - * @param username Username - * @param jobKey Job key - * @param applicationId Application ID - * @param context Context - * @throws JSONException If error occurred - * @return {@link JSONObject} - */ - public JSONObject getThreadByContextLastPosts(String username, String jobKey, String applicationId, String context) throws JSONException { - return oClient.get("/mc/v1/contexts/" + username + "/" + context + ":" + jobKey + ":" + applicationId + "/last_posts"); - } - - /** - * Send new message - * - * @param username User ID - * @param params Parameters - * @throws JSONException If error occurred - * @return {@link JSONObject} - */ - public JSONObject startNewThread(String username, HashMap params) throws JSONException { - return oClient.post("/mc/v1/threads/" + username, params); - } - - /** - * Reply to existent thread - * - * @param username User ID - * @param threadId Thread ID - * @param params Parameters - * @throws JSONException If error occurred - * @return {@link JSONObject} - */ - public JSONObject replyToThread(String username, String threadId, HashMap params) throws JSONException { - return oClient.post("/mc/v1/threads/" + username + "/" + threadId, params); - } - - /** - * Update threads based on user actions - * - * @param username Username - * @param threadId Thread ID - * @param params Parameters - * @throws JSONException If error occurred - * @return {@link JSONObject} - */ - public JSONObject markThread(String username, String threadId, HashMap params) throws JSONException { - return oClient.put("/mc/v1/threads/" + username + "/" + threadId, params); - } - -} diff --git a/src/com/Upwork/api/Routers/Messages.java b/src/com/Upwork/api/Routers/Messages.java new file mode 100644 index 0000000..07e9785 --- /dev/null +++ b/src/com/Upwork/api/Routers/Messages.java @@ -0,0 +1,157 @@ +package com.Upwork.api.Routers; + +import java.util.HashMap; + +import com.Upwork.ClassPreamble; +import com.Upwork.api.OAuthClient; + +import org.json.JSONException; +import org.json.JSONObject; + +@ClassPreamble ( + author = "Maksym Novozhylov ", + date = "6/6/2014", + currentRevision = 1, + lastModified = "6/6/2014", + lastModifiedBy = "Maksym Novozhylov", + reviewers = {"Yiota Tsakiri"} + ) +public final class Messages { + + final static String ENTRY_POINT = "api"; + + private OAuthClient oClient = null; + + public Messages(OAuthClient client) { + oClient = client; + oClient.setEntryPoint(ENTRY_POINT); + } + + /** + * Retrieve rooms information + * + * @param company Company ID + * @throws JSONException If error occurred + * @return {@link JSONObject} + */ + public JSONObject getRooms(String company) throws JSONException { + return oClient.get("/messages/v3/" + company + "/rooms"); + } + + /** + * Retrieve rooms information with params + * + * @param company Company ID + * @param params Parameters + * @throws JSONException If error occurred + * @return {@link JSONObject} + */ + public JSONObject getRooms(String company, HashMap params) throws JSONException { + return oClient.get("/messages/v3/" + company + "/rooms", params); + } + + /** + * Get a specific room information + * + * @param company Company ID + * @param roomId Room ID + * @param params Parameters + * @throws JSONException If error occurred + * @return {@link JSONObject} + */ + public JSONObject getRoomDetails(String company, String roomId, HashMap params) throws JSONException { + return oClient.get("/messages/v3/" + company + "/rooms/" + roomId, params); + } + + /** + * Get a specific room by offer ID + * + * @param company Company ID + * @param offerId Offer ID + * @param params Parameters + * @throws JSONException If error occurred + * @return {@link JSONObject} + */ + public JSONObject getRoomByOffer(String company, String offerId, HashMap params) throws JSONException { + return oClient.get("/messages/v3/" + company + "/rooms/offers/" + offerId, params); + } + + /** + * Get a specific room by application ID + * + * @param company Company ID + * @param applicationId Application ID + * @param params Parameters + * @throws JSONException If error occurred + * @return {@link JSONObject} + */ + public JSONObject getRoomByApplication(String company, String applicationId, HashMap params) throws JSONException { + return oClient.get("/messages/v3/" + company + "/rooms/appications/" + applicationId, params); + } + + /** + * Get a specific room by contract ID + * + * @param company Company ID + * @param contractId Contract ID + * @param params Parameters + * @throws JSONException If error occurred + * @return {@link JSONObject} + */ + public JSONObject getRoomByContract(String company, String contractId, HashMap params) throws JSONException { + return oClient.get("/messages/v3/" + company + "/rooms/contracts/" + contractId, params); + } + + /** + * Create a new room + * + * @param company Company ID + * @param params Parameters + * @throws JSONException If error occurred + * @return {@link JSONObject} + */ + public JSONObject createRoom(String company, HashMap params) throws JSONException { + return oClient.post("/messages/v3/" + company + "/rooms", params); + } + + /** + * Send a message to a room + * + * @param company Company ID + * @param roomId Room ID + * @param params Parameters + * @throws JSONException If error occurred + * @return {@link JSONObject} + */ + public JSONObject sendMessageToRoom(String company, String roomId, HashMap params) throws JSONException { + return oClient.post("/messages/v3/" + company + "/rooms/" + roomId + "/stories", params); + } + + /** + * Update a room settings + * + * @param company Company ID + * @param roomId Room ID + * @param username User ID + * @param params Parameters + * @throws JSONException If error occurred + * @return {@link JSONObject} + */ + public JSONObject updateRoomSettings(String company, String roomId, String username, HashMap params) throws JSONException { + return oClient.get("/messages/v3/" + company + "/rooms/" + roomId + "/users/" + username, params); + } + + /** + * Update the metadata of a room + * + * @param company Company ID + * @param roomId Room ID + * @param params Parameters + * @throws JSONException If error occurred + * @return {@link JSONObject} + */ + public JSONObject updateRoomMetadata(String company, String roomId, HashMap params) throws JSONException { + return oClient.get("/messages/v3/" + company + "/rooms/" + roomId, params); + } + +} diff --git a/test/com/Upwork/api/Routers/McTest.java b/test/com/Upwork/api/Routers/McTest.java deleted file mode 100644 index 38ed869..0000000 --- a/test/com/Upwork/api/Routers/McTest.java +++ /dev/null @@ -1,82 +0,0 @@ -package com.Upwork.api.Routers; - -import static org.junit.Assert.*; - -import java.util.HashMap; - -import org.json.JSONObject; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; - -import com.Upwork.api.Routers.Helper; -import com.Upwork.api.Routers.Mc; - -@RunWith(PowerMockRunner.class) -@PrepareForTest({ - Mc.class -}) -public class McTest extends Helper { - @Test public void getTrays() throws Exception { - Mc mc = new Mc(client); - JSONObject json = mc.getTrays(); - - assertTrue(json instanceof JSONObject); - } - - @Test public void getTrayByType() throws Exception { - Mc mc = new Mc(client); - JSONObject json1 = mc.getTrayByType("username", "inbox"); - JSONObject json2 = mc.getTrayByType("username", "inbox", new HashMap()); - - assertTrue(json1 instanceof JSONObject); - assertTrue(json2 instanceof JSONObject); - } - - @Test public void getThreadDetails() throws Exception { - Mc mc = new Mc(client); - JSONObject json = mc.getThreadDetails("username", "1234"); - - assertTrue(json instanceof JSONObject); - } - - @Test public void getThreadByContext() throws Exception { - Mc mc = new Mc(client); - JSONObject json1 = mc.getThreadByContext("username", "~key", "1234"); - JSONObject json2 = mc.getThreadByContext("username", "~key", "1234", "Interviews"); - - assertTrue(json1 instanceof JSONObject); - assertTrue(json2 instanceof JSONObject); - } - - @Test public void getThreadByContextLastPosts() throws Exception { - Mc mc = new Mc(client); - JSONObject json1 = mc.getThreadByContextLastPosts("username", "~key", "1234"); - JSONObject json2 = mc.getThreadByContextLastPosts("username", "~key", "1234", "Interviews"); - - assertTrue(json1 instanceof JSONObject); - assertTrue(json2 instanceof JSONObject); - } - - @Test public void startNewThread() throws Exception { - Mc mc = new Mc(client); - JSONObject json = mc.startNewThread("username", new HashMap()); - - assertTrue(json instanceof JSONObject); - } - - @Test public void replyToThread() throws Exception { - Mc mc = new Mc(client); - JSONObject json = mc.replyToThread("username", "1234", new HashMap()); - - assertTrue(json instanceof JSONObject); - } - - @Test public void markThread() throws Exception { - Mc mc = new Mc(client); - JSONObject json = mc.markThread("username", "1234", new HashMap()); - - assertTrue(json instanceof JSONObject); - } -} diff --git a/test/com/Upwork/api/Routers/MessagesTest.java b/test/com/Upwork/api/Routers/MessagesTest.java new file mode 100644 index 0000000..2faac6c --- /dev/null +++ b/test/com/Upwork/api/Routers/MessagesTest.java @@ -0,0 +1,87 @@ +package com.Upwork.api.Routers; + +import static org.junit.Assert.*; + +import java.util.HashMap; + +import org.json.JSONObject; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +import com.Upwork.api.Routers.Helper; +import com.Upwork.api.Routers.Messages; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({ + Messages.class +}) +public class MessagesTest extends Helper { + @Test public void getRooms() throws Exception { + Messages messages = new Messages(client); + JSONObject json = messages.getRooms("company"); + + assertTrue(json instanceof JSONObject); + + JSONObject json2 = messages.getRooms("company", new HashMap()); + + assertTrue(json2 instanceof JSONObject); + } + + @Test public void getRoomDetails() throws Exception { + Messages messages = new Messages(client); + JSONObject json1 = messages.getRoomDetails("company", "room-id", new HashMap()); + + assertTrue(json1 instanceof JSONObject); + } + + @Test public void getRoomByOffer() throws Exception { + Messages messages = new Messages(client); + JSONObject json = messages.getRoomByOffer("company", "1234", new HashMap()); + + assertTrue(json instanceof JSONObject); + } + + @Test public void getRoomByApplication() throws Exception { + Messages messages = new Messages(client); + JSONObject json = messages.getRoomByApplication("company", "1234", new HashMap()); + + assertTrue(json instanceof JSONObject); + } + + @Test public void getRoomByContract() throws Exception { + Messages messages = new Messages(client); + JSONObject json = messages.getRoomByContract("company", "1234", new HashMap()); + + assertTrue(json instanceof JSONObject); + } + + @Test public void createRoom() throws Exception { + Messages messages = new Messages(client); + JSONObject json = messages.createRoom("company", new HashMap()); + + assertTrue(json instanceof JSONObject); + } + + @Test public void sendMessageToRoom() throws Exception { + Messages messages = new Messages(client); + JSONObject json = messages.sendMessageToRoom("company", "room-id", new HashMap()); + + assertTrue(json instanceof JSONObject); + } + + @Test public void updateRoomSettings() throws Exception { + Messages messages = new Messages(client); + JSONObject json = messages.updateRoomSettings("company", "room-id", "username", new HashMap()); + + assertTrue(json instanceof JSONObject); + } + + @Test public void updateRoomMetadata() throws Exception { + Messages messages = new Messages(client); + JSONObject json = messages.updateRoomMetadata("company", "room-id", new HashMap()); + + assertTrue(json instanceof JSONObject); + } +}