|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.eclipse.egit.github.core.client.GitHubClient
public class GitHubClient
Client class for interacting with GitHub HTTP/JSON API.
Field Summary | |
---|---|
protected String |
baseUri
Base URI |
protected com.google.gson.Gson |
gson
Gson instance |
protected static String |
HEADER_ACCEPT
Accept header |
protected static String |
HEADER_AUTHORIZATION
Authorization header |
protected static String |
HEADER_CONTENT_TYPE
Content-Type header |
protected static String |
HEADER_USER_AGENT
User-Agent header |
protected static int |
HTTP_UNPROCESSABLE_ENTITY
422 status code for unprocessable entity |
protected static String |
METHOD_DELETE
METHOD_DELETE |
protected static String |
METHOD_GET
METHOD_GET |
protected static String |
METHOD_POST
METHOD_POST |
protected static String |
METHOD_PUT
METHOD_PUT |
protected String |
prefix
Prefix to apply to base URI |
protected static String |
USER_AGENT
Default user agent request header value |
Constructor Summary | |
---|---|
GitHubClient()
Create default client |
|
GitHubClient(String hostname)
Create client for host name |
|
GitHubClient(String hostname,
int port,
String scheme)
Create client for host, port, and scheme |
Method Summary | ||
---|---|---|
protected HttpURLConnection |
configureRequest(HttpURLConnection request)
Configure request with standard headers |
|
protected String |
configureUri(String uri)
Configure request URI |
|
static GitHubClient |
createClient(String url)
Create API v3 client from URL. |
|
protected HttpURLConnection |
createConnection(String uri)
Create connection to URI |
|
protected HttpURLConnection |
createConnection(String uri,
String method)
Create connection to URI |
|
protected HttpURLConnection |
createDelete(String uri)
Create a DELETE request connection to the URI |
|
protected IOException |
createException(InputStream response,
int code,
String status)
Create error exception from response and throw it |
|
protected HttpURLConnection |
createGet(String uri)
Create a GET request connection to the URI |
|
protected HttpURLConnection |
createPost(String uri)
Create a POST request connection to the URI |
|
protected HttpURLConnection |
createPut(String uri)
Create a PUT request connection to the URI |
|
protected String |
createUri(String path)
Create full URI from path |
|
void |
delete(String uri)
Delete resource at URI. |
|
void |
delete(String uri,
Object params)
Delete resource at URI. |
|
GitHubResponse |
get(GitHubRequest request)
Get response from URI and bind to specified type |
|
protected Object |
getBody(GitHubRequest request,
InputStream stream)
Get body from response inputs stream |
|
int |
getRemainingRequests()
Get number of requests remaining before rate limiting occurs |
|
int |
getRequestLimit()
Get number of requests that getRemainingRequests() counts down
from as each request is made |
|
InputStream |
getStream(GitHubRequest request)
Get response stream from URI. |
|
protected InputStream |
getStream(HttpURLConnection request)
Get stream from request |
|
String |
getUser()
Get the user that this client is currently authenticating as |
|
protected boolean |
isEmpty(int code)
Is the response empty? |
|
protected boolean |
isError(int code)
Does status code denote an error |
|
protected boolean |
isOk(int code)
Does status code denote a non-error response? |
|
protected RequestError |
parseError(InputStream response)
Parse error from response |
|
protected
|
parseJson(InputStream stream,
Type type)
Parse JSON to specified type |
|
void |
post(String uri)
Post to URI |
|
|
post(String uri,
Object params,
Type type)
Post data to URI |
|
void |
put(String uri)
Put to URI |
|
|
put(String uri,
Object params,
Type type)
Put data to URI |
|
protected void |
sendParams(HttpURLConnection request,
Object params)
Send parameters to output stream of request |
|
GitHubClient |
setBufferSize(int bufferSize)
Set buffer size used to send the request and read the response |
|
GitHubClient |
setCredentials(String user,
String password)
Set credentials |
|
GitHubClient |
setOAuth2Token(String token)
Set OAuth2 token |
|
GitHubClient |
setSerializeNulls(boolean serializeNulls)
Set whether or not serialized data should include fields that are null. |
|
GitHubClient |
setUserAgent(String agent)
Set the value to set as the user agent header on every request created. |
|
protected String |
toJson(Object object)
Convert object to a JSON string |
|
protected GitHubClient |
updateRateLimits(HttpURLConnection request)
Update rate limits present in response headers |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected static final String HEADER_CONTENT_TYPE
protected static final String HEADER_ACCEPT
protected static final String HEADER_AUTHORIZATION
protected static final String HEADER_USER_AGENT
protected static final String METHOD_GET
protected static final String METHOD_PUT
protected static final String METHOD_POST
protected static final String METHOD_DELETE
protected static final String USER_AGENT
protected static final int HTTP_UNPROCESSABLE_ENTITY
protected final String baseUri
protected final String prefix
protected com.google.gson.Gson gson
Gson
instance
Constructor Detail |
---|
public GitHubClient()
public GitHubClient(String hostname)
hostname
- public GitHubClient(String hostname, int port, String scheme)
hostname
- port
- scheme
- Method Detail |
---|
public static GitHubClient createClient(String url)
This creates an HTTPS-based client with a host that contains the host value of the given URL prefixed with 'api' if the given URL is github.com or gist.github.com
url
-
public GitHubClient setSerializeNulls(boolean serializeNulls)
serializeNulls
-
public GitHubClient setUserAgent(String agent)
agent
-
protected HttpURLConnection configureRequest(HttpURLConnection request)
request
-
protected String configureUri(String uri)
uri
-
protected HttpURLConnection createConnection(String uri) throws IOException
uri
-
IOException
protected HttpURLConnection createConnection(String uri, String method) throws IOException
uri
- method
-
IOException
protected HttpURLConnection createGet(String uri) throws IOException
uri
-
IOException
protected HttpURLConnection createPost(String uri) throws IOException
uri
-
IOException
protected HttpURLConnection createPut(String uri) throws IOException
uri
-
IOException
protected HttpURLConnection createDelete(String uri) throws IOException
uri
-
IOException
public GitHubClient setCredentials(String user, String password)
user
- password
-
public GitHubClient setOAuth2Token(String token)
token
-
public GitHubClient setBufferSize(int bufferSize)
bufferSize
-
public String getUser()
protected String toJson(Object object) throws IOException
object
-
IOException
protected <V> V parseJson(InputStream stream, Type type) throws IOException
V
- stream
- type
-
IOException
protected boolean isError(int code)
code
-
protected boolean isOk(int code)
code
-
protected boolean isEmpty(int code)
code
-
protected RequestError parseError(InputStream response) throws IOException
response
-
IOException
protected Object getBody(GitHubRequest request, InputStream stream) throws IOException
request
- stream
-
IOException
protected IOException createException(InputStream response, int code, String status)
response
- code
- status
-
IOException
public void post(String uri) throws IOException
uri
-
IOException
public void put(String uri) throws IOException
uri
-
IOException
public void delete(String uri) throws IOException
IOException
when the response status is not a 204 (No Content).
uri
-
IOException
protected void sendParams(HttpURLConnection request, Object params) throws IOException
request
- params
-
IOException
protected String createUri(String path)
path
-
public InputStream getStream(GitHubRequest request) throws IOException
request
-
IOException
protected InputStream getStream(HttpURLConnection request) throws IOException
request
-
IOException
public GitHubResponse get(GitHubRequest request) throws IOException
request
-
IOException
public <V> V post(String uri, Object params, Type type) throws IOException
V
- uri
- params
- type
-
IOException
public <V> V put(String uri, Object params, Type type) throws IOException
V
- uri
- params
- type
-
IOException
public void delete(String uri, Object params) throws IOException
IOException
when the response status is not a 204 (No Content).
uri
- params
-
IOException
protected GitHubClient updateRateLimits(HttpURLConnection request)
request
-
public int getRemainingRequests()
This will be the value of the 'X-RateLimit-Remaining' header from the last request made
public int getRequestLimit()
getRemainingRequests()
counts down
from as each request is made
This will be the value of the 'X-RateLimit-Limit' header from the last request made
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |