-
Notifications
You must be signed in to change notification settings - Fork 8
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
Joe Linn
committed
Nov 21, 2013
1 parent
4b1cfa0
commit 35176eb
Showing
42 changed files
with
1,523 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,6 @@ | ||
*.iml | ||
/.idea | ||
|
||
# build files | ||
/data | ||
/target |
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
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,103 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>net.joelinn</groupId> | ||
<artifactId>asana</artifactId> | ||
<version>0.5.0</version> | ||
<packaging>jar</packaging> | ||
<description>A Java client library for Asana's API</description> | ||
<licenses> | ||
<license> | ||
<name>The Apache Software License, Version 2.0</name> | ||
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url> | ||
<distribution>repo</distribution> | ||
</license> | ||
</licenses> | ||
|
||
<scm> | ||
<connection>scm:git:[email protected]:jlinn/asana-api-java.git</connection> | ||
<developerConnection>scm:git:[email protected]:jlinn/asana-api-java.git</developerConnection> | ||
<url>http://github.com/jlinn/asana-api-java</url> | ||
</scm> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
|
||
<repositories> | ||
<repository> | ||
<id>sonatype</id> | ||
<url>http://oss.sonatype.org/content/repositories/releases/</url> | ||
</repository> | ||
</repositories> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>com.google.guava</groupId> | ||
<artifactId>guava</artifactId> | ||
<version>15.0</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.codehaus.jackson</groupId> | ||
<artifactId>jackson-jaxrs</artifactId> | ||
<version>1.9.13</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.sun.jersey</groupId> | ||
<artifactId>jersey-client</artifactId> | ||
<version>1.17.1</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>4.11</version> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
</dependencies> | ||
|
||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-dependency-plugin</artifactId> | ||
<version>2.8</version> | ||
</plugin> | ||
|
||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-source-plugin</artifactId> | ||
<version>2.2.1</version> | ||
<executions> | ||
<execution> | ||
<id>attach-sources</id> | ||
<goals> | ||
<goal>jar</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
|
||
<pluginManagement> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<configuration> | ||
<source>1.7</source> | ||
<target>1.7</target> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</pluginManagement> | ||
</build> | ||
|
||
</project> |
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,90 @@ | ||
package net.joelinn.asana; | ||
|
||
import com.sun.jersey.api.client.Client; | ||
import com.sun.jersey.api.client.ClientResponse; | ||
import com.sun.jersey.api.client.WebResource; | ||
import com.sun.jersey.api.client.config.ClientConfig; | ||
import com.sun.jersey.api.client.config.DefaultClientConfig; | ||
import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter; | ||
import com.sun.jersey.core.util.MultivaluedMapImpl; | ||
import org.codehaus.jackson.jaxrs.JacksonJsonProvider; | ||
import org.codehaus.jackson.map.DeserializationConfig; | ||
import org.codehaus.jackson.map.ObjectMapper; | ||
|
||
import javax.ws.rs.core.MediaType; | ||
import javax.ws.rs.core.UriBuilder; | ||
|
||
/** | ||
* Joe Linn | ||
* 11/16/13 | ||
*/ | ||
public abstract class AbstractClient { | ||
public static final String BASE_URL = "https://app.asana.com/api/1.0/"; | ||
|
||
protected String apiKey; | ||
|
||
protected WebResource service; | ||
|
||
public AbstractClient(String apiKey){ | ||
this.apiKey = apiKey; | ||
|
||
ClientConfig config = new DefaultClientConfig(); | ||
ObjectMapper mapper = new ObjectMapper(); | ||
mapper.configure(DeserializationConfig.Feature.UNWRAP_ROOT_VALUE, true); | ||
JacksonJsonProvider provider = new JacksonJsonProvider(mapper); | ||
config.getSingletons().add(provider); | ||
//config.getClasses().add(JacksonJsonProvider.class); | ||
Client client = Client.create(config); | ||
client.addFilter(new HTTPBasicAuthFilter(apiKey, "")); | ||
service = client.resource(UriBuilder.fromUri(BASE_URL).build()); | ||
} | ||
|
||
protected ClientResponse get(String url){ | ||
return get(url, null); | ||
} | ||
|
||
protected ClientResponse get(String url, MultivaluedMapImpl queryParams){ | ||
return request("GET", url, queryParams); | ||
} | ||
|
||
protected ClientResponse post(String url, MultivaluedMapImpl data){ | ||
return request("POST", url, null, data); | ||
} | ||
|
||
protected ClientResponse put(String url, MultivaluedMapImpl data){ | ||
return request("PUT", url, null, data); | ||
} | ||
|
||
protected ClientResponse delete(String url){ | ||
return request("DELETE", url); | ||
} | ||
|
||
protected ClientResponse request(String method, String url){ | ||
return request(method, url, null); | ||
} | ||
|
||
protected ClientResponse request(String method, String url, MultivaluedMapImpl queryParams){ | ||
return request(method, url, queryParams, null); | ||
} | ||
|
||
protected ClientResponse request(String method, String url, MultivaluedMapImpl queryParams, MultivaluedMapImpl data){ | ||
ClientResponse clientResponse = getResourceBuilder(url, queryParams).method(method, ClientResponse.class, data); | ||
checkForErrors(clientResponse); | ||
return clientResponse; | ||
} | ||
|
||
private void checkForErrors(ClientResponse clientResponse){ | ||
if(clientResponse.getClientResponseStatus().getStatusCode() != ClientResponse.Status.OK.getStatusCode() | ||
&& clientResponse.getClientResponseStatus().getStatusCode() != ClientResponse.Status.CREATED.getStatusCode()){ | ||
throw new ApiException(clientResponse.getClientResponseStatus(), clientResponse.getEntity(Errors.class).get(0).message); | ||
} | ||
} | ||
|
||
private WebResource.Builder getResourceBuilder(String url, MultivaluedMapImpl queryParams){ | ||
WebResource webResource = service.path(url); | ||
if(queryParams != null){ | ||
webResource.queryParams(queryParams); | ||
} | ||
return webResource.accept(MediaType.APPLICATION_JSON).type(MediaType.APPLICATION_FORM_URLENCODED); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/net/joelinn/asana/AbstractRequestBuilder.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,20 @@ | ||
package net.joelinn.asana; | ||
|
||
import com.sun.jersey.core.util.MultivaluedMapImpl; | ||
|
||
/** | ||
* Joe Linn | ||
* 11/20/13 | ||
*/ | ||
public abstract class AbstractRequestBuilder { | ||
protected MultivaluedMapImpl params = new MultivaluedMapImpl(); | ||
|
||
public AbstractRequestBuilder setParam(String name, Object value){ | ||
params.add(name, value); | ||
return this; | ||
} | ||
|
||
public MultivaluedMapImpl build(){ | ||
return params; | ||
} | ||
} |
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,29 @@ | ||
package net.joelinn.asana; | ||
|
||
import com.sun.jersey.api.client.ClientResponse; | ||
|
||
/** | ||
* Joe Linn | ||
* 11/17/13 | ||
*/ | ||
public class ApiException extends RuntimeException{ | ||
protected ClientResponse.Status status; | ||
protected String message; | ||
|
||
public ApiException(ClientResponse.Status status, String message){ | ||
super(message); | ||
this.status = status; | ||
this.message = message; | ||
} | ||
|
||
public ClientResponse.Status getStatus(){ | ||
return status; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
String s = getClass().getName(); | ||
String message = getLocalizedMessage(); | ||
return String.format("%s: %s %s", s, status.getStatusCode(), message); | ||
} | ||
} |
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,84 @@ | ||
package net.joelinn.asana; | ||
|
||
import net.joelinn.asana.projects.ProjectsClient; | ||
import net.joelinn.asana.stories.StoriesClient; | ||
import net.joelinn.asana.tags.TagsClient; | ||
import net.joelinn.asana.tasks.TasksClient; | ||
import net.joelinn.asana.teams.TeamsClient; | ||
import net.joelinn.asana.users.UsersClient; | ||
import net.joelinn.asana.workspaces.WorkspacesClient; | ||
|
||
/** | ||
* Joe Linn | ||
* 11/20/13 | ||
*/ | ||
public class Asana { | ||
protected String apiKey; | ||
|
||
protected ProjectsClient projectsClient; | ||
|
||
protected StoriesClient storiesClient; | ||
|
||
protected TagsClient tagsClient; | ||
|
||
protected TasksClient tasksClient; | ||
|
||
protected TeamsClient teamsClient; | ||
|
||
protected UsersClient usersClient; | ||
|
||
protected WorkspacesClient workspacesClient; | ||
|
||
public Asana(String apiKey){ | ||
this.apiKey = apiKey; | ||
} | ||
|
||
public ProjectsClient projects(){ | ||
if(projectsClient == null){ | ||
projectsClient = new ProjectsClient(apiKey); | ||
} | ||
return projectsClient; | ||
} | ||
|
||
public StoriesClient stories(){ | ||
if(storiesClient == null){ | ||
storiesClient = new StoriesClient(apiKey); | ||
} | ||
return storiesClient; | ||
} | ||
|
||
public TagsClient tags(){ | ||
if(tagsClient == null){ | ||
tagsClient = new TagsClient(apiKey); | ||
} | ||
return tagsClient; | ||
} | ||
|
||
public TasksClient tasks(){ | ||
if(tasksClient == null){ | ||
tasksClient = new TasksClient(apiKey); | ||
} | ||
return tasksClient; | ||
} | ||
|
||
public TeamsClient teams(){ | ||
if(teamsClient == null){ | ||
teamsClient = new TeamsClient(apiKey); | ||
} | ||
return teamsClient; | ||
} | ||
|
||
public UsersClient users(){ | ||
if(usersClient == null){ | ||
usersClient = new UsersClient(apiKey); | ||
} | ||
return usersClient; | ||
} | ||
|
||
public WorkspacesClient workspaces(){ | ||
if(workspacesClient == null){ | ||
workspacesClient = new WorkspacesClient(apiKey); | ||
} | ||
return workspacesClient; | ||
} | ||
} |
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,26 @@ | ||
package net.joelinn.asana; | ||
|
||
/** | ||
* Joe Linn | ||
* 11/20/13 | ||
*/ | ||
public class Colors { | ||
public static final String DARK_PINK = "dark-pink"; | ||
public static final String DARK_GREEN = "dark-green"; | ||
public static final String DARK_BLUE = "dark-blue"; | ||
public static final String DARK_RED = "dark-red"; | ||
public static final String DARK_TEAL = "dark-teal"; | ||
public static final String DARK_BROWN = "dark-brown"; | ||
public static final String DARK_ORANGE = "dark-orange"; | ||
public static final String DARK_PURPLE = "dark-purple"; | ||
public static final String DARK_WARM_GRAY = "dark-warm-gray"; | ||
public static final String LIGHT_PINK = "light-pink"; | ||
public static final String LIGHT_GREEN = "light-green"; | ||
public static final String LIGHT_BLUE = "light-blue"; | ||
public static final String LIGHT_RED = "light-red"; | ||
public static final String LIGHT_TEAL = "light-teal"; | ||
public static final String LIGHT_YELLOW = "light-yellow"; | ||
public static final String LIGHT_ORANGE = "light-orange"; | ||
public static final String LIGHT_PURPLE = "light-purple"; | ||
public static final String LIGHT_WARM_GRAY = "light-warm-gray"; | ||
} |
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,9 @@ | ||
package net.joelinn.asana; | ||
|
||
/** | ||
* Joe Linn | ||
* 11/17/13 | ||
*/ | ||
public class Error { | ||
public String message; | ||
} |
Oops, something went wrong.