Python client for the Más Móvil's B2B API
Project description
Más Móvil Python API client
This Python API client provides access to Más Móvil's B2B REST API.
Installation
Requirements
- Python 3.8+
Usage
Login
To authenticate, you need to specify credentials which need to be set as environment variables with the following names:
'MM_BASEURL': 'https://<host>/cableOperadores/services/apexrest/api'
'MM_USER': 'user'
'MM_PASSWORD': 'pwd'
'MM_DOMAIN': 'domain'
MM_BASEURL must point to the MásMóvili's API environment, either testing or production. Pymasmovil will only append API routes to it like /v0/accounts to perform requests. In the case of testing, check with them as this surely changes per customer.
MM_USER and MM_PASSWORD must be replaced with your actual user credentials, and MM_DOMAIN must point to either "test" or "login" depending on which MM environment need to be called (test/production).
Session creation
The login is done when we create a session using the Session.create method:
from pymasmovil.models.session import Session
session = Session.create()
print('Session created with id : {}'.format(session.session_id))
This returns the API key needed to authenticate all subsequent requests. That is why the Session instance has to be passed in to other all other objects methods.
Account
from pymasmovil.models.account import Account
account_id = '0017E000017pEo3QAE'
account = Account.get(session, account_id)
To create a new account we need to use Account.create passing the account data as keyword arguments. The Account attributes are listed bellow. Note they are all strings.
town, surname, stair, roadType, roadNumber, roadName, region, province, postalCode, phone, name, id, flat, email, door, donorCountry, documentType, documentNumber, corporateName, buildingPortal
No attribute is mandatory for the client leaving parameter validation to the API.
from pymasmovil.models.account import Account
account = Account.create(session, town='Barcelona', surname='Garcia', phone='616010101')
OrderItem
Order items can be accessed the same way as accounts:
from pymasmovil.models.order_items.py import OrderItem
order_item_id = '8028E34500215wgQAA'
order_item = OrderItem.get(session, order_item_id)
Currently, order items can be created following the account creation example, but the structure of their attributes is a bit more complex.
Since GET /order-item/:id response and the POST /accounts/:id/order-items request don't match except for a few attributes, order item creation is then designed to opimistically build an OrderItem instance based on the attributes inferred from the POST body. MásMóvil's API doesn't return the whole resource as one would expect with a REST API. That is why OrderItem's create input data structure won't directly match an OrderItem attributes.
The minimum structure is presented as the variable sample-order-item-post-request:
from pymasmovil.models.order_items.py import OrderItem
order_item_data = {
'lineInfo': [
{
'name': 'Antonio',
'surname': 'Garcia',
'phoneNumber': '616010101',
'documentType': 'NIF',
'iccid_donante': '8934046318031035245',
'iccid': '8934046318031035250',
}
]
}
order_item = OrderItem.create(session, order_item_data)
Development
Python version
We use Pyenv to fix the Python version and the virtualenv to develop the package.
You need to:
- Install and configure
pyenv - Install and configure
pyenv-virtualenv - Install the required Python version:
$ pyenv install 3.8.2
- Create the virtualenv:
$ pyenv virtualenv 3.8.2 pymasmovil
Python packages requirements
Install the Python packages in the virtual environment:
$ pyenv exec pip install -r requirements.txt
Formatting
We use Pre-commit to execute Black as formatter before commiting.
Install pre-commit configuration (found in file .pre-commit-config.yaml)
$ pre-commit install
After this, any time we apply a commit black will run with the modified files within the commit.
We can also execute black at any moment, choosing a file or a path to format all the files in there:
$ black .
All done! ✨ 🍰 ✨
24 files left unchanged.
Releasing
Update CHANGELOG.md following this steps:
- Add any entries missing from merged merge requests.
- Duplicate the
[Unreleased]header. - Replace the second
Unreleasedwith a version number followed by the current date. Copy the exact format from previous releases.
Then, you can release and publish the package to PyPi:
- Update the
VERSIONvar insetup.pymatching the version you specified in the CHANGELOG. - Open a merge request with these changes for the team to approve
- Merge it, add a git tag on that merge commit and push it.
- Once the pipeline has successfully passed, go approve the
publishstep.
License
TBD
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pymasmovil-0.0.30.tar.gz.
File metadata
- Download URL: pymasmovil-0.0.30.tar.gz
- Upload date:
- Size: 14.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.8.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e94f5e84c83e43d930d819c49a2353dc3f08d4b88ba3fa27937576b328c3b341
|
|
| MD5 |
200362a2940125851bb3d94aa1ec8d11
|
|
| BLAKE2b-256 |
8d2dd551b2b86e0968786d09c640f919e7b1b8d9d0497a9abaf611dccc07ca52
|
File details
Details for the file pymasmovil-0.0.30-py2.py3-none-any.whl.
File metadata
- Download URL: pymasmovil-0.0.30-py2.py3-none-any.whl
- Upload date:
- Size: 15.6 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.8.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
41136eae4954b18003278e12bce42b9b31f22f3c13bee58b7d7b6f1f482ca672
|
|
| MD5 |
6bf3ecd402a25364c1520425055516b6
|
|
| BLAKE2b-256 |
e73904cb4cd0de798fe5b530fcf8e54bb49d42488919bd6ba9eed8775b4d3ca4
|