Package: pymasmovil
Más Móvil Python API clientThis Python API client provides access to Más Móvil's B2B REST API.InstallationRequirementsPython 3.8+UsageLoginTo 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_BASEURLmust point to the MásMóvili's API environment, either testing or production. Pymasmovil will only append API routes to it like/v0/accountsto perform requests. In the case of testing, check with them as this surely changes per customer.MM_USERandMM_PASSWORDmust be replaced with your actual user credentials, andMM_DOMAINmust point to either "test" or "login" depending on which MM environment need to be called (test/production).Session creationThe login is done when we create a session using theSession.createmethod:frompymasmovil.models.sessionimportSessionsession=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 theSessioninstance has to be passed in to other all other objects methods.Accountfrompymasmovil.models.accountimportAccountaccount_id='0017E000017pEo3QAE'account=Account.get(session,account_id)To create a new account we need to useAccount.createpassing the account data as keyword arguments. TheAccountattributes 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, buildingPortalNo attribute is mandatory for the client leaving parameter validation to the API.frompymasmovil.models.accountimportAccountaccount=Account.create(session,town='Barcelona',surname='Garcia',phone='616010101')OrderItemOrder items can be accessed the same way as accounts:frompymasmovil.models.order_items.pyimportOrderItemorder_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.SinceGET /order-item/:idresponse and thePOST /accounts/:id/order-itemsrequest don't match except for a few attributes, order item creation is then designed to opimistically build anOrderIteminstance 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 whyOrderItem'screateinput data structure won't directly match anOrderItemattributes.The minimum structure is presented as the variablesample-order-item-post-request:frompymasmovil.models.order_items.pyimportOrderItemorder_item_data={'lineInfo':[{'name':'Antonio','surname':'Garcia','phoneNumber':'616010101','documentType':'NIF','iccid_donante':'8934046318031035245','iccid':'8934046318031035250',}]}order_item=OrderItem.create(session,order_item_data)DevelopmentPython versionWe usePyenvto fix the Python version and the virtualenv to develop the package.You need to:Install and configurepyenvInstall and configurepyenv-virtualenvInstall the required Python version:$ pyenv install 3.8.2Create the virtualenv:$ pyenv virtualenv 3.8.2 pymasmovilPython packages requirementsInstall the Python packages in the virtual environment:$ pyenv exec pip install -r requirements.txtFormattingWe usePre-committo executeBlackas formatter before commiting.Install pre-commit configuration (found in file.pre-commit-config.yaml)$ pre-commit installAfter 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.ReleasingUpdate CHANGELOG.md following this steps:Add any entries missing from merged merge requests.Duplicate the[Unreleased]header.Replace the secondUnreleasedwith 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 theVERSIONvar insetup.pymatching the version you specified in the CHANGELOG.Open a merge request with these changes for the team to approveMerge it, add a git tag on that merge commit and push it.Once the pipeline has successfully passed, go approve thepublishstep.LicenseTBD