Coder Social home page Coder Social logo

spacetab-io / onelya-python-sdk Goto Github PK

View Code? Open in Web Editor NEW
7.0 5.0 2.0 230 KB

Python SDK to work with Onelya API (smarttravel).

Home Page: https://in.smarttravel.ru

License: MIT License

Python 99.94% HTML 0.06%
onelya railway sdk opensource mit-license we-are-not-waiting rzd ufs sdk-python

onelya-python-sdk's Introduction

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.

onelya-python-sdk's People

Contributors

roquie avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.