easybuild.base.rest module

This module contains Rest api utilities, Mainly the RestClient, which you can use to easily pythonify a rest api.

based on https://github.com/jpaugh/agithub/commit/1e2575825b165c1cb7cbd85c22e2561fc4d434d3

author:Jonathan Paugh
author:Jens Timmerman
class easybuild.base.rest.Client(url, username=None, password=None, token=None, token_type='Token', user_agent=None, append_slash=False)

Bases: object

An implementation of a REST client

DELETE = 'DELETE'
GET = 'GET'
HEAD = 'HEAD'
HTTP_METHODS = ('DELETE', 'GET', 'HEAD', 'PATCH', 'POST', 'PUT')
PATCH = 'PATCH'
POST = 'POST'
PUT = 'PUT'
USER_AGENT = 'vsc-rest-client'
delete(url, headers=None, body=None, **params)

Do a http delete request on the given url with given headers, body and parameters Parameters is a dictionary that will will be urlencoded

get(url, headers=None, **params)

Do a http get request on the given url with given headers and parameters Parameters is a dictionary that will will be urlencoded

get_connection(method, url, body, headers)
hash_pass(password, username=None)
head(url, headers=None, **params)

Do a http head request on the given url with given headers and parameters Parameters is a dictionary that will will be urlencoded

patch(url, body=None, headers=None, **params)

Do a http patch request on the given url with given body, headers and parameters Parameters is a dictionary that will will be urlencoded

post(url, body=None, headers=None, **params)

Do a http post request on the given url with given body, headers and parameters Parameters is a dictionary that will will be urlencoded

put(url, body=None, headers=None, **params)

Do a http put request on the given url with given body, headers and parameters Parameters is a dictionary that will will be urlencoded

request(method, url, body, headers, content_type=None)

Low-level networking. All HTTP-method methods call this

urlencode(params)
class easybuild.base.rest.RequestBuilder(client).path.to.resource.method(...)

Bases: object

stands for RequestBuilder(client).client.method(‘path/to/resource, …)

Also, if you use an invalid path, too bad. Just be ready to catch a You can use item access instead of attribute access. This is convenient for using variables’ values and required for numbers. bad status from github.com. (Or maybe an httplib.error…)

To understand the method(…) calls, check out github.client.Client.

class easybuild.base.rest.RestClient(*args, **kwargs)

Bases: object

A client with a request builder, so you can easily create rest requests e.g. to create a github Rest API client just do >>> g = RestClient(’https://api.github.com’, username=’user’, password=’pass’) >>> g = RestClient(’https://api.github.com’, token=’oauth token’) >>> status, data = g.issues.get(filter=’subscribed’) >>> data … [ list_, of, stuff ] >>> status, data = g.repos.jpaugh64.repla.issues[1].get() >>> data … { ‘dict’: ‘my issue data’, } >>> name, repo = ‘jpaugh64’, ‘repla’ >>> status, data = g.repos[name][repo].issues[1].get() … same thing >>> status, data = g.funny.I.donna.remember.that.one.get() >>> status … 404

That’s all there is to it. (blah.post() should work, too.)

NOTE: It is up to you to spell things correctly. Github doesn’t even try to validate the url you feed it. On the other hand, it automatically supports the full API–so why should you care?