Skip to content

veilovv/onelya-python-sdk

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Onelya Python SDK master

This SDK is used to connect to the Onelya and use it methods(Railway and Aeroexpress) for a 3-d party API.

Installation

pip3 install onelya_sdk

Get started

To start you will need to have credentials for the Onelya.
Example of api initializing

from onelya_sdk import API

api = API('username', 'password', 'pos')

After that, include the wrappers for requests to Railway Reservation

from onelya_sdk.railway import *

Now you can use all the methods of the Onelya Railway.

If field type in docs represented as datetime, then you need to pass it as datetime object, not str

For example:

E.g Railway/Search for route pricing:

from datetime import datetime

date = datetime.now()
route_pricing = api.railway_search.route_pricing('2000000', '2078750', date)

Now the result will be an instance of RoutePricing

Request with wrappers

product_request = ProductRequest('AccidentAndLuggageLossAndDamage')
service_add_upsale_request = ServiceAddUpsaleRequest('Igs', [1389, 1390], product_request)
add_upsale = api.railway_reservation.add_upsale(51978, 52919, service_add_upsale_request)

Results

All methods, except the railway_reservation.return_amount, return instance of class that contains all fields as a class variables and json_data variable with response json

E.g. References for balances

api = API(self.username, self.password, self.pos)
balances = api.partner_balances()

balances.account_balances #array of AgentAccount

balances.account_balances[0].current_balance # 1 902 157,38
balances.account_balances[0].account_name # ???? ???? (??????????????)1

balances.account_balances[1].current_balance # 17 991 136,47
balances.account_balances[1].account_name # ?? ???? (????????)2

balances.json_data

{
  "AccountBalances": [
    {
      "CurrentBalance": "1 902 157,38",
      "AccountName": "???? ???? (??????????????)1"
    },
    {
      "CurrentBalance": "17 991 136,47",
      "AccountName": "?? ???? (????????)2"
    }
  ]
}

Handling errors

Every method returns an objects with result or raise an error fo OnelyaAPIError

Onelya contains all data about error as in docs

Additionally returns docs url for method which raised an error

E.g.

blank_as_html = api.railway_search.route_pricing(-1, -1, None)

OnelyaAPIError output

onelya_railway_sdk.exceptions.OnelyaAPIError: Code: 43
  Message: ???????????? ???????? ?????????(??) 'DepartureDate'
  MessageParams: {'DepartureDate': None}
  Docs: https://test.onelya.ru/ApiDocs/Api?apiId=Railway-V1-Search-RoutePricing

API Reference

To use any of methods, you have to create an instance of Onelya. Described here

Currently available methods:

Contact us.

If you have any issues or questions regarding the API or the SDK it self, you are welcome to create an issue, or You can write an Email to [email protected] or [email protected]

License.

SDK is released under the MIT License.

About

Python SDK to work with Onelya API (smarttravel).

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 99.9%
  • HTML 0.1%