Ruby Hash and Tumblr API -


controller page, json output api
i'm trying display posts users tumblr account on view page using ruby. have never done api's before. i'm trying use hash tables. controller code such:

@posts = client.posts"zombieprocess1.tumblr.com" 

on view page using html have

<%=posts%> 

the response such

{"blog"=>{"title"=>"untitled", "name"=>"zombieprocess1", "total_posts"=>1, "posts"=>1, "url"=>"url", "updated"=>1478191052, "description"=>"", "is_nsfw"=>false, "ask"=>false, "ask_page_title"=>"ask me anything", "ask_anon"=>false, "followed"=>false, "can_send_fan_mail"=>true, "is_blocked_from_primary"=>false, "share_likes"=>true, "likes"=>1, "twitter_enabled"=>false, "twitter_send"=>false, "facebook_opengraph_enabled"=>"n", "tweet"=>"n", "facebook"=>"n", "followers"=>0, "primary"=>true, "admin"=>true, "messages"=>0, "queue"=>0, "drafts"=>0, "type"=>"public", "reply_conditions"=>3, "subscribed"=>false, "can_subscribe"=>false}, "posts"=>[{"blog_name"=>"zombieprocess1", "id"=>152689921093, "post_url"=>"url", "slug"=>"", "type"=>"photo", "date"=>"2016-11-03 16:37:32 gmt", "timestamp"=>1478191052, "state"=>"published", "format"=>"html", "reblog_key"=>"ncdqgtzw", "tags"=>[], "short_url"=>"url", "summary"=>"", "recommended_source"=>nil, "recommended_color"=>nil, "followed"=>false, "liked"=>true, "note_count"=>1, "caption"=>"", "reblog"=>{"tree_html"=>"", "comment"=>""}, "trail"=>[], "image_permalink"=>"url", "photos"=>[{"caption"=>"", "alt_sizes"=>[{"url"=>"url", "width"=>400, "height"=>544}, {"url"=>"url", "width"=>250, "height"=>340}, {"url"=>"url", "width"=>100, "height"=>136}, {"url"=>"url", "width"=>75, "height"=>75}], "original_size"=>{"url"=>"url", "width"=>400, "height"=>544}}], "can_like"=>false, "can_reblog"=>true, "can_send_in_message"=>true, "can_reply"=>true, "display_avatar"=>true}], "total_posts"=>1}  

i have tried many different formats , can't seem post url. thought post_url , embed each of them shows in tumblr on webpage. can me?

try this:

@posts['posts'].first['post_url'] 

or if response contains more 1 post can return them this:

(0...@posts['total_posts']).map { |i| @posts['posts'][i]['post_url'] } 

edit: fixed capitalization in second line of code. assume using lowercase variable per ruby convention, '@posts'. if not, should change lowercase variable may confusing something.


Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -