org.knuth.chkupdate.provider
Class GitHubProvider

java.lang.Object
  extended by org.knuth.chkupdate.Provider
      extended by org.knuth.chkupdate.provider.GitHubProvider

public class GitHubProvider
extends Provider

A Provider used to check for a new Update on GitHub.

Author:
Lukas Knuth
See Also:
GitHub-Webseite

Nested Class Summary
private  class GitHubProvider.TagWrapper
          Wrapper which is used to wrap the commit-ID and it's date in one Object.
 
Field Summary
private  java.lang.String BASE_URL
          The Base of the Request-URL
private  java.lang.String COMMIT_START
           
private  java.lang.String repo
          The given Repo from "username"
private  java.lang.String TAG_COMMAND
           
private  java.lang.String TAG_START
           
private  java.lang.String username
          The given UserName
 
Constructor Summary
GitHubProvider(java.lang.String username, java.lang.String repo)
          Creates a new Provider for GitHub
 
Method Summary
private  java.net.URL createCommitURL(java.lang.String commit_id)
          Creates an "URL"-Object to query the GitHub API for a single commit.
private  java.net.URL createListURL()
          Creates an "URL"-Object from the given URL-parts to query the GitHub API for a list of tags.
 UpdateResult doCheck()
          Performs the Update-Check.
 java.lang.String getName()
          Returns the Name of the Service used by this Provider
private  java.util.Date parseCommitDate(java.lang.String response)
          Parses the JSON-Response to a "Date"-Object.
private  GitHubProvider.TagWrapper parseList(java.lang.String response)
          Parses the tag-list JSON-String and returns the first (last added) item of it.
private  java.lang.String requestReader(java.net.URL url)
          Reads the plain-text response of the GitHub API for the given request-URL.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BASE_URL

private final java.lang.String BASE_URL
The Base of the Request-URL

See Also:
Constant Field Values

TAG_START

private final java.lang.String TAG_START
See Also:
Constant Field Values

TAG_COMMAND

private final java.lang.String TAG_COMMAND
See Also:
Constant Field Values

COMMIT_START

private final java.lang.String COMMIT_START
See Also:
Constant Field Values

username

private java.lang.String username
The given UserName


repo

private java.lang.String repo
The given Repo from "username"

Constructor Detail

GitHubProvider

public GitHubProvider(java.lang.String username,
                      java.lang.String repo)
Creates a new Provider for GitHub

Parameters:
username - The user-name on GitHub.
repo - The Repo's name on GitHub.
Method Detail

doCheck

public UpdateResult doCheck()
                     throws UpdateRequestException,
                            UpdateResponseException
Description copied from class: Provider
Performs the Update-Check.

Specified by:
doCheck in class Provider
Returns:
An "UpdateResult"-Object holding informations about the newest update.
Throws:
UpdateRequestException - Thrown when there was a problem requesting informations from the Provider.
UpdateResponseException - Thrown when there was a problem parsing the response from the Provider.

parseCommitDate

private java.util.Date parseCommitDate(java.lang.String response)
                                throws UpdateResponseException
Parses the JSON-Response to a "Date"-Object.

Parameters:
response - The JSON-String.
Returns:
A "Date"-object parsed from the JSON-String.
Throws:
UpdateResponseException - Thrown when the Date could not be parsed.

parseList

private GitHubProvider.TagWrapper parseList(java.lang.String response)
                                     throws UpdateResponseException
Parses the tag-list JSON-String and returns the first (last added) item of it.

Parameters:
response - The JSON-String.
Returns:
The first (last added) item of the list in a Wrapper.
Throws:
UpdateResponseException - Thrown when the JSON- String could not be parsed.

requestReader

private java.lang.String requestReader(java.net.URL url)
                                throws UpdateRequestException
Reads the plain-text response of the GitHub API for the given request-URL.

Parameters:
url - The request-URL.
Returns:
The plain-text response of the GitHub API as a String.
Throws:
UpdateRequestException - Thrown when the GitHub API could not be reached.

createListURL

private java.net.URL createListURL()
                            throws java.net.MalformedURLException
Creates an "URL"-Object from the given URL-parts to query the GitHub API for a list of tags.

Returns:
The URL to query the GitHub API
Throws:
java.net.MalformedURLException - Thrown when the URL could not be created.

createCommitURL

private java.net.URL createCommitURL(java.lang.String commit_id)
                              throws java.net.MalformedURLException
Creates an "URL"-Object to query the GitHub API for a single commit.

Parameters:
commit_id - The ID of the commit.
Returns:
The URL to query the GitHub API.
Throws:
java.net.MalformedURLException - Thrown when the URL could not be created.

getName

public java.lang.String getName()
Description copied from class: Provider
Returns the Name of the Service used by this Provider

Specified by:
getName in class Provider
Returns:
The Service-Name