Files
fn-serverless/examples/twitter/README.md
James Jeffrey c7f3066c75 Update references remove refs to treeder oracle funcy (#376)
* Remove lots of refs to iron and funcy oracle etc..

* more ref replacements

* Replacing more refs. Treeder

* Use Fn not FN
2017-09-29 16:22:15 -07:00

89 lines
1.8 KiB
Markdown

# Twitter Function Image
This function exemplifies an authentication in Twitter API and get latest tweets of an account.
## Requirements
- Fn API
- Configure a [Twitter App](https://apps.twitter.com/) and [configure Customer Access and Access Token](https://dev.twitter.com/oauth/overview/application-owner-access-tokens).
## Development
### Building image locally
```
# SET BELOW TO YOUR DOCKER HUB USERNAME
USERNAME=YOUR_DOCKER_HUB_USERNAME
# build it
./build.sh
```
### Publishing to DockerHub
```
# tagging
docker run --rm -v "$PWD":/app treeder/bump patch
docker tag $USERNAME/func-twitter:latest $USERNAME/func-twitter:`cat VERSION`
# pushing to docker hub
docker push $USERNAME/func-twitter
```
### Testing image
```
./test.sh
```
## Running it on Fn
### Let's define some environment variables
```
# Set your Function server address
# Eg. 127.0.0.1:8080
FUNCAPI=YOUR_FUNCTIONS_ADDRESS
CUSTOMER_KEY="XXXXXX"
CUSTOMER_SECRET="XXXXXX"
ACCESS_TOKEN="XXXXXX"
ACCESS_SECRET="XXXXXX"
```
### Running with Fn
With this command we are going to create an application with name `twitter`.
```
curl -X POST --data '{
"app": {
"name": "twitter",
"config": {
"CUSTOMER_KEY": "'$CUSTOMER_KEY'",
"CUSTOMER_SECRET": "'$CUSTOMER_SECRET'",
"ACCESS_TOKEN": "'$ACCESS_TOKEN'",
"ACCESS_SECRET": "'$ACCESS_SECRET'"
}
}
}' http://$FUNCAPI/v1/apps
```
Now, we can create our route
```
curl -X POST --data '{
"route": {
"image": "'$USERNAME'/func-twitter",
"path": "/tweets",
}
}' http://$FUNCAPI/v1/apps/twitter/routes
```
#### Testing function
Now that we created our Fn route, let's test our new route
```
curl -X POST --data '{"username": "getiron"}' http://$FUNCAPI/r/twitter/tweets
```