Client

This file contains the implementation of the Client class.

The Client defines methods which can be used to run REST methods on the CloudCIX API as if they were Python methods.

class cloudcix.client.Client(application, service_uri, version='v1')

CloudCIX API Client

The underlying class to generate the services in the API Reference

There are a couple of things to note about some of the methods, namely create, update, and partial_update

  • The data parameter to these methods is for passing the json data to use for the creation or updating of an object in the database

  • The params parameter is simply for filtering lists

Note

The kwargs parameter for the methods can be used to specify any other ids that are needed in the URL

__init__(application, service_uri, version='v1')

Create a Client instance to interact with a specified Service in an Application.

Parameters:
  • application (str) – Name of the application the client will interact with

  • service_uri (str) – URI specifying the location at the application where the service is listening

  • version (str) – Optional API version, defaults to v1. This is deprecated as it is ignored for the python 3 API.

create(token=None, data=None, params=None, **kwargs)

Creates a new resource using the API service (using HTTP POST)

Parameters:
  • token (str) – The user’s authentication token

  • data (Dict[str, Any]) – The HTTP POST data which will be used to create a new resource

  • params (Dict[str, Any]) – Any HTTP GET parameters to be sent in the request. Used for filtering lists, etc

  • kwargs (Dict[Any, Any]) – Any other kwargs for the method

Returns:

The data of the created resource contained in a requests.Response object, accessible through .json()

Return type:

requests.Response

delete(pk, token=None, params=None, **kwargs)

Deletes a resource identified by the given pk (using HTTP DELETE)

Parameters:
  • pk (Optional[int]) – The id of the resource to delete

  • token (str) – The user’s authentication token

  • params (Dict[str, Any]) – Any HTTP GET parameters to be sent in the request. Used for filtering lists, etc

  • kwargs (Dict[Any, Any]) – Any other kwargs for the method

Returns:

A HTTP 204 response in the form of a requests.Response instance

Return type:

requests.Response

get_all(token=None, params=None, **kwargs)

Given some parameters, retrieves all of the resources from the API that match the passed parameters

Parameters:
  • token (str) – The user’s authentication token

  • params (Dict[str, Any]) – Any HTTP GET parameters to be sent in the request. Used for filtering lists, etc

  • kwargs (Dict[Any, Any]) – Any other kwargs for the method

Returns:

A list of resources

Return type:

List[Dict[str, Any]]

head(token=None, pk=None, params=None, **kwargs)

The HEAD method retrieves metadata from an object without returning the object itself. This method is useful if you’re only interested in an object’s metadata. The HEAD is also used to check existence of a resource/collection. To use HEAD, you must have READ access to the object. (using HTTP HEAD with or without a resource id)

Parameters:
  • pk (Optional[int]) – The id of the resource to read

  • token (str) – The user’s authentication token

  • params (Dict[str, Any]) – Any HTTP HEAD parameters to be sent in the request. Used for retrieving metadata, etc

  • kwargs (Dict[Any, Any]) – Any other kwargs for the method

Returns:

A status code and metadata if params sent in request

Return type:

requests.Response

list(token=None, params=None, **kwargs)

Retrieves a list of resources from the API service (using HTTP GET without a resource id)

Parameters:
  • token (str) – The user’s authentication token

  • params (Dict[str, Any]) – Any HTTP GET parameters to be sent in the request. Used for filtering lists, etc

  • kwargs (Dict[Any, Any]) – Any other kwargs for the method

Returns:

A list of resources contained in a requests.Response object, accessible through .json()

Return type:

requests.Response

partial_update(pk, token=None, data=None, params=None, **kwargs)

Updates a resource identified by the given pk with the sent data (using HTTP PATCH). The difference between this and update is that this method will ignore any fields not sent in data.

Parameters:
  • pk (Optional[int]) – The id of the resource to update

  • token (str) – The user’s authentication token

  • data (Dict[str, Any]) – The HTTP PATCH data which will be used to update the specified resource

  • params (Dict[str, Any]) – Any HTTP GET parameters to be sent in the request. Used for filtering lists, etc

  • kwargs (Dict[Any, Any]) – Any other kwargs for the method

Returns:

The data of the updated resource contained in a requests.Response object, accessible through .json()

Return type:

requests.Response

read(pk, token=None, params=None, **kwargs)

Reads a resource from the API service identified by the given pk (using HTTP GET with a resource id)

Parameters:
  • pk (Optional[int]) – The id of the resource to read

  • token (str) – The user’s authentication token

  • params (Dict[str, Any]) – Any HTTP GET parameters to be sent in the request. Used for filtering lists, etc

  • kwargs (Dict[Any, Any]) – Any other kwargs for the method

Returns:

The data of the specified resource contained in a requests.Response object, accessible through .json()

Return type:

requests.Response

update(pk, token=None, data=None, params=None, **kwargs)

Updates a resource identified by the given pk with the sent data (using HTTP PUT)

Parameters:
  • pk (Optional[int]) – The id of the resource to update

  • token (str) – The user’s authentication token

  • data (Dict[str, Any]) – The HTTP PUT data which will be used to update the specified resource

  • params (Dict[str, Any]) – Any HTTP GET parameters to be sent in the request. Used for filtering lists, etc

  • kwargs (Dict[Any, Any]) – Any other kwargs for the method

Returns:

The data of the updated resource contained in a requests.Response object, accessible through .json()

Return type:

requests.Response