org.eclipse.egit.github.core.client
Class GitHubClient

java.lang.Object
  extended by org.eclipse.egit.github.core.client.GitHubClient

public class GitHubClient
extends Object

Client class for interacting with GitHub HTTP/JSON API.


Constructor Summary
GitHubClient()
          Create default client
GitHubClient(org.apache.http.HttpHost httpHost)
          Create client for host configuration
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
<V extends org.apache.http.HttpMessage>
V
configureRequest(V 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  org.apache.http.client.methods.HttpDelete createDelete(String uri)
          Create delete method
protected  IOException createException(org.apache.http.HttpResponse response, org.apache.http.StatusLine status)
          Create error exception from response and throw it
protected  org.apache.http.client.methods.HttpGet createGet(String uri)
          Create get method
protected  org.apache.http.client.methods.HttpPost createPost(String uri)
          Create standard post method
protected  org.apache.http.client.methods.HttpPut createPut(String uri)
          Create standard put method
 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  org.apache.http.HttpEntity getEntity(org.apache.http.HttpResponse response)
          Get HttpEntity from response
protected  org.apache.http.StatusLine getStatus(org.apache.http.HttpResponse response)
          Get status line from response
 InputStream getStream(GitHubRequest request)
          Get response stream from URI.
protected  InputStream getStream(org.apache.http.HttpResponse response)
          Get InputStream from response
 String getUser()
          Get the user that this client is currently authenticating as
protected  boolean isEmpty(org.apache.http.HttpResponse response, org.apache.http.StatusLine status)
          Is the response empty?
protected  boolean isOk(org.apache.http.HttpResponse response, org.apache.http.StatusLine status)
          Is the response successful?
protected  RequestError parseError(org.apache.http.HttpResponse response)
          Parse error from response
protected
<V> V
parseJson(org.apache.http.HttpResponse response, Type type)
          Parse JSON to specified type
 void post(String uri)
          Post to URI
<V> V
post(String uri, Object params, Type type)
          Post data to URI
 void put(String uri)
          Put to URI
<V> V
put(String uri, Object params, Type type)
          Put data to URI
protected
<V> V
sendJson(org.apache.http.client.methods.HttpEntityEnclosingRequestBase method, Object params, Type type)
          Send JSON using specified method
 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  GitHubClient updateCredentials(String user, String password)
          Update credential on HTTP client credentials provider
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GitHubClient

public GitHubClient()
Create default client


GitHubClient

public GitHubClient(String hostname)
Create client for host name

Parameters:
hostname -

GitHubClient

public GitHubClient(String hostname,
                    int port,
                    String scheme)
Create client for host, port, and scheme

Parameters:
hostname -
port -
scheme -

GitHubClient

public GitHubClient(org.apache.http.HttpHost httpHost)
Create client for host configuration

Parameters:
httpHost -
Method Detail

createClient

public static GitHubClient createClient(String url)
Create API v3 client from 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

Parameters:
url -
Returns:
client

setSerializeNulls

public GitHubClient setSerializeNulls(boolean serializeNulls)
Set whether or not serialized data should include fields that are null.

Parameters:
serializeNulls -
Returns:
this client

setUserAgent

public GitHubClient setUserAgent(String agent)
Set the value to set as the user agent header on every request created. Specifying a null or empty agent parameter will reset this client to use the default user agent header value.

Parameters:
agent -
Returns:
this client

configureRequest

protected <V extends org.apache.http.HttpMessage> V configureRequest(V request)
Configure request with standard headers

Parameters:
request -
Returns:
configured request

configureUri

protected String configureUri(String uri)
Configure request URI

Parameters:
uri -
Returns:
configured URI

createPost

protected org.apache.http.client.methods.HttpPost createPost(String uri)
Create standard post method

Parameters:
uri -
Returns:
post

createPut

protected org.apache.http.client.methods.HttpPut createPut(String uri)
Create standard put method

Parameters:
uri -
Returns:
post

createGet

protected org.apache.http.client.methods.HttpGet createGet(String uri)
Create get method

Parameters:
uri -
Returns:
get method

createDelete

protected org.apache.http.client.methods.HttpDelete createDelete(String uri)
Create delete method

Parameters:
uri -
Returns:
get method

updateCredentials

protected GitHubClient updateCredentials(String user,
                                         String password)
Update credential on HTTP client credentials provider

Parameters:
user -
password -
Returns:
this client

setCredentials

public GitHubClient setCredentials(String user,
                                   String password)
Set credentials

Parameters:
user -
password -
Returns:
this client

setOAuth2Token

public GitHubClient setOAuth2Token(String token)
Set OAuth2 token

Parameters:
token -
Returns:
this client

getUser

public String getUser()
Get the user that this client is currently authenticating as

Returns:
user or null if not authentication

parseJson

protected <V> V parseJson(org.apache.http.HttpResponse response,
                          Type type)
               throws IOException
Parse JSON to specified type

Type Parameters:
V -
Parameters:
response -
type -
Returns:
type
Throws:
IOException

getEntity

protected org.apache.http.HttpEntity getEntity(org.apache.http.HttpResponse response)
                                        throws IOException
Get HttpEntity from response

Parameters:
response -
Returns:
non-null entity
Throws:
IOException

getStream

protected InputStream getStream(org.apache.http.HttpResponse response)
                         throws IOException
Get InputStream from response

Parameters:
response -
Returns:
non-null input stream
Throws:
IOException

parseError

protected RequestError parseError(org.apache.http.HttpResponse response)
                           throws IOException
Parse error from response

Parameters:
response -
Returns:
request error
Throws:
IOException

createException

protected IOException createException(org.apache.http.HttpResponse response,
                                      org.apache.http.StatusLine status)
Create error exception from response and throw it

Parameters:
response -
status -
Returns:
non-null newly created IOException

isOk

protected boolean isOk(org.apache.http.HttpResponse response,
                       org.apache.http.StatusLine status)
Is the response successful?

Parameters:
response -
status -
Returns:
true if okay, false otherwise

isEmpty

protected boolean isEmpty(org.apache.http.HttpResponse response,
                          org.apache.http.StatusLine status)
Is the response empty?

Parameters:
response -
status -
Returns:
true if empty, false otherwise

getStatus

protected org.apache.http.StatusLine getStatus(org.apache.http.HttpResponse response)
                                        throws IOException
Get status line from response

Parameters:
response -
Returns:
Non-null status line
Throws:
IOException

getStream

public InputStream getStream(GitHubRequest request)
                      throws IOException
Get response stream from URI. It is the responsibility of the calling method to close the returned stream.

Parameters:
request -
Returns:
stream
Throws:
IOException

get

public GitHubResponse get(GitHubRequest request)
                   throws IOException
Get response from URI and bind to specified type

Parameters:
request -
Returns:
response
Throws:
IOException

sendJson

protected <V> V sendJson(org.apache.http.client.methods.HttpEntityEnclosingRequestBase method,
                         Object params,
                         Type type)
              throws IOException
Send JSON using specified method

Type Parameters:
V -
Parameters:
method -
params -
type -
Returns:
resource
Throws:
IOException

post

public <V> V post(String uri,
                  Object params,
                  Type type)
       throws IOException
Post data to URI

Type Parameters:
V -
Parameters:
uri -
params -
type -
Returns:
response
Throws:
IOException

post

public void post(String uri)
          throws IOException
Post to URI

Parameters:
uri -
Throws:
IOException

put

public <V> V put(String uri,
                 Object params,
                 Type type)
      throws IOException
Put data to URI

Type Parameters:
V -
Parameters:
uri -
params -
type -
Returns:
response
Throws:
IOException

put

public void put(String uri)
         throws IOException
Put to URI

Parameters:
uri -
Throws:
IOException

delete

public void delete(String uri,
                   Object params)
            throws IOException
Delete resource at URI. This method will throw an IOException when the response status is not a 204 (No Content).

Parameters:
uri -
params -
Throws:
IOException

delete

public void delete(String uri)
            throws IOException
Delete resource at URI. This method will throw an IOException when the response status is not a 204 (No Content).

Parameters:
uri -
Throws:
IOException


Copyright © 2012. All Rights Reserved.