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://api-grupomasmovil.cs86.force.com/cableOperadores/services/apexrest/api'
'MM_USER': 'user'
'MM_PASSWORD': 'pwd'
MM_USER
and MM_PASSWORD
must be replaced with your actual user credentials.
For the moment, MM_BASEURL
points to the testing environement.
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 Session
instance should be kept, as is a required paramether for other package functionalities. The reason is that each API call needs to know the session in which the user is logged.
Example (following the last code snippet):
Account usage
from pymasmovil.models.account import Account
account_id = 'example-account-id'
account = Account.get(session, account_id)
To create a new account we need to use Account.create
passing as key-word arguments with the new account information. The Account
attributes are listed bellow, corresponding with the parameters (as strings) that could be sent when creating a new account (except id
).
town, surname, stair, roadType, roadNumber, roadName, region, province, postalCode, phone, name, id, flat, email, door, donorCountry, documentType, documentNumber, corporateName, buildingPortal
No attribute is compulsary, and parameter validation is done by the API at present.
from pymasmovil.models.account import Account
account = Account.create(session, town='example-town', surname='sample-surname', phone='sample-phone')
Order-item usage
Order-items can be accessed the same way it's done with accounts:
from pymasmovil.models.order_items.py import OrderItem
order_item_id = 'example-order-item-Id'
order_item = OrderItem.get(session, order_item_id)
Concurrently, order-items can be created following the account creation example, but the structure of its attributes is a little more complicated. Since GET /order-item/:id response and the POST /order-item request don't match except for a few attributes, for the moment to create an order-item we require the minimum structure that the POST request can accept and that we can map to build an OrderItem instance.
The minimum structure is presented as the variable sample-order-item-post-request
:
from pymasmovil.models.order_items.py import OrderItem
sample-order-item-post-request = {
'lineInfo': [
{
'name': '',
'surname': '',
'phoneNumber': '',
'documentType': '',
'portabilityDate': '',
'iccid_donante': '',
'iccid': '',
}
]
}
order_item = OrderItem.create(session, sample-order-item-post-request)
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-virtualenvwrapper
- 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
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
Hashes for pymasmovil-0.0.1-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 47e6fbe9b31ea2b009202723f84fb903c36cf4964a556df041f955848c806f06 |
|
MD5 | 8a75b2f46c580c57ce02b16c82f0638c |
|
BLAKE2b-256 | c571ac0e1510f3af220ec64421d061650583ca9f7b2b2b28d9982ca33e722942 |