View Source CircleCI.Operation (CircleCI API Client v0.1.0)

Defines a struct that tracks client requests

Note

This module is unlikely to be used directly by applications. Instead, functions in this module are useful for plugins. See CircleCI.Plugin for more information.

Fields

  • private (map): This field is useful for plugins that need to store information. Plugins should be careful to namespace their data to avoid overlap. By default, this map will include an __auth__ key with the auth credentials used for the request, __info__ containing the information that originated the request, and __opts__ containing all of the options passed in to the original operation function.

  • request_body (term): For requests that support request bodies, this key will hold the data to be included in an outgoing request. Depending on the plugins involved, this key may have Elixir terms (like a map) or strings (such as a JSON-encoded string).

  • request_headers (list of headers): HTTP headers to be included in the outgoing request. These are specified as tuples with the name of the header and its value.

  • request_method (atom): HTTP verb of the outgoing request.

  • request_params (keyword): URL-based query parameters for the outgoing request.

  • request_server (string): URL scheme and hostname of the API server for the request.

  • request_types (list of types): OpenAPI type specifications for the request body. These are specified as tuples with the Content-Type and the type specification.

  • request_url (string): URL path of the outgoing request.

  • response_body (term): For responses that include response bodies, this key will hold the data from the response. Depending on the plugins involved, this key may have raw response data (such as a JSON-encoded string) or Elixir terms (like a map).

  • response_code (integer): Response status code.

  • response_headers (list of headers): HTTP headers from the response. These are specified as tuples with the name of the header and its value.

  • response_types (list of types): OpenAPI type specifications for the response body. These are specified as tuples with the status code and the type specification.

Summary

Types

t()

Operation struct for tracking client requests from start to finish

Type annotation produced by OpenAPI

Functions

Get the client's calling function and original arguments

Get the options passed to the client request

Get the value of a response header

Put information in the operation's private data store

Add a request header to an outgoing operation

Types

@type auth() ::
  nil | (token :: String.t()) | {username :: String.t(), password :: String.t()}
@type header() :: {String.t(), String.t()}
@type headers() :: [header()]
@type method() :: :get | :put | :post | :delete | :options | :head | :patch | :trace
@type request_type() :: {String.t(), type()}
@type request_types() :: [request_type()]
@type response_type() :: {integer(), type() | nil}
@type response_types() :: [response_type()]
@type t() :: %CircleCI.Operation{
  private: map(),
  request_body: term(),
  request_headers: headers(),
  request_method: method(),
  request_params: keyword() | [{String.t(), String.t()}] | nil,
  request_server: String.t(),
  request_types: request_types() | nil,
  request_url: String.t(),
  response_body: term(),
  response_code: integer() | nil,
  response_headers: headers() | nil,
  response_types: response_types()
}

Operation struct for tracking client requests from start to finish

@type type() ::
  :binary
  | :boolean
  | :integer
  | :map
  | :number
  | :string
  | :unknown
  | {:array, type()}
  | {:nullable, type()}
  | {:union, [type()]}
  | {module(), atom()}

Type annotation produced by OpenAPI

Functions

@spec get_caller(t()) :: {module(), atom(), [any()]}

Get the client's calling function and original arguments

This level of introspection is meant for testing purposes, although other plugins can take advantage of it as necessary.

@spec get_options(t()) :: keyword()

Get the options passed to the client request

Examples

iex> operation = %Operation{private: %{__opts__: [server: "https://api.github.com"]}}
iex> Operation.get_options(operation)
[server: "https://api.github.com"]
Link to this function

get_response_header(operation, header)

View Source
@spec get_response_header(t(), String.t()) :: String.t() | nil

Get the value of a response header

If response headers have not been filled in — or the response did not have the given header — then nil will be returned.

Examples

iex> operation = %Operation{response_headers: [{"Content-Type", "application/json"}]}
iex> Operation.get_response_header(operation, "Content-Type")
"application/json"

iex> operation = %Operation{response_headers: []}
iex> Operation.get_response_header(operation, "ETag")
nil
Link to this function

put_private(operation, key, value)

View Source
@spec put_private(t(), atom(), term()) :: t()

Put information in the operation's private data store

Existing data with the same key will be overridden.

Example

iex> operation = %Operation{private: %{}}
iex> operation = Operation.put_private(operation, :my_plugin_data, "abc123")
%Operation{private: %{my_plugin_data: "abc123"}} = operation
Link to this function

put_request_header(operation, header, value)

View Source
@spec put_request_header(t(), String.t(), String.t()) :: t()

Add a request header to an outgoing operation

This function makes no effort to deduplicate headers.

Example

iex> operation = %Operation{request_headers: []}
iex> operation = Operation.put_request_header(operation, "Content-Type", "application/json")
%Operation{request_headers: [{"Content-Type", "application/json"}]} = operation