Created
February 21, 2012 23:14
-
-
Save naaman/1879715 to your computer and use it in GitHub Desktop.
UserInfo call
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
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; | |
} | |
} |
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
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