hsl-city-bikes
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -1,1 +0,13 @@ | ||
export {}; | ||
export interface IBikeRentalStation { | ||
stationId: string; | ||
name: string; | ||
bikesAvailable: number; | ||
spacesAvailable: number; | ||
lat: number; | ||
lon: number; | ||
allowDropoff: boolean; | ||
} | ||
export declare const graphqlApiUrl_set: (url: string) => string; | ||
export declare const graphqlApiUrl_get: () => string; | ||
export declare function fetchBikeRentalStations(): Promise<IBikeRentalStation[]>; | ||
export declare function fetchBikeRentalStations(stationId: string): Promise<IBikeRentalStation>; |
@@ -12,23 +12,48 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.fetchBikeRentalStations = exports.graphqlApiUrl_get = exports.graphqlApiUrl_set = void 0; | ||
global.fetch = require("node-fetch"); | ||
const graphql_request_1 = require("graphql-request"); | ||
function main() { | ||
let api = "https://api.digitransit.fi/routing/v1/routers/hsl/index/graphql"; | ||
exports.graphqlApiUrl_set = (url) => (api = url); | ||
exports.graphqlApiUrl_get = () => api; | ||
function fetchBikeRentalStations(stationId) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const endpoint = 'https://api.graph.cool/simple/v1/cixos23120m0n0173veiiwrjr'; | ||
const query = /* GraphQL */ ` | ||
query getMovie($title: String!) { | ||
Movie(title: $title) { | ||
releaseDate | ||
actors { | ||
name | ||
const query = `{ | ||
bikeRentalStation${stationId ? `(id:"${stationId}")` : "s"} { | ||
stationId | ||
name | ||
bikesAvailable | ||
spacesAvailable | ||
lat | ||
lon | ||
allowDropoff | ||
} | ||
}`; | ||
let res = yield graphql_request_1.request(api, query).catch(e => { | ||
return Promise.reject(e); | ||
}); | ||
if (stationId) { | ||
res = res.bikeRentalStation; | ||
} | ||
} | ||
} | ||
`; | ||
const variables = { | ||
title: 'Inception', | ||
}; | ||
const data = yield graphql_request_1.request(endpoint, query, variables); | ||
console.log(JSON.stringify(data, undefined, 2)); | ||
else { | ||
res = res.bikeRentalStations; | ||
} | ||
if (!res) { | ||
return Promise.reject("No bike rental stations found."); | ||
} | ||
return res; | ||
if (stationId) { | ||
return graphql_request_1.request(api, query) | ||
.then((data) => { | ||
return data.bikeRentalStation; | ||
}) | ||
.catch(e => Promise.reject(e)); | ||
} | ||
return graphql_request_1.request(api, query) | ||
.then((data) => { | ||
return data.bikeRentalStations; | ||
}) | ||
.catch(e => Promise.reject(e)); | ||
}); | ||
} | ||
main().catch((error) => console.error(error)); | ||
exports.fetchBikeRentalStations = fetchBikeRentalStations; |
{ | ||
"name": "hsl-city-bikes", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "NPM package for fetching data about city bike station in Helsinki.", | ||
@@ -13,2 +13,3 @@ "main": "dist/index.js", | ||
"postversion": "git push && git push --tags", | ||
"prepare": "npm run build", | ||
"prepublishOnly": "npm test && npm run lint", | ||
@@ -15,0 +16,0 @@ "preversion": "npm run lint", |
4995
71