Created
July 19, 2014 16:11
-
-
Save alekhinen/10b05cb8e1b996c578dc to your computer and use it in GitHub Desktop.
BlogController for Tumblr API (Ruby)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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