Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates #2

Merged
merged 6 commits into from
Jun 18, 2014
Merged

Updates #2

merged 6 commits into from
Jun 18, 2014

Conversation

fedor
Copy link
Contributor

@fedor fedor commented Jun 13, 2014

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:

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:

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.:

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:

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

…APIv3.

APIv3 main features:
— Returns 'data' dictionary on success (strips 'meta dictionary').
— Accepts lists and datetime objects as input parameters (converts them to comma-separated strings and ISO 8601 strings).
— On return, converts ISO 8601 strings to datetime.
@teddychan
Copy link
Member

very good design and easy to use.
however, with new api v4, there is some optional parameters.
we can discuss this when v4 is launched.

teddychan added a commit that referenced this pull request Jun 18, 2014
@teddychan teddychan merged commit b17bab6 into AfterShip:master Jun 18, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants