Skip to content

Instantly share code, notes, and snippets.

@pepetox
Created December 6, 2014 10:37
Show Gist options
  • Save pepetox/9c354668171a241b93af to your computer and use it in GitHub Desktop.
Save pepetox/9c354668171a241b93af to your computer and use it in GitHub Desktop.
Link rails with tumblr
1. go https://www.tumblr.com/oauth/apps and registry our app
2. go https://api.tumblr.com/console/calls/user/info to obtain the data to access the API. take note of customer_key, customer_secret, oauth token y token secret
gem ‘tumblr_client’
gem ‘simple_oauth’, ‘0.2.0’
<% @posts["posts"].each do |post| %>
<div class="col-xs-12 col-sm-6 col-md-4 col-lg-4">
<article class="post" data-animate="fade-in-bottom">
<h3 class="post-title"><%= link_to post["title"], post["post_url"] %></a></h3>
<p class="post-meta"><span class="meta-date"><%= distance_of_time_in_words(Time.now, post["date"]) %></span><span class="meta-by"><a href="#">Pepetox</a></span></p>
<p class="post-content">
<%= truncate(post["body"], :length => 380, :escape => false)%>
</p>
</article>
</div>
<% end %>
class PostController < ApplicationController
def index
# Keys given from Tumblr API
@key = "kldsafjañlsdkjafalñskdjf"
@secret = "lkdfjalñksdjfañlksdj"
@oauth_token = 'sfdaadsfaf'
@oauth_token_secret = 'asfdafdsadsafsdf'
# 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("yourblog.tumblr.com", :limit => 3)
#if kaminari pagination
#@posts = Kaminari.paginate_array(@posts["posts"]).page(params[:page]).per(10)
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