Skip to content
This repository has been archived by the owner on Oct 9, 2018. It is now read-only.

Commit

Permalink
Merge pull request #3 from odesk/v0_1_8
Browse files Browse the repository at this point in the history
version 0.1.8
  • Loading branch information
mnovozhylov committed Sep 24, 2014
2 parents 0b90a73 + d69f2e7 commit 0ef259b
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 13 deletions.
6 changes: 6 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Release History

## 0.1.8
* Added new API - Suspend Contract
* Added new API - Resume Contract
* Un/archive Activities start supporting a list of codes
* Added new method client.getAuthorizationUrl(oauthCallback), supported in mobile applications

## 0.1.7
* Added new API - Get brief profile summary
* Added new API - Update bulk of activities
Expand Down
Binary file modified doc/java-odesk-javadoc.zip
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,9 @@ class ODeskAuthorizeTask extends AsyncTask<Void, Void, String> {
@Override
protected String doInBackground(Void... params) {
String authzUrl = client.getAuthorizationUrl();
// if your api key type is 'mobile', possibly you want to use
// oauth_callback in your application, then use
//String authzUrl = client.getAuthorizationUrl("x-app://your_callback");

startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(authzUrl)));

Expand Down
Binary file modified lib/java-odesk.jar
Binary file not shown.
40 changes: 30 additions & 10 deletions src/com/oDesk/api/OAuthClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,22 +100,23 @@ public OAuthClient(Config properties) {
mOAuthConsumer = new CommonsHttpOAuthConsumer(consumerKey, consumerSecret);
}

/**
* Get authorization URL, and use provided callback
*
* @param oauthCallback URL, i.e. oauth_callback used in mobile applications
* @return URL for authorizing application
* */
public String getAuthorizationUrl(String oauthCallback) {
return _getAuthorizationUrl(oauthCallback);
}

/**
* Get authorization URL
*
* @return URL for authorizing application
* */
public String getAuthorizationUrl() {
String url = null;

try {
url = mOAuthProvider.retrieveRequestToken(mOAuthConsumer, "");
}
catch (OAuthException e) {
e.printStackTrace();
}

return url;
return _getAuthorizationUrl("");
}

/**
Expand Down Expand Up @@ -246,6 +247,25 @@ public JSONObject delete(String url, HashMap<String, String> params) throws JSON
return sendPostRequest(url, METHOD_DELETE, params);
}

/**
* Get authorization URL, use provided callback URL
*
* @param oauthCallback URL, i.e. oauth_callback
* @return URL for authorizing application
* */
private String _getAuthorizationUrl(String oauthCallback) {
String url = null;

try {
url = mOAuthProvider.retrieveRequestToken(mOAuthConsumer, oauthCallback);
}
catch (OAuthException e) {
e.printStackTrace();
}

return url;
}

/**
* Send signed GET OAuth request
*
Expand Down
4 changes: 2 additions & 2 deletions src/com/oDesk/api/Routers/Activities/Team.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public JSONObject updateActivity(String company, String team, String code, HashM
*
* @param company Company ID
* @param team Team ID
* @param code Specific code
* @param code Specific code(s)
* @throws JSONException If error occurred
* @return {@link JSONObject}
*/
Expand All @@ -130,7 +130,7 @@ public JSONObject archiveActivity(String company, String team, String code) thro
*
* @param company Company ID
* @param team Team ID
* @param code Specific code
* @param code Specific code(s)
* @throws JSONException If error occurred
* @return {@link JSONObject}
*/
Expand Down
26 changes: 25 additions & 1 deletion src/com/oDesk/api/Routers/Hr/Contracts.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
author = "Maksym Novozhylov <mnovozhilov@odesk.com>",
date = "6/4/2014",
currentRevision = 1,
lastModified = "6/4/2014",
lastModified = "19/9/2014",
lastModifiedBy = "Maksym Novozhylov",
reviewers = {"Yiota Tsakiri"}
)
Expand All @@ -43,6 +43,30 @@ public Contracts(OAuthClient client) {
oClient.setEntryPoint(ENTRY_POINT);
}

/**
* Suspend Contract
*
* @param reference Contract reference
* @param params Parameters
* @throws JSONException If error occurred
* @return {@link JSONObject}
*/
public JSONObject suspendContract(String reference, HashMap<String, String> params) throws JSONException {
return oClient.put("/hr/v2/contracts/" + reference + "/suspend", params);
}

/**
* Restart Contract
*
* @param reference Contract reference
* @param params Parameters
* @throws JSONException If error occurred
* @return {@link JSONObject}
*/
public JSONObject restartContract(String reference, HashMap<String, String> params) throws JSONException {
return oClient.put("/hr/v2/contracts/" + reference + "/restart", params);
}

/**
* End Contract
*
Expand Down
14 changes: 14 additions & 0 deletions test/com/oDesk/api/Routers/Hr/ContractsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,20 @@
Contracts.class
})
public class ContractsTest extends Helper {
@Test public void suspendContract() throws Exception {
Contracts contracts = new Contracts(client);
JSONObject json = contracts.suspendContract("1234", new HashMap<String, String>());

assertTrue(json instanceof JSONObject);
}

@Test public void restartContract() throws Exception {
Contracts contracts = new Contracts(client);
JSONObject json = contracts.restartContract("1234", new HashMap<String, String>());

assertTrue(json instanceof JSONObject);
}

@Test public void endContract() throws Exception {
Contracts contracts = new Contracts(client);
JSONObject json = contracts.endContract("1234", new HashMap<String, String>());
Expand Down

0 comments on commit 0ef259b

Please sign in to comment.