AfterShip/aftership-python — pull request #2 by korshunov (2014-06-13 00:59:29+00:00)
Title: Updates

Hi Teddy!

Here is a portion of new updates.
I forgot to mention that on Tuesdays and Thursdays I'm busy with Thai classes, so my contributions whould be shifted to weekends. Next one will appear faster :)

__1. Exceptions raise on error response from aftership API__
If non 2XX response code came from API I raise exception which contains actual server response.
Example of exception handling:
```python
import aftership
api = aftership.API(FAKE_API_KEY) # Fake API key guarantee error on API call
try:
response = api.get.trackings()
except aftership.AftershipRequestException as err:
print 'Error:', err['meta']['error_type'] # "Error: InvalidCredentials"
```

__2. Rate limit support. Custom headers support__
Rate limit is set to 10 calls per second (1 call per 1/10 sec), can be overwritten by API object creation:
```python
api = aftership.API(max_calls_per_sec=5, API_KEY) # set rate limit to 5 calls per sec.
```

__3. ... added positional arguments support__
Convenient way to call methods with positional argument going at the end, e.g.:
```python
api = aftership.API(API_KEY)
tracking_number = '123456789'
api.couriers.detect.get(tracking_number) # GET /couriers/detect/:tracking_number
```

__There is 3 ways to write positional arguments:__
— Arguments separated by dots. Used for predefined API words.
— _get(), post(), put(), delete()_ positional arguments (unnamed arguments). Used for variable values that goes at the end of the API endpoint.
— String values in _['brackets']_. Used for variable values that goes NOT at the end of the API endpoint.

Example of brackets use:
```python
api = aftership.API(API_KEY)
slug = 'dhl'
tracking_number = '123456789'
api.trackings[slug][tracking_number].reactivate.post() # POST /trackings/:slug/:tracking_number/reactivate
```

Would be glad to answer your questions.
Fedor