Code Examples

curl example

Access the service using curl at the command line.


Github Hubot example

Access the service using Github's Hubot


Post to Tumblr example

CapGun "Dog Food's" its own API into a Tumblr at http://tumblr.capgun.io/ We started to do this even before CapGun was opened to the public to be sure we were building the service towards a real working goal.

This example is how you can do the same to automate posting captures of URLs from your Twitter feed into your Tumblr. This requires obtaining an OAuth token and secret for the Tumblr.com API allowing an external application to post to your Tumblr. Tumblr's OAuth page is at http://www.tumblr.com/oauth/apps You will also have to create a Twitter app in the context of their developer panel https://dev.twitter.com/apps and obtain OAuth credentials for that app as well to gather URLs that are posted in your Twitter feed.

Generate OAuth keys for Tumblr and Twitter APIs

We've built a micro Ruby Gem, an example is below, to make it easier to generate your Tumblr API OAuth keys.

# a micro Ruby Gem to generate Tumblr API OAuth keys https://gist.github.com/4577106
mkdir /path/to/some/new/dir
cd /path/to/some/new/dir
wget https://gist.github.com/raw/4577106/6bc9befedcd5238ce9f2ee562cace666dece460c/Gemfile
bundle install
bundle exec generate-token

Next, go through the steps to configure a Twitter application in their developer panel and obtain the OAuth credentials for that application. https://dev.twitter.com/apps and https://dev.twitter.com/apps/new

Create script to watch Twitter for URLs and post them to Capgun.io service

Now, we'll build a script that will watch your Twitter timeline picking off new URLs posted by people you follow. When the watcher sees a new URL it will create a CapGun job to capture that URL. After that, we'll build a Sinatra application that will respond to CapGun's post receive hook when jobs are completed and submit the images in the job to posted to the Tumblr.

If you are lazy you can use our watcher scripts.

Create a Sinatra application to catch Capgin.io web hook callbacks and post the results to Tumblr

We've created a simple Sinatra app that you can use outright or as an example to trigger capgun capture images to the Tumblr API.