Class 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.
    • Field Detail

      • spaceId

        public java.lang.String spaceId
    • 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 HTTPS
        java.io.IOException - if there are errors establishing a web connection OR reading the output stream
        java.lang.IllegalArgumentException - When data to post is null
      • 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