The Moco Instance

class moco_wrapper.Moco(auth={}, objector=<moco_wrapper.util.objector.default.DefaultObjector object>, requestor=<moco_wrapper.util.requestor.default.DefaultRequestor object>, impersonate_user_id: int = None, **kwargs)

Main Moco class for handling authentication, object conversion, requesting ressources with the moco api

Parameters:
import moco_wrapper
moco = moco_wrapper.Moco(
    auth = {
        "api_key": "<TOKEN>",
        "domain": "<DOMAIN>"
    }
)
auth = None

Authentication information

It either contains an api key and and domain

from moco_wrapper import Moco

m = Moco(
    auth={"api_key": "here is my key", "domain": "testdomain"}
)

Or it contains domain, email and password

from moco_wrapper import Moco

m = Moco(
    auth={"domain": "testdomain", "email": "testemail@mycompany.com", "password": "test"}
)
authenticate()

Performs any action necessary to be authenticated against the moco api.

This method gets invoked automatically, on the very first request you send against the api.

clear_impersonation()

Ends impersonation

See also

impersonate()

delete(path, ep_params=None, params=None, data=None, **kwargs)

Helper function for DELETE requests

full_domain

Returns the full url of the moco api

>> m = Moco(auth={"domain": "testabcd", ..})
>> print(m.full_domain)
https://testabcd.mocoapp.com/api/v1
get(path, ep_params=None, params=None, data=None, **kwargs)

Helper function for GET requests

headers

Returns all http headers to be used by the assigned requestor

impersonate(user_id: int)

Impersonates the user with the supplied user id

Parameters:user_id – user id to impersonate

See also

clear_impersonation() to end impersonation of user_id

objector

Get the currently assigned objector object

See also

Objector

patch(path, ep_params=None, params=None, data=None, **kwargs)

Helper function for PATCH requests

post(path, ep_params=None, params=None, data=None, **kwargs)

Helper function for POST requests

put(path, ep_params=None, params=None, data=None, **kwargs)

Helper function for PUT requests

request(method: str, path: str, params: dict = None, data: dict = None, bypass_auth: bool = False, **kwargs)

Requests the given resource with the assigned requestor

Parameters:
  • method – HTTP Method (eg. POST, GET, PUT, DELETE)
  • path – path of the resource (e.g. /projects)
  • params – url parameters (e.g. page=1, query parameters)
  • data – dictionary with data (http body)
  • bypass_auth – If authentication checks should be skipped (default False)

The request will be given to the currently assigned requestor (see Requestor). The response will then be given to the currently assigned objector (see Objector)

The possibly modified response will then be returned

requestor

Get the currently assigned requestor object

See also

Requestor

session

Get the http.session object of the current requestor (None if the requestor does not have a session)