Files
fn-serverless/examples/twitter
Travis Reeder 9cc12b4b12 Remove iron...
2017-05-18 18:59:34 +00:00
..
2016-11-01 13:15:27 -07:00
2017-05-18 18:59:34 +00:00
2017-05-18 18:59:34 +00:00
2017-05-18 18:59:34 +00:00
2016-11-01 13:15:27 -07:00
2017-05-15 11:00:15 -07:00
2017-05-18 18:59:34 +00:00
2017-05-18 18:59:34 +00:00
2016-11-01 13:15:27 -07:00

Twitter Function Image

This function exemplifies an authentication in Twitter API and get latest tweets of an account.

Requirements

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 Oracle Functions

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 Oracle Functions

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 Oracle Functions route, let's test our new route

curl -X POST --data '{"username": "getiron"}' http://$FUNCAPI/r/twitter/tweets