This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (pypi.python.org).
Help us improve Python packaging - Donate today!

a client for the classowl.com REST API

Project Description

This is a client for classowl’s RESTful API based on slumber, a generic REST API client. Slumber turns an expression like:

>>> endpoint.users.me.get(param=2)

or:

>>> endpoint.users('me').get(param=2)

into an Http request like:

GET <endpoint>/users/me?param=2

or:

>>> endpoint.users('me').put(data)

into an Http request like:

PUT <endpoint>/users/me

It also serializes and deserlializes the data automatically to and from dictionaries.

Included are a factory for a slumber endpoint which provides authentication given a username and password or an access token:

>>> import classowl_client
>>> client = classowl_client.create('username', 'password')
>>> client.users.me.get()
DataObject(**{'email': 'you@host.com',
 'first_name': 'John',
 'id': 4387,
 'is_staff': False,
 'last_name': 'Smith',
 'profile': '/api/v1/user_profiles/4381/',
 'resource_uri': '/api/v1/users/4387/',
 'token': '2882386636-c50f9414ae284727fc9e'})

or, if you want to persist the token, avoiding repeating the initial login call:

>>> token = classowl_client.get_token('username', 'password')
>>> token
'78285b2c479c5f9f73ccca094b7f9307f2648144'
>>> client = classowl_client.create(token=token)
>>> client.users.me.get()
DataObject(**{'email': 'you@host.com',
 'first_name': 'John',
 'id': 4387,
 'is_staff': False,
 'last_name': 'Smith',
 'profile': '/api/v1/user_profiles/4381/',
 'resource_uri': '/api/v1/users/4387/',
 'token': '2882386636-c50f9414ae284727fc9e'})

A few lazily instantiated shortcuts to the main endpoints for convenience, which authenticate using the username and password set on the module:

>>> classowl_client.username = 'username'
>>> classowl_client.password = 'password'
>>> classowl_client.users.me.get()
DataObject(**{'email': 'you@host.com',
 'first_name': 'John',
 'id': 4387,
 'is_staff': False,
 'last_name': 'Smith',
 'profile': '/api/v1/user_profiles/4381/',
 'resource_uri': '/api/v1/users/4387/',
 'token': '2882386636-c50f9414ae284727fc9e'})

A serializer that turns the received data into objects:

>>> account = client.users.me.get()
>>> account
DataObject(**{'email': 'you@host.com',
 'first_name': 'John',
 'id': 4387,
 'is_staff': False,
 'last_name': 'Smith',
 'profile': '/api/v1/user_profiles/4381/',
 'resource_uri': '/api/v1/users/4387/',
 'token': '2882386636-c50f9414ae284727fc9e'})
>>> account.last_name
'Smith'

Its main feature is turning the uri fields into usable endpoints:

>>> account.profile.get()
DataObject(**{'avatar_url': None,
 'current_year': None,
 'department': None,
 'email_notifications': True,
 'graduation_year': 2013,
 'id': 4381,
 'is_private': False,
 'is_valid_email': True,
 'resource_uri': '/api/v1/user_profiles/4381/',
 'role': 3,
 'school': '/api/v1/schools/5/',
 'unread_notifications': 40,
 'user': '/api/v1/users/4387/',
 'walkthrough_step': 5})

To update the information:

>>> account.last_name = 'Brown'
>>> classowl_client.users.me.put(account)
DataObject(**{'email': 'you@host.com',
 'first_name': 'John',
 'id': 4387,
 'is_staff': False,
 'last_name': 'Brown',
 'pk': 4387,
 'profile': '/api/v1/user_profiles/4381/',
 'resource_uri': '/api/v1/users/4387/',
 'token': '2882386636-c50f9414ae284727fc9e'})
>>> classowl_client.users.me.get()
DataObject(**{'email': 'you@host.com',
 'first_name': 'John',
 'id': 4387,
 'is_staff': False,
 'last_name': 'Brown',
 'profile': '/api/v1/user_profiles/4381/',
 'resource_uri': '/api/v1/users/4387/',
 'token': '2882386636-c50f9414ae284727fc9e'})

You can get the plain dictionary data from it like so:

>>> dict(account)
{'email': 'you@host.com',
 'first_name': 'John',
 'id': 4387,
 'is_staff': False,
 'last_name': 'Smith',
 'profile': '/api/v1/user_profiles/4381/',
 'resource_uri': '/api/v1/users/4387/',
 'token': '2882386636-c50f9414ae284727fc9e'}
Release History

Release History

This version
History Node

0.1a2

History Node

0.1a1

Download Files

Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
classowl-client-0.1a2.tar.gz (4.2 kB) Copy SHA256 Checksum SHA256 Source Jun 20, 2014

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting