Comparing version 1.0.0 to 1.0.1
@@ -7,2 +7,2 @@ export * from './clients/cot-client'; | ||
export * from './types/temporal-page'; | ||
export * from './utils'; | ||
export * from './util'; |
@@ -9,3 +9,3 @@ "use strict"; | ||
__export(require("./clients/locations-client")); | ||
__export(require("./utils")); | ||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiQzovVXNlcnMvdGR1cG9udC9Xb3Jrc3BhY2VzL2NvdC1saWIvbGliLyIsInNvdXJjZXMiOlsiaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7QUFBQSwwQ0FBcUM7QUFDckMsOENBQXlDO0FBQ3pDLGdEQUEyQztBQUkzQyw2QkFBd0IifQ== | ||
__export(require("./util")); | ||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiQzovVXNlcnMvdGR1cG9udC9Xb3Jrc3BhY2VzL2NvdC1saWIvbGliLyIsInNvdXJjZXMiOlsiaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7QUFBQSwwQ0FBcUM7QUFDckMsOENBQXlDO0FBQ3pDLGdEQUEyQztBQUkzQyw0QkFBdUIifQ== |
{ | ||
"name": "cot-lib", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Easily consume the City of Things platform data", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -11,9 +11,35 @@ The City of Things client library will help you to connect to the City of Things backend. It uses the Web Linking RFC 5988 and interprets the Link header for you. This way you can let the library follow the next/prev/last pages for you. | ||
[TODO] including via Typescript of Javascript | ||
### Typescript | ||
This library is written in Typescript before being transpiled to Javascript, hence the type information is embedded. | ||
You start by creating a CotClient object. | ||
```ts | ||
import { CotClient, LocationsClient, SourcesClient, Util } from 'cot-lib'; | ||
let client = new CotClient('http://my-cot-backend.eu'); | ||
let hash = Util.encodeAsGeohash(31.123456,15.321654); | ||
``` | ||
### Javascript | ||
This library can also be used as a regular javascript library. | ||
```js | ||
var CotClient = require('cot-lib').CotClient; | ||
var Util = require('cot-lib').Util; | ||
var client = new CotClient('http://my-cot-backend.eu'); | ||
var hash = Util.encodeAsGeohash(31.123456,15.321654); | ||
``` | ||
or | ||
```js | ||
var cot = require('cot-lib'); | ||
var client = new cot.CotClient('http://my-cot-backend.eu'); | ||
var hash = cot.Util.encodeAsGeohash(31.123456,15.321654); | ||
``` | ||
### Creating a CotClient | ||
A **CotClient** object allows you to request the basic API functions. It needs a reference to the base url of the API. | ||
You start by creating a CotClient object. A **CotClient** object allows you to request the basic API functions. It needs a reference to the base url of the API. | ||
@@ -151,3 +177,3 @@ ```ts | ||
"name": "Car1" or ["Car1", "Car2"], | ||
"columns": ["timestamp","co2","temperature"] | ||
"columns": ["timestamp","co2","temperature"], | ||
"values": [ | ||
@@ -207,3 +233,3 @@ [1483201200, 430, 297.15], | ||
If you want to wait and only call a handler when all data has come in, use the `Utils.collectOne(...)` method on this Observable. More information on this method can be found at the end of this API section. | ||
If you want to wait and only call a handler when all data has come in, use the `Util.collectOne(...)` method on this Observable. More information on this method can be found at the end of this API section. | ||
@@ -224,3 +250,3 @@ *The arguments **from** and **to** are UNIX (UTC) timestamps.* | ||
If you want to wait and only call a handler when all data has come in, use the `Utils.collectOne(...)` method on this Observable. More information on this method can be found at the end of this API section. | ||
If you want to wait and only call a handler when all data has come in, use the `Util.collectOne(...)` method on this Observable. More information on this method can be found at the end of this API section. | ||
@@ -252,3 +278,3 @@ *The arguments **from** and **to** are UNIX (UTC) timestamps.* | ||
If you want to wait and only call a handler when all data has come in, use the `Utils.collectMany(...)` method on this Observable. More information on this method can be found at the end of this API section. | ||
If you want to wait and only call a handler when all data has come in, use the `Util.collectMany(...)` method on this Observable. More information on this method can be found at the end of this API section. | ||
@@ -274,11 +300,11 @@ *The arguments **from** and **to** are UNIX (UTC) timestamps.* | ||
If you want to wait and only call a handler when all data has come in, use the `Utils.collectMany(...)` method on this Observable. More information on this method can be found at the end of this API section. | ||
If you want to wait and only call a handler when all data has come in, use the `Util.collectMany(...)` method on this Observable. More information on this method can be found at the end of this API section. | ||
*The arguments **from** and **to** are UNIX (UTC) timestamps.* | ||
## Utils API | ||
## Util API | ||
The Utils class contains some static methods that can be helpful when working with the City of Things cilent library. | ||
The Util class contains some static methods that can be helpful when working with the City of Things cilent library. | ||
### Utils.timestampOf(year: *number*, month: *number*, day?: *number*, hours?: *number*, minutes?: *number*, seconds?: *number*, milliseconds?: *number*): *number* | ||
### Util.timestampOf(year: *number*, month: *number*, day?: *number*, hours?: *number*, minutes?: *number*, seconds?: *number*, milliseconds?: *number*): *number* | ||
Returns the unix (UTC) timestamp for the given date parameters. The arguments are considered to be in UTC time. | ||
@@ -296,3 +322,15 @@ | ||
### Utils.collectOne(observable: *Observable\<TemporalPageData>*, callback: *(data: TemporalPageData) => any*, error?: (error: Error) => any*): *void* | ||
### Util.encodeAsGoehash(lat: *number*, lng: *number*, precision: *number* = 9): *string* | ||
Encodes a latitude-longitude point as a geohash with the given precision. | ||
Argument | Description | ||
------------|----------------------------------------------- | ||
lat | Latitude of point | ||
lng | Longitude of point | ||
precision | Character length of geohash *(defaults to 9)* | ||
### Util.decodeFromGeohash(geohash: *string*): *{"latitude": number, "longitude": number}* | ||
Decode a given geohash as a latitude-longitude point. | ||
### Util.collectOne(observable: *Observable\<TemporalPageData>*, callback: *(data: TemporalPageData) => any*, error?: (error: Error) => any*): *void* | ||
This utility method will subscribe to an *Observable\<TemporalPageData>* and collect the results that are sent through on each update of the next handler. Once it is complete, the *callback* handler will be called with the complete collected data as an argument. An optional *error* handler is called with the Error object, if one occurs. | ||
@@ -303,8 +341,8 @@ | ||
```ts | ||
import { CotClient, Utils } from 'cot-lib'; | ||
import { CotClient, Util } from 'cot-lib'; | ||
testMethod() { | ||
let client = new CotClient('http://my-cot-endpoint.eu'); | ||
let from = Utils.timestampOf(2017, 3, 1, 0, 0, 0, 0); | ||
let to = Utils.timestampOf(2017, 4, 1, 0, 0, 0, 0); | ||
let from = Util.timestampOf(2017, 3, 1, 0, 0, 0, 0); | ||
let to = Util.timestampOf(2017, 4, 1, 0, 0, 0, 0); | ||
let observable = client.getDataIntervalIn('u15kk', 'bpost.cars', from, to); | ||
@@ -318,15 +356,4 @@ | ||
### Utils.encodeAsGoehash(lat: *number*, lng: *number*, precision: *number* = 9): *string* | ||
Encodes a latitude-longitude point as a geohash with the given precision. | ||
Argument | Description | ||
------------|----------------------------------------------- | ||
lat | Latitude of point | ||
lng | Longitude of point | ||
precision | Character length of geohash *(defaults to 9)* | ||
### Utils.decodeFromGeohash(geohash: *string*): *{"latitude": number, "longitude": number}* | ||
Decode a given geohash as a latitude-longitude point. | ||
### Utils.collectMany(observable: *Observable\<TemporalPageData>*, callback: *(data: TemporalPageData[]) => any*, error?: (error: Error) => any*): *void* | ||
### Util.collectMany(observable: *Observable\<TemporalPageData>*, callback: *(data: TemporalPageData[]) => any*, error?: (error: Error) => any*): *void* | ||
This utility method will subscribe to an *Observable\<TemporalPageData>* and collect the results that are sent through on each update of the next handler for each endpoint. It will send these updates as an array of *TemporalPageData* objects. Once it is complete, the *callback* handler will be called with the complete collected data as an argument, this is again an array of *TemporalPageData* objects, as many as there are registered sourceIds for a *SourcesClient* or geohashes for a *LocationsClient*. An optional *error* handler is called with the Error object, if one occurs. | ||
@@ -337,8 +364,8 @@ | ||
```ts | ||
import { SourcesClient, Utils } from 'cot-lib'; | ||
import { SourcesClient, Util } from 'cot-lib'; | ||
testMethod() { | ||
let sclient = new SourcesClient('http://my-cot-endpoint.eu', 'Car1', 'Car2', 'Car3', 'Car4'); | ||
let from = Utils.timestampOf(2017, 3, 1, 0, 0, 0, 0); | ||
let to = Utils.timestampOf(2017, 4, 1, 0, 0, 0, 0); | ||
let from = Util.timestampOf(2017, 3, 1, 0, 0, 0, 0); | ||
let to = Util.timestampOf(2017, 4, 1, 0, 0, 0, 0); | ||
let observable = sclient.getDataInterval(from, to); | ||
@@ -345,0 +372,0 @@ |
114670
42
1423
369