Skip to main content

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:

  1. Add any entries missing from merged merge requests.
  2. Duplicate the [Unreleased] header.
  3. Replace the second Unreleased with 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:

  1. Update the VERSION var in setup.py matching the version you specified in the CHANGELOG.
  2. Open a merge request with these changes for the team to approve
  3. Merge it, add a git tag on that merge commit and push it.
  4. Once the pipeline has successfully passed, go approve the publish step.

License

TBD

Metadata

Release files for pymasmovil 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pymasmovil 0.1.0
File Size Uploaded
pymasmovil-0.1.0.tar.gz 15.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pymasmovil 0.1.0
File Interpreter ABI Platform
pymasmovil-0.1.0-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 32.9 kB

Release files / pymasmovil-0.1.0.tar.gz

Download URL pymasmovil-0.1.0.tar.gz
Size 15.8 kB
Tags Source
SHA-256 checksum
How to use checksums
489a2e494f3b966e2a3e5ebe8e39095844c37a4ab851e622fa00fa15ffe593d0
BLAKE2b-256 checksum
How to use checksums
54a3fda453eafc52dc44fede065f2ef51baff51ce5d0cbdaa78c1ac04bccf1c0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.8.20

Release files / pymasmovil-0.1.0-py2.py3-none-any.whl

Download URL pymasmovil-0.1.0-py2.py3-none-any.whl
Size 17.1 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
976736a76ed3f012da21ea8cc3aee702183c80f5b987253edfb9c2e7fc27bf48
BLAKE2b-256 checksum
How to use checksums
275388aa302a69ff72331ecd706334a76fc8d4d1f547c46c070034f225ffc000
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.8.20

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

0.0.30

2 release files

0.0.29

2 release files

0.0.28

2 release files

0.0.26

2 release files

0.0.24

2 release files

0.0.23

2 release files

0.0.21

2 release files

0.0.20

2 release files

0.0.19

2 release files

0.0.17

2 release files

0.0.16

2 release files

0.0.13

2 release files

0.0.12

2 release files

0.0.11

2 release files

0.0.10

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page