|
| 1 | +package com.Upwork.api.Routers; |
| 2 | + |
| 3 | +import java.util.HashMap; |
| 4 | + |
| 5 | +import com.Upwork.ClassPreamble; |
| 6 | +import com.Upwork.api.OAuthClient; |
| 7 | + |
| 8 | +import org.json.JSONException; |
| 9 | +import org.json.JSONObject; |
| 10 | + |
| 11 | +@ClassPreamble ( |
| 12 | + author = "Maksym Novozhylov <[email protected]>", |
| 13 | + date = "6/6/2014", |
| 14 | + currentRevision = 1, |
| 15 | + lastModified = "6/6/2014", |
| 16 | + lastModifiedBy = "Maksym Novozhylov", |
| 17 | + reviewers = {"Yiota Tsakiri"} |
| 18 | + ) |
| 19 | +public final class Messages { |
| 20 | + |
| 21 | + final static String ENTRY_POINT = "api"; |
| 22 | + |
| 23 | + private OAuthClient oClient = null; |
| 24 | + |
| 25 | + public Messages(OAuthClient client) { |
| 26 | + oClient = client; |
| 27 | + oClient.setEntryPoint(ENTRY_POINT); |
| 28 | + } |
| 29 | + |
| 30 | + /** |
| 31 | + * Retrieve rooms information |
| 32 | + * |
| 33 | + * @param company Company ID |
| 34 | + * @throws JSONException If error occurred |
| 35 | + * @return {@link JSONObject} |
| 36 | + */ |
| 37 | + public JSONObject getRooms(String company) throws JSONException { |
| 38 | + return oClient.get("/messages/v3/" + company + "/rooms"); |
| 39 | + } |
| 40 | + |
| 41 | + /** |
| 42 | + * Retrieve rooms information with params |
| 43 | + * |
| 44 | + * @param company Company ID |
| 45 | + * @param params Parameters |
| 46 | + * @throws JSONException If error occurred |
| 47 | + * @return {@link JSONObject} |
| 48 | + */ |
| 49 | + public JSONObject getRooms(String company, HashMap<String, String> params) throws JSONException { |
| 50 | + return oClient.get("/messages/v3/" + company + "/rooms", params); |
| 51 | + } |
| 52 | + |
| 53 | + /** |
| 54 | + * Get a specific room information |
| 55 | + * |
| 56 | + * @param company Company ID |
| 57 | + * @param roomId Room ID |
| 58 | + * @param params Parameters |
| 59 | + * @throws JSONException If error occurred |
| 60 | + * @return {@link JSONObject} |
| 61 | + */ |
| 62 | + public JSONObject getRoomDetails(String company, String roomId, HashMap<String, String> params) throws JSONException { |
| 63 | + return oClient.get("/messages/v3/" + company + "/rooms/" + roomId, params); |
| 64 | + } |
| 65 | + |
| 66 | + /** |
| 67 | + * Get a specific room by offer ID |
| 68 | + * |
| 69 | + * @param company Company ID |
| 70 | + * @param offerId Offer ID |
| 71 | + * @param params Parameters |
| 72 | + * @throws JSONException If error occurred |
| 73 | + * @return {@link JSONObject} |
| 74 | + */ |
| 75 | + public JSONObject getRoomByOffer(String company, String offerId, HashMap<String, String> params) throws JSONException { |
| 76 | + return oClient.get("/messages/v3/" + company + "/rooms/offers/" + offerId, params); |
| 77 | + } |
| 78 | + |
| 79 | + /** |
| 80 | + * Get a specific room by application ID |
| 81 | + * |
| 82 | + * @param company Company ID |
| 83 | + * @param applicationId Application ID |
| 84 | + * @param params Parameters |
| 85 | + * @throws JSONException If error occurred |
| 86 | + * @return {@link JSONObject} |
| 87 | + */ |
| 88 | + public JSONObject getRoomByApplication(String company, String applicationId, HashMap<String, String> params) throws JSONException { |
| 89 | + return oClient.get("/messages/v3/" + company + "/rooms/appications/" + applicationId, params); |
| 90 | + } |
| 91 | + |
| 92 | + /** |
| 93 | + * Get a specific room by contract ID |
| 94 | + * |
| 95 | + * @param company Company ID |
| 96 | + * @param contractId Contract ID |
| 97 | + * @param params Parameters |
| 98 | + * @throws JSONException If error occurred |
| 99 | + * @return {@link JSONObject} |
| 100 | + */ |
| 101 | + public JSONObject getRoomByContract(String company, String contractId, HashMap<String, String> params) throws JSONException { |
| 102 | + return oClient.get("/messages/v3/" + company + "/rooms/contracts/" + contractId, params); |
| 103 | + } |
| 104 | + |
| 105 | + /** |
| 106 | + * Create a new room |
| 107 | + * |
| 108 | + * @param company Company ID |
| 109 | + * @param params Parameters |
| 110 | + * @throws JSONException If error occurred |
| 111 | + * @return {@link JSONObject} |
| 112 | + */ |
| 113 | + public JSONObject createRoom(String company, HashMap<String, String> params) throws JSONException { |
| 114 | + return oClient.post("/messages/v3/" + company + "/rooms", params); |
| 115 | + } |
| 116 | + |
| 117 | + /** |
| 118 | + * Send a message to a room |
| 119 | + * |
| 120 | + * @param company Company ID |
| 121 | + * @param roomId Room ID |
| 122 | + * @param params Parameters |
| 123 | + * @throws JSONException If error occurred |
| 124 | + * @return {@link JSONObject} |
| 125 | + */ |
| 126 | + public JSONObject sendMessageToRoom(String company, String roomId, HashMap<String, String> params) throws JSONException { |
| 127 | + return oClient.post("/messages/v3/" + company + "/rooms/" + roomId + "/stories", params); |
| 128 | + } |
| 129 | + |
| 130 | + /** |
| 131 | + * Update a room settings |
| 132 | + * |
| 133 | + * @param company Company ID |
| 134 | + * @param roomId Room ID |
| 135 | + * @param username User ID |
| 136 | + * @param params Parameters |
| 137 | + * @throws JSONException If error occurred |
| 138 | + * @return {@link JSONObject} |
| 139 | + */ |
| 140 | + public JSONObject updateRoomSettings(String company, String roomId, String username, HashMap<String, String> params) throws JSONException { |
| 141 | + return oClient.get("/messages/v3/" + company + "/rooms/" + roomId + "/users/" + username, params); |
| 142 | + } |
| 143 | + |
| 144 | + /** |
| 145 | + * Update the metadata of a room |
| 146 | + * |
| 147 | + * @param company Company ID |
| 148 | + * @param roomId Room ID |
| 149 | + * @param params Parameters |
| 150 | + * @throws JSONException If error occurred |
| 151 | + * @return {@link JSONObject} |
| 152 | + */ |
| 153 | + public JSONObject updateRoomMetadata(String company, String roomId, HashMap<String, String> params) throws JSONException { |
| 154 | + return oClient.get("/messages/v3/" + company + "/rooms/" + roomId, params); |
| 155 | + } |
| 156 | + |
| 157 | +} |
0 commit comments