1.1.2 • Published 2 years ago

@liberatos/strava.js v1.1.2

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

strava.js

Simple and intuitive client for communication with strava.cz API.

Installation

You need Node and NPM (Node Package Manager)

npm install @liberatos/strava.js

How to start

Create new strava.js client

  const client = new Client(username, password, code, options)
  
  client.login((sessionId) => {
    console.log(`Logged in with sessionId: ${sessionId}`)
  })
ParameterTypeRequiredDescription
usernamestringYesStrava.cz credentials (username)
passwordstringYesStrava.cz credentials (password)
codenumberYesCode of canteen
optionsClientOptionsNoCustom client settings

ClientOptions

ParameterTypeDefaultDescription
refreshSessionbooleanfalseAutomatically renews the session if it expires
autoSavebooleanfalseSaves orders immediately after changing

Features

The strava.js client provides several methods for retrieving or modifying data. Most of them are asynchronous.

  • login(callback)
  • logout()
  • getOverpayment()
  • getOrders()
  • getDispensings()
  • getPayments()
  • getMessages()
  • changeOrder(orderId, mealId, state)
  • changeOrders(changes)
  • saveOrders(orders)

async login(callback): Promise

Calling the method is necessary before using other client functions that require user authorization. If the login is successful, it returns the sessionId. Similarly, the callback function will be called with the parameter of the retrieved sessionId, if specified.

async logout(): Promise

This method invalidates the sessionId, thus logging the user out. Returns void.

Authorization is required for use

async getOverpayment(): Promise

Returns the current overpayment on the user's account.

Authorization is required for use

async getOrders(): Promise<Order[]>

Returns all available user's orders and meals.

Authorization is required for use

async getDispensings(): Promise<Dispensing[]>

Returns available order dispensing history.

Authorization is required for use

async getPayments(): Promise<Payment[]>

Returns the payment history of the user's account (top-ups).

Authorization is required for use

async getMessages(): Promise<Message[]>

Returns messages that have been sent to the user. Currently only general information about the message can be retrieved, content is not supported for now.

Authorization is required for use

async changeOrder(orderId, mealId, state): Promise<Order[]>

Returns a modified array of orders as requested. The method has validation implemented, so you can't have two types of meals logged per order. If you try to log two meals, the originally logged meal will be checked out. If you can no longer change the status of the order, you will receive an error. Only one order can be edited at a time using this method.

If autoSave is enabled, the change will be automatically saved on the server - otherwise you have to save it manually.

  const modified = await client.changeOrder(1672500000, 1, true)

Authorization is required for use

async changeOrders(changes): Promise<Order[]>

This method is identical to the previous one, but you can change multiple orders at once.

  const changes: ChangeMealOptions[] = [
    { orderId: 1672500000, mealId: 1, state: false },
    { orderId: 1662430000, mealId: 2, state: false },
    { orderId: 1663800000, mealId: 1, state: true }
  ]

  const modified = await client.changeOrders(changes)

Authorization is required for use

async saveOrders(orders): Promise

The method saves all orders that are passed as a parameter. It is necessary to save all available orders as well as those that have not been changed.

I recommend using the autoSave function, which means you won't have to use this feature at all.

  const modified = await client.changeOrder(1672500000, 1, true)
  await client.saveChanges(modified)

Authorization is required for use

Typing

An overview of the interfaces used by the package.

Order

ParameterTypeDescription
idnumberCreated from unix timestamp
dateDateDate of order
mealsArray<Meal>Meals available in order

Meal

ParameterTypeDescription
idnumber
namestring
descriptionstring
selectedbooleanIs meal selected within the order
canChangebooleanIf the selected state can be changed
allergensArray<string> \| null
detailsMealDetailsDetail infomations

MealDetails

ParameterTypeDescription
priceFinancialAmount \| null
endOfCheckInDate \| null
endOfCheckOutDate \| null

FinancialAmount

ParameterTypeDescription
amountnumber
currencystring

Dispensing

ParameterTypeDescription
descriptionstring
dateDate
pickupTimenumber \| nullTime when the meal was picked up
pickedboolean
mealVoucherbooleanIf the voucher was used to pick up the meal

Payment

ParameterTypeDescription
descriptionstring
dateDate
detailsFinancialAmount

Message

ParameterTypeDescription
subjectstring
recipientstringMost often email
dateDate

ChangeMealOptions

ParameterTypeDescription
orderIdnumber
mealIdnumber
stateboolean

Authors