An open API service indexing awesome lists of open source software.

https://github.com/andmos/bikesharefunction

OpenFaaS function for BikeshareClient
https://github.com/andmos/bikesharefunction

bikeshare dotnet functions gbfs openfaas serverless

Last synced: 5 months ago
JSON representation

OpenFaaS function for BikeshareClient

Awesome Lists containing this project

README

          

BikeshareFunction
===

[OpenFaaS](https://www.openfaas.com/) function for [BikeshareClient](https://github.com/andmos/BikeshareClient) access.
Provides a simple serverless [GBFS](https://github.com/NABSA/gbfs) status system.

`gbfs-systems-function` parses the [GBFS Systems CSV](https://raw.githubusercontent.com/NABSA/gbfs/master/systems.csv) to JSON, providing API for systems overview.

```bash
faas-cli template pull https://github.com/burtonr/csharp-kestrel-template
faas-cli build -f bikeshare-function.yml

faas-cli deploy -f bikeshare-function.yml

echo "skansen" |faas-cli invoke bikeshare-function |jq
# {
# "Name: "skansen",
# "BikesAvailable": 18,
# "LocksAvailable": 0
# }

echo |faas-cli invoke gbfs-systems-function |jq
#{
# "CountryCode": "US",
# "Name": "Sobi Long Beach",
# "Location": "Long Beach, NY",
# "Id": "sobi_long_beach",
# "Url": "http://sobilongbeach.com/",
# "GBFSFileUrl": "http://sobilongbeach.com/opendata/gbfs.json"
# }
```

Change GBFS system by updating the `GBFSAddress` variable:

```bash
faas-cli deploy -f bikeshare-function.yml --env=GBFSAddress=https://gbfs.urbansharing.com/oslobysykkel.no/gbfs.json update=true
echo "Diakonhjemmet" |faas-cli invoke bikeshare-function
# {
# "Name: "Diakonhjemmet",
# "BikesAvailable": 9,
# "LocksAvailable": 5
# }
```

This project also contains function to post from `bikeshare-function` to Slack. Add a new bot named `bikesharebot` to a Slack workspace, and update the variable under `bikeshare-slack-function:` in `bikeshare-function.yml` with the location of the [OpenFaaS gateway](https://github.com/openfaas/workshop/blob/master/lab4.md#call-one-function-from-another):

```yaml
environment:
gateway_hostname: http://gateway:8080/
```

Add the bot's OAUTH token to [OpenFaaS secrets](https://docs.openfaas.com/reference/secrets/):

```shell
faas-cli secret create bikebotslacktoken --from-file=slackbot-key.txt
```

and initialize the bot by trigging the function after deploy:

```shell
echo "init" |faas-cli invoke bikeshare-slack-function
# Bot initializing
```

Now simply ask the bot for a station:

```shell
andmos [8:40 PM]
@BikeshareBot Lerkendal
BikeshareBot APP [8:40 PM]
Lerkendal: :bike:: 17 :unlock:: 3
```

To run OpenFaaS, look at the guides for [Docker Swarm](https://docs.openfaas.com/deployment/docker-swarm/), [Kubernetes](https://docs.openfaas.com/deployment/kubernetes/) or [OpenShift](https://docs.openfaas.com/deployment/openshift/).

[![Build Status](https://github.com/andmos/bikesharefunction/workflows/Publish/badge.svg)](https://github.com/andmos/BikeshareFunction/actions?query=workflow%3APublish)

[![Dependabot Status](https://api.dependabot.com/badges/status?host=github&repo=andmos/BikeshareFunction)](https://dependabot.com)