Skip to content

Instantly share code, notes, and snippets.

@alekhinen
Created July 19, 2014 16:11
Show Gist options
  • Save alekhinen/10b05cb8e1b996c578dc to your computer and use it in GitHub Desktop.
Save alekhinen/10b05cb8e1b996c578dc to your computer and use it in GitHub Desktop.
BlogController for Tumblr API (Ruby)
class BlogController < ApplicationController
def index
# Keys given from Tumblr API
@key = TUMBLR_KEY
@secret = TUMBLR_SECRET_KEY
@oauth_token = TUMBLR_OAUTH_TOKEN
@oauth_token_secret = TUMBLR_OAUTH_TOKEN_SECRET
# Sets the client that allows interfacing with Tumblr
@myClient = Tumblr::Client.new(
:consumer_key => @key,
:consumer_secret => @secret,
:oauth_token => @oauth_token,
:oauth_token_secret => @oauth_token_secret
)
@posts = @myClient.posts("YOURTUMBLR.tumblr.com")
@posts = Kaminari.paginate_array(@posts["posts"]).page(params[:page]).per(10)
# # Photography posts only (other types follow the same pattern)
# @photoPosts = @myClient.posts("YOURTUMBLR.tumblr.com",
# :limit => 5,
# :type => "photo")
# @photoPosts = @photoPosts["posts"]
respond_to do |format|
format.html # index.html.erb
format.json { render json: @posts }
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment