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: - auth (dict) – Dictionary containing authentication information, see Authentication
- objector – objector object (see Objector, default:
moco_wrapper.util.objector.DefaultObjector
) - requestor – requestor object (see Requestor, default:
moco_wrapper.util.requestor.DefaultRequestor
) - impersonate_user_id (int) – user id the client should impersonate (default: None, see https://github.com/hundertzehn/mocoapp-api-docs#impersonation)
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 neccessary to be authenticated against the moco api.
This method gets invoked automaticly, on the very first request you send against the api.
-
clear_impersonation
()¶ Ends impersonation
See also
-
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
-
headers
¶ Returns all http headers to be used by the assigned requestor
-
impersonate
(user_id: int)¶ Impersontates the user with the supplied user id
Parameters: user_id – user id to impersonate See also
clear_impersonation()
to end impersonation ofuser_id
-
request
(method, path, params=None, data=None, bypass_auth=False)¶ request the given ressource with the assigned requestor
Parameters: - method – HTTP Method (eg. POST, GET, PUT, DELETE)
- path – path of the ressource (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 assinged requestor (see Requestor). The response will then be given to the currently assinged objector (see Objector)
The possibly modified response will then be returned
-
session
¶ Get the http.session object of the current requestor (None if the requestor does not have a session)