npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

lecab-api

v0.0.1

Published

An API client for the LeCab cab service.

Downloads

3

Readme

An API client for LeCab

A TypeScript/Javascript API client for the LeCab API.

It features:

  • a simple yet exhaustive API mapping of the LeCab REST API
  • strong static typing checks using TypeScript for security

NOTE: This code is not generated by the openapi-generator/

Installation

The library is available using NPM or yarn:

$ npm install --save lecab-api
# or
$ yarn add lecab-api

Usage

Below is a sample test script, using the test API Key available on the official OpenAPI documentation:

import APIClient, { hasGPSCoordinate } from "lecab-api"
import { AxiosError } from "axios"

const sleep = (delay: number) =>
  new Promise((resolve) => setTimeout(resolve, delay))

async function main() {
  const lecab = new APIClient({
    subdomain: "testapi",
    apiKey: "89696335d20acc59d7060642ba312cc6",
  })

  console.log(`Checking server status`)
  const status = await lecab.server.status()
  console.log(`status: ${status.online ? "ONLINE" : "OFFLINE"}`)

  console.log(`Loading server config`)
  const config = await lecab.profiles.settings()
  console.log(`available services =`, config.services.join(", "))
  console.log(`accepted payments =`, config.payments.join(", "))

  const address = "22 rue du pont neuf 75001"
  console.log(`Searching for location: ${address}`)
  const { locations } = await lecab.locations.search({
    location: { address },
  })
  const filteredLocations = locations
    .filter((location) => location.type === "LEAF")
    .filter(hasGPSCoordinate)
  if (filteredLocations.length === 0) {
    throw new Error("Could not find location")
  }
  for (const location of filteredLocations) {
    console.log(
      ` - found location: ${location.address} (${location.type}) @(${location.latitude}, ${location.longitude})`,
    )
  }
  const location = filteredLocations[0]

  console.log(`Searching services available at this location`)
  const services = await lecab.services.available({
    location: {
      latitude: location.latitude,
      longitude: location.longitude,
    },
  })
  console.log(`services: ${services.services.join(", ")}`)

  console.log(`Estimating the booking (${services.services[0]})`)
  const estimation = await lecab.jobs.estimate({
    pickup: {
      latitude: location.latitude,
      longitude: location.longitude,
    },
    drop: {
      latitude: 48.8703743,
      longitude: 2.3160687,
    },
    service: services[0],
  })
  console.log(`reçu estimation #${estimation.estimate_id}`)
  console.log(`attente: ${estimation.delay}m`)
  console.log(
    `durée: entre ${estimation.duration_min}m et ${estimation.duration_max}m`,
  )
  console.log(`prix: ${estimation.price}€ (${estimation.price_net}HT)`)

  console.log(`Confirming the booking`)
  const booking = await lecab.jobs.confirm({
    estimate_id: estimation.estimate_id,
    contacts: {
      global: {
        firstname: "Aurélien",
        lastname: "Noce",
        phone: "0650228354",
      },
    },
    payment: {
      type: "CASH_AT_DROP",
    },
  })
  console.log(`Course N°${booking.number} (${booking.id}) confirmed`)

  await sleep(2000)

  console.log(`Refreshing course info`)
  let courseInfo = await lecab.jobs.detail({
    id: booking.id,
  })
  console.log(JSON.stringify(courseInfo, null, 2))

  await sleep(2000)

  console.log(`Refreshing course info`)
  courseInfo = await lecab.jobs.detail({
    id: booking.id,
  })
  console.log(JSON.stringify(courseInfo, null, 2))

  await sleep(2000)

  console.log(`Canceling the booking`)
  const cancelationStatus = await lecab.jobs.cancel({
    id: booking.id,
  })
  if (cancelationStatus.type === "CHARGE") {
    console.log(`Cancelation did cost ${cancelationStatus.charge}€`)
  } else {
    console.log(`Cancelation was FREE`)
  }
}

main().catch((error) => {
  const axiosError = error as AxiosError
  if (axiosError.response) {
    console.warn(JSON.stringify(error.response.data, null, 2))
  }
})

TODO

  • [ ] Add support for the oauth endpoint
  • [ ] Add detailled docs
  • [ ] Write some tests (?)