github.com/iron-io/functions@v0.0.0-20180820112432-d59d7d1c40b2/examples/twitter/README.md (about)

     1  # Twitter Function Image
     2  
     3  This function exemplifies an authentication in Twitter API and get latest tweets of an account.
     4  
     5  ## Requirements
     6  
     7  - IronFunctions API
     8  - 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).
     9  
    10  ## Development
    11  
    12  ### Building image locally
    13  
    14  ```
    15  # SET BELOW TO YOUR DOCKER HUB USERNAME
    16  USERNAME=YOUR_DOCKER_HUB_USERNAME
    17  
    18  # build it
    19  ./build.sh
    20  ```
    21  
    22  ### Publishing to DockerHub
    23  
    24  ```
    25  # tagging
    26  docker run --rm -v "$PWD":/app treeder/bump patch
    27  docker tag $USERNAME/func-twitter:latest $USERNAME/func-twitter:`cat VERSION`
    28  
    29  # pushing to docker hub
    30  docker push $USERNAME/func-twitter
    31  ```
    32  
    33  ### Testing image
    34  
    35  ```
    36  ./test.sh
    37  ```
    38  
    39  ## Running it on IronFunctions
    40  
    41  ### Let's define some environment variables
    42  
    43  ```
    44  # Set your Function server address
    45  # Eg. 127.0.0.1:8080
    46  FUNCAPI=YOUR_FUNCTIONS_ADDRESS
    47  
    48  CUSTOMER_KEY="XXXXXX"
    49  CUSTOMER_SECRET="XXXXXX"
    50  ACCESS_TOKEN="XXXXXX"
    51  ACCESS_SECRET="XXXXXX"
    52  ```
    53  
    54  ### Running with IronFunctions
    55  
    56  With this command we are going to create an application with name `twitter`.
    57  
    58  ```
    59  curl -X POST --data '{
    60      "app": {
    61          "name": "twitter",
    62          "config": { 
    63              "CUSTOMER_KEY": "'$CUSTOMER_KEY'",
    64              "CUSTOMER_SECRET": "'$CUSTOMER_SECRET'", 
    65              "ACCESS_TOKEN": "'$ACCESS_TOKEN'",
    66              "ACCESS_SECRET": "'$ACCESS_SECRET'"
    67          }
    68      }
    69  }' http://$FUNCAPI/v1/apps
    70  ```
    71  
    72  Now, we can create our route
    73  
    74  ```
    75  curl -X POST --data '{
    76      "route": {
    77          "image": "'$USERNAME'/func-twitter",
    78          "path": "/tweets",
    79      }
    80  }' http://$FUNCAPI/v1/apps/twitter/routes
    81  ```
    82  
    83  #### Testing function
    84  
    85  Now that we created our IronFunction route, let's test our new route
    86  
    87  ```
    88  curl -X POST --data '{"username": "getiron"}' http://$FUNCAPI/r/twitter/tweets
    89  ```