GithubHelp home page GithubHelp logo

ebii / roulier Goto Github PK

View Code? Open in Web Editor NEW

This project forked from akretion/roulier

0.0 2.0 0.0 89 KB

API for package delivery

License: GNU Affero General Public License v3.0

Python 98.34% Zimpl 0.89% XSLT 0.77%

roulier's Introduction

Roulier

Roulier is a shipping library written in Python for sending parcels. Roulier will get a label + tracking number to your carrier for you.

big picture

  • Roulier runs on your server and call each carrier API directly.
  • You have to use your own credentials provided by each carriers.
  • Roulier is Open Source software, AGPL-3
  • Roulier integrate a multitude of carriers : Laposte, Geodis, DPD, K&N... more to come.

Usage

from roulier import roulier

laposte = roulier.get('laposte')

response = laposte.get_label({
	"auth": { 
		"login": "12345",
		"password": "password",
	},
	"service": {
		"productCode": "COL"
	},
	"parcel": {
		"weight": 3.4,
	},
	"to_address": {
		"firstName": "Hparfr"
		"street1": "35 b Rue Montgolfier"
		"city": "Villeurbanne"
        "country": "FR",
        "zip": "69100"
   	},
   	"from_address": {
		"fristName": "Akretion France"
		"street1": "35 b Rue Montgolfier"
		"city": "Villeurbanne"
        "country": "FR",
        "zip": "69100"
   	},
})


print response

Get supported carriers:

from roulier import roulier
print roulier.get_carriers()

To get the full list of parameters:

from pprint import pprint
from roulier import roulier


laposte = roulier.get('laposte')
pprint(laposte.api())

# ...

Advanced usage for Laposte

Usefull for debugging: get the xml before the call, send an xml directly, analyse the response

from roulier import roulier
laposte = roulier.get('laposte')

#0) create dict for the request as usually 
api = laposte.api();
api['auth']['login'] = '12345'
...

# 1) get the sls xml: 
req = laposte.encoder.encode(api, 'generateLabelRequest')
# req['body'] contains the xml payload (<sls:generateLabel xmlns:sls="http://sls.ws.coliposte.fr">...</sls:generateLabel>)

# 2) get the soap message
soap_request = laposte.ws.soap_wrap(req['body'], req['headers'])
#soap_request is a string (xml)

# 3) send xml_request to ws
soap_response = laposte.ws.send_request(xml_request)
# soap_response is a Requests response

# 4) interpret the response
data = laposte.ws.handle_response(soap_response)

# 5)get the raw Request Response:
data['response'] 

It's more or less the same for every carrier with SOAP webservice.

Validate input

For input validate we use Cerberus

from roulier import roulier
laposte = roulier.get('laposte')

# get a ready to fill dict with default values:
laposte.api()


# advanced usage : 
from roulier.carriers.laposte.laposte_api import LaposteApi
l_api = LaposteApi()

# get the full schema:
l_api.api_schema()

# validate a dict against the schema
a_dict = { 'auth': {'login': '', 'password': 'password'}, ... }
l_api.errors(a_dict)
# > {'auth': [{'login': ['empty values not allowed']}], ...}

# get a part of schema (like 'parcel')
l_api._parcel()

###Contributors

Dependencies

roulier's People

Contributors

damdam-s avatar hparfr avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.