Skip to content
This repository has been archived by the owner on Oct 6, 2022. It is now read-only.

Commit

Permalink
Merge branch 'master' into topic/fisher/APF-2667-Discovery
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanrfisher1 authored Dec 3, 2019
2 parents a368efc + 46c9a46 commit 95ea8fc
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 14 deletions.
30 changes: 17 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

This serves as a guide for writing connectors for the Mobile Flows. A connector is an adapter with two responsibilities:

* Based on object requests, render objects. This would typically be achieved by accessing an external backend system. The object is a JSON structure that allows a client to display something meaningful to the user. The object also includes references to actions the user can take, relevant to the context of the object. Note that the Weather connector in the [samples section](samples/node) uses Card, a type of oject as defined here : https://github.com/vmwaresamples/card-connectors-guide/wiki/Card-Responses
* Based on object requests, render objects. This would typically be achieved by accessing an external backend system. The object is a JSON structure that allows a client to display something meaningful to the user. The object also includes references to actions the user can take, relevant to the context of the object. Note that the Weather connector in the [samples section](samples/node) uses Card, a type of oject as defined here : https://github.com/vmware-samples/card-connectors-guide/wiki/Card-Responses
* Provide endpoints for all actions advertised in the object.

All communication with a connector is over HTTPS. A connector can be written in any language that allows the developer to create HTTP endpoints.
Expand All @@ -15,24 +15,28 @@ The Weather Connector accesses a fictitious crowd-sourced weather service to pro

A client requests a weather card and the following request is forwarded to the connector:
```
$ curl -H "Authorization: Bearer abcdef" \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-H "X-Routing-Prefix: /connectors/weather/" \
-X POST -d '{"tokens":{"zip":["30360"]}}' \
https://weather-connector.acme.com/cards/requests
$ curl -H "Authorization: Bearer mobileflows-token" \
-H "X-Connector-Authorization: Bearer backend-token" \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-H "X-Routing-Prefix: /connectors/weather/" \
-X POST \
-d '{"tokens":{"zip":["30360"]}}' \
https://weather-connector.acme.com/cards/requests
```
The card includes current weather conditions for ZIP code 30360, as well as an action to report the current temperature. If the user chooses that action, the following request will be forwarded to the connector:

```
$ curl -H "Authorization: Bearer abcdef" \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Accept: application/json" \
-X POST -d "zip=30360&temperature=78" \
https://weather-connector.acme.com/reports
$ curl -H "Authorization: Bearer mobileflows-token" \
-H "X-Connector-Authorization: Bearer backend-token" \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Accept: application/json" \
-X POST \
-d "zip=30360&temperature=78" \
https://weather-connector.acme.com/reports
```
A stubbed service based on the above can be found in the [samples section](samples/node) of this project.

## Further reading

For a detailed specification, please see the [wiki](https://github.com/vmwaresamples/card-connectors-guide/wiki).
For a detailed specification, please see the [wiki](https://github.com/vmware-samples/card-connectors-guide/wiki).
1 change: 1 addition & 0 deletions samples/node/Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: npm start -- --port=$PORT
2 changes: 1 addition & 1 deletion samples/node/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ $ docker run --rm -d -p 3000:3000 --name weather-connector weather-connector --

## Testing the connector

Access [discovery](https://github.com/vmwaresamples/card-connectors-guide/wiki/Discovery), request cards, then report actual weather:
Access [discovery](https://github.com/vmware-samples/card-connectors-guide/wiki/Discovery), request cards, then report actual weather:
```
$ curl http://localhost:3000
```
Expand Down
39 changes: 39 additions & 0 deletions samples/node/routes/discovery.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,45 @@ exports.root = function (req, res) {
const body = {
image: {href: `${base}/images/connector.png`},
test_auth: {href: `${base}/test-auth`},
config: {
foo: {
default: 'bar',
type: 'STRING',
label: {
'en-US': 'Foo',
'es-ES': 'Foo'
},
description: {
'en-US': 'This ...',
'es-ES': 'Este ...'
},
validators: [
{
type: 'required',
description: {
'en-US': 'Foo is required',
'es-ES': '...'
}
},
{
type: 'regex',
value: '^\\w+$',
description: {
'en-US': 'Foo must be only letters and number',
'es-ES': '...'
}
},
{
type: 'max_length',
value: '10',
description: {
'en-US': 'Foo must not be more than 10 characters',
'es-ES': '...'
}
}
]
}
},
actions: {
clear: {
url: {
Expand Down
1 change: 1 addition & 0 deletions samples/node/routes/weather.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const uuidV4 = require('uuid/v4');
const sha1 = require('sha1');

exports.requestCards = function(req, res) {
console.log('cards called: ', req.body);
let tokenZip = (req.body.tokens && req.body.tokens.zip) ? req.body.tokens.zip : null;
let configZip = (req.body.config && req.body.config.defaultZip) ? [req.body.config.defaultZip] : null;

Expand Down

0 comments on commit 95ea8fc

Please sign in to comment.