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

myadmin-geotab-api-v2

v0.3.2

Published

Unofficial nodejs client for myadmin.geotab.com https://myadmin.geotab.com/sdk#/api-reference

Downloads

1

Readme

myadmin-geotab-api

Unofficial nodejs client for myadmin.geotab.com https://myadmin.geotab.com/sdk#/api-reference

Installation

Using npm:

$ npm i https://github.com/DavidSabine/myadmin-geotab-api.git

Getting Started

In Node.js:

The order of operations is:

  1. Require myadmin-geotab-api in your code.

    const MyAdminAPI = require('myadmin-geotab-api')
  2. Create an instance of the class object:

    const myAPI = new MyAdminAPI({<authentication parameters here>})
  3. Tell that new instance to authenticate with GeoTab's server. This returns an object containing credentials, sessionId, apiKey, etc.

    myAPI.authenticate()
  4. Then use myAPI.call() to perform actions against GeoTab's service. The return values will vary depending which method name you send to GeoTab's service:

    myAPI.call(<a method name>, {<parameters related to that method>})

Examples:

Using Async/Await Promises

const MyAdminAPI = require('myadmin-geotab-api');

(async function main() {
	const username = 'your username'
	const password = 'your password'
	const testServerUrl = 'https://myadminapitest.geotab.com/v2/MyAdminApi.ashx'

	const api = new MyAdminAPI({
		username,
		password,
		testServerUrl // or omit to use prod
	})
	
	// Call authenticate method:<Promise>
	const authData = await api.authenticate()

	// get list of countries
	const countriesList = await api.call('GetCountries', {})

	console.log(countriesList)
})()

Using Promises then catch

const MyAdminAPI = require('myadmin-geotab-api')

(function main() {
	const username = process.env.GEOTAB_USERNAME
	const password = process.env.GEOTAB_PASSWORD

	const api = new MyAdminAPI({
		username,
		password,
	})

	api
		.authenticate()
		.then(() =>
			api.call('GetCountries', {})
		)
		.then((countriesList) => {
			console.log(countriesList)
		})
		.catch((err) => console.error(err))
})()

End note for contributors

Testing has been performed on node v14.

Notes for users of previous version: <=0.1.2

New method names are available, old method names still supported

We felt it redundant to use 'Async' in the function name. New method names are:

.authenticate()
.call()

The old function names are still supported. You should not have to change any of your code.

.authenticateAsync()
.callAsync()

Improved error handling for post() method

This may break your previous code. And note that post() is used by callAsync().

Previously, if something went wrong during the HTTP call to GeoTab's service, post() (and thus callAsync()) would throw an exception.

The new implementation differentiates between internal and intended exceptions. (See notes on this page, https://mswjs.io/docs/recipes/mocking-error-responses.) As per general guidance, the new implementation treats an error response (from the fetch promise) as an actual response not an exception.

If you implement call() or post() incorrectly, an exception will occur. But if you implement those methods correctly and something goes wrong during the HTTP call to GeoTab's server, you should now expect a JSON response with an error message. The JSON response looks like this:

{
	result: {
		error: {
			code: an error code,
			message: an error message,
			name: a name of error, example: 'MissingMethodException'
		}
	}
}

Examples:

Receive error message from GeoTab's server

const MyAdminAPI = require('myadmin-geotab-api')

(() => {
	const username = process.env.GEOTAB_USERNAME
	const password = process.env.GEOTAB_PASSWORD

	const api = new MyAdminAPI({
		username,
		password,
		uri: 'https://myadminapitest.geotab.com/v2/MyAdminApi.ashx'
	})

	api
		.authenticate()
		.then((result) =>
			api.call('Wrong Method', { 'wrong': 'parameter' })
		)
		.then((result) => {
			// The error message from GeoTab server is in the result
			console.log(result)
		})
		.catch((err) => console.error(err))
})()

Catch error in your code

const MyAdminAPI = require('myadmin-geotab-api')

(() => {
	const username = process.env.GEOTAB_USERNAME
	const password = process.env.GEOTAB_PASSWORD

	const api = new MyAdminAPI({
		username,
		password,
		uri: 'https://myadminapitest.geotab.com/v2/MyAdminApi.ashx'
	})

	api
		.authenticate()
		.then((result) =>
			api.WRONG('you did something wrong')
		)
		.then((result) => {
			// Error occured before http fetch could happen
			// so, no result is available
			console.log(result)
		})
		.catch((err) => {
			// thrown error is available here
			console.error(err)
		})
})()