Skip to content

Instantly share code, notes, and snippets.

@naaman
Created February 21, 2012 23:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save naaman/1879715 to your computer and use it in GitHub Desktop.
Save naaman/1879715 to your computer and use it in GitHub Desktop.
UserInfo call
package models;
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import javax.xml.bind.annotation.XmlRootElement;
import java.io.Serializable;
/**
* TODO: Javadoc
*
* @author Naaman Newbold
* @author rbrainard
*/
@XmlRootElement
@JsonIgnoreProperties(ignoreUnknown = true)
public class User implements Serializable {
public String email;
public String apiKey;
public User() {}
public User(String email) {
this.email = email;
}
@Override
public boolean equals(Object other) {
if (!User.class.equals(other.getClass()))
return false;
User otherUser = (User) other;
return email.equals(otherUser.email)
&& apiKey.equals(otherUser.apiKey);
}
@Override
public String toString() {
return email + ":" + apiKey;
}
}
package services;
import com.heroku.api.exception.RequestFailedException;
import com.heroku.api.http.Http;
import com.heroku.api.http.HttpUtil;
import com.heroku.api.parser.Json;
import com.heroku.api.request.Request;
import models.User;
import java.util.Collections;
import java.util.Map;
/**
* TODO: Javadoc
*
* @author Naaman Newbold
*/
public class UserInfo implements Request<User> {
@Override
public Http.Method getHttpMethod() {
return Http.Method.GET;
}
@Override
public String getEndpoint() {
return "/user";
}
@Override
public boolean hasBody() {
return false;
}
@Override
public String getBody() {
throw HttpUtil.noBody();
}
@Override
public Http.Accept getResponseType() {
return Http.Accept.JSON;
}
@Override
public Map<String, String> getHeaders() {
return Collections.emptyMap();
}
@Override
public User getResponse(byte[] bytes, int status) {
if (status == Http.Status.OK.statusCode)
return Json.parse(bytes, getClass());
throw new RequestFailedException("Unable to get user info", status, bytes);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment