1.0.0 • Published 6 years ago

teksavvy-js v1.0.0

Weekly downloads
5
License
MIT
Repository
github
Last release
6 years ago

teksavvy-js

A JS wrapper for the Teksavvy API

Why?

Teksavvy is one of the few ISPs offering a public API that can be used to query usage data. However, no official documentation seems to exist online for it, making the use of the API a bit of a pain. This API wrapper seeks to solve the issue of having to chase scarce and user-contributed API documentation to build software on top of the Teksavvy API.

The main source of truth on the API at the moment is this short document found on DSLReport.

Getting started

To use this wrapper, you will need to generate an API key for your Teksavvy account. This can be done through the customer portal.

Wrapper setup

constructor(apiKey [, options = {}])

The apiKey needs to be supplied, omitting it will raise a MissingAPIKeyError and prevent any requests from being sent.

The options are described below:

OptionTypeDefaultDescription
rateLimitInteger30The number of requests per minute allowed by the wrapper. Set to 0 to disable rate limiting

Usage

The API methods will return Promises that can be handled however you want using the then and catch functions.

API methods

usageRecords([operators = {}])

See the Query Operators section for details on how to use the operators parameter.

Output format

{
  date: ...,
  download: {
    onPeak: ...,
    offPeak: ...,
  },
  upload: {
    onPeak: ...,
    offPeak: ...,
  },
}
KeyTypeDescription
datedatetimeDate corresponding to the usage reading
download-Download usage information
onPeakdecimalBandwidth used in peak hours (in GB)
offPeakdecimalBandwidth used off peak hours (in GB)
upload-Upload usage information
onPeakdecimalSee prev.
offPeakdecimalSee prev.

usageSummaries([operators = {}])

See the Query Operators section for details on how to use the operators parameter.

{
  start: ...,
  end: ...,
  isCurrent: ...,
  download: {
    onPeak: ...,
    offPeak: ...,
  },
  upload: {
    onPeak: ...,
    offPeak: ...,
  },
}
KeyTypeDescription
startdatetimeStart of the usage reading period
enddatetimeEnd of the usage reading period
isCurrentbooleanFlags the current usage period
download-Download usage information
onPeakdecimalBandwidth used in peak hours (in GB)
offPeakdecimalBandwidth used off peak hours (in GB)
upload-Upload usage information
onPeakdecimalSee prev.
offPeakdecimalSee prev.

Rate limiting

The API wrapper includes a rate limiting feature which can be set using the rateLimit option. The rate limit is based on the number of requests per minute allowed to go through.

Any request that would exceed the preset per-minute request limit will throw a RateLimitExceededError and will not be sent nor queued.

By default, the rate limit is set to 30, as it is the limit set by the Teksavvy API documentation.

Query operators

The wrapper supports OData query operators that are accepted by the Teksavvy API. You can use them by passing an object to the usageSummaries and usageRecords functions.

KeyCorresponding OData operatorDescriptionValid values
top$topQueries the first N values of the setIntegers > 0
skip$skipSkips the first N values of the set, query starts at the N+1thIntegers > 0
count$inlinecountAdds a count of the returned items to the responseBoolean
select$selectNot supported yet-
orderby$orderbyBasic support*-
filter$filter(very) alpha supportArray of query objects
-$expandUnsupported by Teksavvy-
-$anyUnsupported by Teksavvy-
-$allUnsupported by Teksavvy-

$orderby support

Teksavvy doesn't seem to allow the use of $orderby with any useful keys, the wrapper allows the requests to be sent anyway while the situation is figured out.

Filter query objects

The current format of filter query parameters is an array of objects containing a key corresponding to one of the elements of the formatted result object, a reference value and a comparison operator compare.

[
  {
    key: ...,
    value: ...,
    compare: ...,
  },
  ...
]
1.0.0

6 years ago

0.0.2

7 years ago

0.0.1

7 years ago