chub package

Submodules

chub.api module

this module has classes for converting python method calls to request on RESTful api

class chub.api.API(base_url, async=True, api_version='v1', token=None, **kwargs)[source]

Bases: chub.api.Resource

API takes the base_url and a boolean async . Based on value of async an async or sync fetch function is set

mappings = {}
token[source]

get the token

class chub.api.Accounts(base_url, async=True, api_version='v1', token=None, **kwargs)[source]

Bases: chub.api.API

API client for accounts service

info()[source]

get service information

login(email, password)[source]

login using email and password :param email: email address :param password: password

mappings = {'info': 'accounts.get', 'login': 'accounts.login.post', 'register_service': 'accounts.services.post'}
register_service(name, location, organisation_id, certificate)[source]

register a service :param name: name of the service :param location: url of the service :param organisation_id: organisation id :param certificate: ssl certificate

class chub.api.Resource(path, fetch, resource_map=None, request_class=<class 'tornado.httpclient.HTTPRequest'>, default_headers=None)[source]

Bases: object

Resource converts python method calls to request on RESTful api

prepare_request(*args, **kw)[source]

creates a full featured HTTPRequest objects

chub.handlers module

this module has some handler utilities for HTTP request and response

class chub.handlers.ResponseObject[source]

Bases: dict

Access the value of in a dictionary by using the key as attribute. >>> obj = ResponseObject() >>> obj[‘foo’] = ‘bar’ >>> obj.foo ‘bar’

chub.handlers.async_fetch(*args, **kwargs)[source]

fetch resource using the asynchronous AsyncHTTPClient :param request: HTTPRequest object or a url :param method: HTTP method in string format, e.g. GET, POST :param callback: callback function on the result. it is used by the coroutine decorator. :param kwargs: query string entities or POST data

chub.handlers.convert(data)[source]

convert a standalone unicode string or unicode strings in a mapping or iterable into byte strings.

chub.handlers.make_fetch_func(base_url, async, **kwargs)[source]

make a fetch function based on conditions of 1) async 2) ssl

chub.handlers.make_request(request, method, default_headers=None, **kwargs)[source]

convert parameters into relevant parts of the an http request :param request: either url or an HTTPRequest object :param method: http request method :param default_headers: default headers :param kwargs: headers, query string params for GET and DELETE, data for POST and PUT

chub.handlers.parse_response(response)[source]

parse response and return a dictionary if the content type. is json/application. :param response: HTTPRequest :return dictionary for json content type otherwise response body

chub.handlers.sync_fetch(request, method, default_headers=None, httpclient=None, **kwargs)[source]

fetch resource using the synchronous HTTPClient :param request: HTTPRequest object or a url :param method: HTTP method in string format, e.g. GET, POST :param kwargs: query string entities or POST data

chub.oauth2 module

class chub.oauth2.Delegate(resource_id, access)[source]

Bases: object

Object representing a delegate scope

class chub.oauth2.Read(resource_id=None)[source]

Bases: object

Object representing a read scope

class chub.oauth2.RequestToken[source]

Bases: object

Function object for making token requests with simple caching of the responses

NOTE: errors are not cached

max_cache_size = 100
max_until_expired = 60
purge_cache()[source]

Purge expired cached tokens and oldest tokens if more than cache_size

reset_cache()[source]

Reset the token cache

class chub.oauth2.Scope(*scopes)[source]

Bases: object

add(scope)[source]

Add a scope

remove(scope)[source]

Remove a scope

class chub.oauth2.Write(resource_id)[source]

Bases: object

Object representing a write scope

Module contents