Giter Site home page Giter Site logo

uz-booking-client's Introduction

NPM version NPM downloads MIT License Build Status

uz-booking-client

Unofficial uz booking API client for Node.js. https://booking.uz.gov.ua/en/

Installation

Using npm:

$ npm i uz-booking-client

Note: add --save if you are using npm < 5.0.0

In Node.js:

import Client from "uz-booking-client"
//  or
const Client = require("uz-booking-client")

Usage

/*
   Data can be retrieved from the API either using callbacks (as in versions < 1.0)
   or using a new promise-based API. The promise-based API returns the raw Axios
   request promise.
 */
  import Client from "uz-booking-client"

  const uzClient = new Client.ApiV3("en")
  const phoneNumber = await askQuestion('Your phone number: ')

  await uzClient.Auth.sendSms(phoneNumber)

  const code = await askQuestion('Code from SMS: ')

  await uzClient.Auth.login(code)

  const ticketsDate = moment().add(10, 'days')

  const departureStations = await uzClient.Station.find('Київ')
  const departureStationId = departureStations[0].id

  const targetStations = await uzClient.Station.find('Львів')
  const targetStationId = targetStations[0].id

  const trains = await uzClient.Train.find(
    departureStationId,
    targetStationId,
    ticketsDate.format('YYYY-MM-DD'),
  )

  const tripId = trains[0].id
  const wagonType = trains[0].train.wagon_classes[0].id

  const wagons = await uzClient.Wagon.list(tripId, wagonType)

  console.dir(wagons, { depth: 20, colors: true })

  // [
  //     {
  //         "id": "eyJpdiI6IlZZd1JoeExwYVFadWdOb2JUbEo3eWc9PSIsInZhbHVlIjoiWFRaWUJPNjJkVmw1OUZRcHlMdWtPeUtjZUQrUUE5djdyejF4N3lnUEllVmJOTFVRZWgzelFEN1lFR2VsWmpDSkM0SCtVQnZOcFpIQ1NET0FNOUtNMlFlSjhEbjRNMTFSOEd5UVluZU5sMmgzZTdOeU9yZzJ6cWF1VGlnNEpadjgiLCJtYWMiOiJlODlkYTM5ZTE1OTRjMDgxMDhlNDBmN2M4NDcyMDYxMDJmYjUyNjY1Mjk3YTk1NTQ4ZWY0YzhjMDA1MDRjZjlhIiwidGFnIjoiIn0=",
  //         "number": "6",
  //         "mockup_name": "Вагон типу СВ на 20 місць з нижніми місцями",
  //         "seats": [
  //             1,
  //             2,
  //             5,
  //             6,
  //             9,
  //             10,
  //             11,
  //             12,
  //             13,
  //             14,
  //             15,
  //             16,
  //             17,
  //             18,
  //             19,
  //             20
  //         ],
  //         "free_seats_top": 0,
  //         "free_seats_lower": 16,
  //         "price": 164938,
  //         "air_conditioner": true,
  //         "services": [
  //             {
  //                 "id": "drinks",
  //                 "title": "Напій",
  //                 "details": {
  //                     "photo": null,
  //                     "content": [
  //                         {
  //                             "title": "На вибір:",
  //                             "description": "Класичний чай, розчинна кава або мінеральна вода 0,5 л.\n"
  //                         }
  //                     ]
  //                 },
  //                 "price": 1000,
  //                 "select_type": "units",
  //                 "select_units_max": 3
  //             },
  //             {
  //                 "id": "tea",
  //                 "title": "Авторський чай",
  //                 "details": {
  //                     "photo": "https://app.uz.gov.ua/img/api/services/tea.jpg",
  //                     "content": [
  //                         {
  //                             "title": "На вибір:",
  //                             "description": "Карпатський трав’яний чай, подільський чай з м’ятою або поліський чай з чебрецем\n"
  //                         }
  //                     ]
  //                 },
  //                 "price": 1500,
  //                 "select_type": "checkbox",
  //                 "select_units_max": null
  //             },
  //             {
  //                 "id": "drip_coffee",
  //                 "title": "Дріп кава",
  //                 "details": {
  //                     "photo": "https://app.uz.gov.ua/img/api/services/drip_coffee.jpg",
  //                     "content": [
  //                         {
  //                             "title": "Арабіка з Бразилії:",
  //                             "description": "Натуральна мелена кава в пакетиках для зручного заварювання.\n"
  //                         }
  //                     ]
  //                 },
  //                 "price": 2500,
  //                 "select_type": "checkbox",
  //                 "select_units_max": null
  //             },
}

uz-booking-client's People

Contributors

dmytrys avatar

Stargazers

 avatar  avatar

uz-booking-client's Issues

Error when using example code

Hello,

I have an issue when trying your example code from README.

I receive this
2021-02-15 17_57_50-

when doing .Train.find although the .Station.find call works OK.

Do you know why this happens?

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.