Package com.octopusdeploy.api
Class AuthenticatedWebClient
- java.lang.Object
-
- com.octopusdeploy.api.AuthenticatedWebClient
-
public class AuthenticatedWebClient extends java.lang.Object
An Octopus Deploy web API client that automatically puts the API key in a header Offers GET and POST, returning the response as JSON.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
AuthenticatedWebClient.WebResponse
A web response code (HTTP Response code) and content from the web request.
-
Field Summary
Fields Modifier and Type Field Description java.lang.String
spaceId
-
Constructor Summary
Constructors Constructor Description AuthenticatedWebClient(java.lang.String hostUrl, java.lang.String apiKey)
Create a new instance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description AuthenticatedWebClient.WebResponse
get(java.lang.String resource)
Executes a get request against the resource provided.AuthenticatedWebClient.WebResponse
get(java.lang.String resource, java.util.Map<java.lang.String,java.lang.String> queryParameters)
Executes a get request against the resource provided.AuthenticatedWebClient.WebResponse
getRoot()
static boolean
isErrorCode(int code)
Returns true if the HTTP Response code represents an error.AuthenticatedWebClient.WebResponse
post(java.lang.String resource, byte[] data)
Executes a post against the resource provided.
-
-
-
Constructor Detail
-
AuthenticatedWebClient
public AuthenticatedWebClient(java.lang.String hostUrl, java.lang.String apiKey)
Create a new instance.- Parameters:
hostUrl
- URL to the Octopus Deploy host. example: https://octopus.company.com/apiKey
- The Octopus Deploy API key to use in making API requests
-
-
Method Detail
-
post
public AuthenticatedWebClient.WebResponse post(java.lang.String resource, byte[] data) throws java.net.ProtocolException, java.io.IOException
Executes a post against the resource provided. Uses content type application/x-www-form-urlencoded- Parameters:
resource
- the URL to the resource (omitting the host portion)data
- an encoded data array of the data to post- Returns:
- JSON blob representing the response from the server.
- Throws:
java.net.ProtocolException
- if the operation is performed on a URL that is not HTTP or HTTPSjava.io.IOException
- if there are errors establishing a web connection OR reading the output streamjava.lang.IllegalArgumentException
- When data to post is null
-
getRoot
public AuthenticatedWebClient.WebResponse getRoot() throws java.io.IOException
- Throws:
java.io.IOException
-
get
public AuthenticatedWebClient.WebResponse get(java.lang.String resource) throws java.io.IOException
Executes a get request against the resource provided.- Parameters:
resource
- the URL to the resource (omitting the host portion)- Returns:
- JSON blob representing the response from the server.
- Throws:
java.io.IOException
- if establishing the web connection fails
-
get
public AuthenticatedWebClient.WebResponse get(java.lang.String resource, java.util.Map<java.lang.String,java.lang.String> queryParameters) throws java.io.IOException
Executes a get request against the resource provided.- Parameters:
resource
- the URL to the resource (omitting the host portion)queryParameters
- a map of keys and values to include in the get.- Returns:
- JSON blob representing the response from the server.
- Throws:
java.io.IOException
- if establishing the web connection fails
-
isErrorCode
public static final boolean isErrorCode(int code)
Returns true if the HTTP Response code represents an error.- Parameters:
code
- the HTTP Response code- Returns:
- true or false
-
-