Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
215 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<html> | ||
<head> | ||
<title> | ||
Toodledo Java api documentation. | ||
</title> | ||
</head> | ||
<body> | ||
<h1>TOC</h1> | ||
<ul> | ||
<li><a href="#disclaimer">Disclaimer</a></li> | ||
<li><a href="#intro">Intro</a></li> | ||
<li><a href="#usage">Usage</a></li> | ||
<ul> | ||
<li> <a href="#authentif">Authentification</a> | ||
<li> <a href="#utapi">Using the API</a> | ||
<li> <a href="#ucstd">Using the components as standalone</a> | ||
</ul> | ||
</ul> | ||
<h2><a name="disclaimer">Disclaimer</a></h2> | ||
Hello all, this is an <b>UNOFFICIAL</b> implementation of the API from <a href="http://www.toodledo.com/info/api_doc.php">toodledo</a>.<p> | ||
Of course it's free software, bla bla bla bla bla bla. So, if you build a critical system using this api and then everything runs out of memory and you end up killing dozens of elders... it's not my problem.<p> | ||
Having said that... | ||
<h2><a name="intro">Intro</a></h2> | ||
Well yeah, I'm a toodledo user and i just wanted to use that for some of my stuff, i basically program in Java, and seems like the toodledo guys haven't got an official Java api (nasty people), so i had to make one. That's it. | ||
<h2><a name="usage">Usage</a></h2> | ||
Pretty basic and pretty straightforward. | ||
<ul> | ||
<li> <a href="#authentif">Authentification</a> | ||
<li> <a href="#utapi">Using the API</a> | ||
<li> <a href="#ucstd">Using the components as standalone</a> | ||
</ul> | ||
<h3><a name="authentif"> Authentification </a></h3> | ||
<h3><a name="utapi"> Using the API </a></h3> | ||
<h3><a name="ucstd"> Using the components as standalone </a></h3> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package org.loststone.toodledo.request; | ||
|
||
import java.io.IOException; | ||
|
||
import org.apache.commons.httpclient.HttpClient; | ||
import org.apache.commons.httpclient.HttpException; | ||
import org.apache.commons.httpclient.HttpMethod; | ||
import org.apache.commons.httpclient.methods.GetMethod; | ||
import org.loststone.toodledo.ToodledoApiException; | ||
import org.loststone.toodledo.response.DeleteResponse; | ||
import org.loststone.toodledo.response.Response; | ||
import org.loststone.toodledo.util.AuthToken; | ||
|
||
public class DeleteTodoRequest extends Request { | ||
|
||
public DeleteTodoRequest(AuthToken token, int id) throws ToodledoApiException { | ||
super(); | ||
this.url = "http://api.toodledo.com/api.php?method=deleteTask;key="+token.getKey()+";id="+id; | ||
} | ||
|
||
|
||
@Override | ||
public Response exec() { | ||
HttpClient client = new HttpClient(); | ||
HttpMethod method = new GetMethod(this.url); | ||
Response addResp = null; | ||
try { | ||
client.executeMethod(method); | ||
addResp = new DeleteResponse(method.getResponseBodyAsString()); | ||
} catch (HttpException e) { | ||
e.printStackTrace(); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} finally { | ||
method.releaseConnection(); | ||
} | ||
return addResp; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package org.loststone.toodledo.request; | ||
|
||
import java.io.IOException; | ||
|
||
import org.apache.commons.httpclient.HttpClient; | ||
import org.apache.commons.httpclient.HttpException; | ||
import org.apache.commons.httpclient.HttpMethod; | ||
import org.apache.commons.httpclient.methods.GetMethod; | ||
import org.loststone.toodledo.Todo; | ||
import org.loststone.toodledo.ToodledoApiException; | ||
import org.loststone.toodledo.response.AddTodoResponse; | ||
import org.loststone.toodledo.response.Response; | ||
import org.loststone.toodledo.util.AuthToken; | ||
|
||
public class ModifyTodoRequest extends Request { | ||
|
||
public ModifyTodoRequest(AuthToken token, Todo todo) throws ToodledoApiException { | ||
super(); | ||
this.url = "http://api.toodledo.com/api.php?method=editTask;key="+token.getKey(); | ||
StringBuffer buff = new StringBuffer(); | ||
if (todo.hasId()) { | ||
buff.append(";id="+todo.getId()); | ||
} else { | ||
throw new ToodledoApiException("At least the todo must have the 'id' field."); | ||
} | ||
if (todo.hasTitle()) buff.append(";title=").append(todo.getTitle()); | ||
if (todo.hasTag()) buff.append(";tag=").append(todo.getTag()); | ||
if (todo.hasFolder()) buff.append(";folder=").append(todo.getFolder()); | ||
if (todo.hasContext()) buff.append(";context=").append(todo.getContext()); | ||
if (todo.hasGoal()) buff.append(";goal=").append(todo.getGoal()); | ||
if (todo.hasParent()) buff.append(";parent=").append(todo.getParent()); | ||
if (todo.hasBefore()) buff.append(";before=").append(todo.getBefore()); | ||
if (todo.hasStartbefore()) buff.append(";startbefore=").append(todo.getStartbefore()); | ||
// TODO seems there's something missing if (todo.has) | ||
if (todo.hasRepeat()) buff.append(";repeat=").append(todo.getRepeat()); | ||
// TODO repeat advances | ||
if (todo.hasStatus()) buff.append(";status=").append(todo.getStatus()); | ||
// TODO length in minutes | ||
if (todo.hasPriority()) buff.append(";priority=").append(todo.getPriority()); | ||
if (todo.hasStar()) buff.append(";star=").append(todo.getStart()); | ||
// TODO add a note | ||
|
||
this.url = this.url.concat(buff.toString()); | ||
} | ||
|
||
|
||
@Override | ||
public Response exec() { | ||
HttpClient client = new HttpClient(); | ||
HttpMethod method = new GetMethod(this.url); | ||
Response addResp = null; | ||
try { | ||
client.executeMethod(method); | ||
addResp = new AddTodoResponse(method.getResponseBodyAsString()); | ||
} catch (HttpException e) { | ||
e.printStackTrace(); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} finally { | ||
method.releaseConnection(); | ||
} | ||
return addResp; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package org.loststone.toodledo.response; | ||
|
||
import org.loststone.toodledo.ToodledoApiException; | ||
|
||
|
||
public class DeleteResponse extends Response { | ||
|
||
public DeleteResponse(String resp) { | ||
super(resp); | ||
if (response.contains("error")) | ||
this.succeed = false; | ||
else | ||
this.succeed = true; | ||
} | ||
|
||
@Override | ||
public int getResponseResult() { | ||
// TODO Auto-generated method stub | ||
return 0; | ||
} | ||
|
||
// TODO refactor to the parent class. | ||
public String getResponseContent() throws ToodledoApiException { | ||
String result = null; | ||
// check for errors: | ||
if (response.contains("error")) { | ||
this.succeed = false; | ||
throw new ToodledoApiException(response.substring(response.indexOf("<error>")+7, | ||
response.indexOf("</error>"))); | ||
} | ||
|
||
result = response.substring(response.indexOf("<success>")+9, response.indexOf("</success>")); | ||
this.succeed = true; | ||
return result; | ||
} | ||
|
||
} |
37 changes: 37 additions & 0 deletions
37
src/org/loststone/toodledo/response/ModifyTodoResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package org.loststone.toodledo.response; | ||
|
||
import org.loststone.toodledo.ToodledoApiException; | ||
|
||
|
||
public class ModifyTodoResponse extends Response { | ||
|
||
public ModifyTodoResponse(String resp) { | ||
super(resp); | ||
if (response.contains("error")) | ||
this.succeed = false; | ||
else | ||
this.succeed = true; | ||
} | ||
|
||
@Override | ||
public int getResponseResult() { | ||
// TODO Auto-generated method stub | ||
return 0; | ||
} | ||
|
||
// TODO refactor to the parent class. | ||
public String getResponseContent() throws ToodledoApiException { | ||
String result = null; | ||
// check for errors: | ||
if (response.contains("error")) { | ||
this.succeed = false; | ||
throw new ToodledoApiException(response.substring(response.indexOf("<error>")+7, | ||
response.indexOf("</error>"))); | ||
} | ||
|
||
result = response.substring(response.indexOf("<success>")+9, response.indexOf("</success>")); | ||
this.succeed = true; | ||
return result; | ||
} | ||
|
||
} |