Skip to content

Commit

Permalink
author avatar is added to API and story content in API has been chang…
Browse files Browse the repository at this point in the history
…ed to html format
  • Loading branch information
Hamed Ramezanian committed Jul 10, 2013
1 parent 18b1d7c commit 81ba5a9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
3 changes: 2 additions & 1 deletion README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ http://nerdnews.ir/
The response would be a json arrays of stories which has the following fields:
id:integer => ID of the story
title:string => title of the story
content:text => content of the story
content:text => content of the story in html format
total_point:integer => total point of the story
hide:boolean => indicates that story must be hidden or not
comments_count:integer => number of comments for the story
Expand All @@ -29,6 +29,7 @@ http://nerdnews.ir/
negative_votes_count:integer => number of negative votes for the story
published_at:string => publish date of the story in Jalali Date
author:string => author of the story
author_avatar:string => avatar of the author story
reference_url:string => reference of the story that would be a link
story_url:string => story url
comments:array => array of comments for the story which has the following fields:
Expand Down
16 changes: 14 additions & 2 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@ module ApplicationHelper
# end

def avatar_url(user, size = 20)
gravater_id = Digest::MD5.hexdigest(user.email.downcase)
"http://gravatar.com/avatar/#{gravater_id}.png?s=#{size}&d=mm"
if user
gravater_id = Digest::MD5.hexdigest(user.email.downcase)
"http://gravatar.com/avatar/#{gravater_id}.png?s=#{size}&d=mm"
else
image_url "nobody.png"
end
end

def to_jalali(date, options = {})
Expand Down Expand Up @@ -100,4 +104,12 @@ def determine_browser_and_os(ua = request.env["HTTP_USER_AGENT"])
ua.include?('win') ? 'win' : nil
"#{br}#{" " unless br.nil? or os.nil?}#{os}"
end

def image_url(source)
abs_path = image_path(source)
unless abs_path =~ /^http/
abs_path = "#{request.protocol}#{request.host_with_port}#{abs_path}"
end
abs_path
end
end
6 changes: 5 additions & 1 deletion app/views/stories/show.json.rabl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ attributes :id, :title, :total_point, :hide, :comments_count, :view_counter, :po
:negative_votes_count

node :content do |story|
RedCloth.new(story.content, [:filter_html, :filter_styles]).to_plain
RedCloth.new(story.content, [:filter_html, :filter_styles]).to_html
end

node :published_at do |story|
Expand All @@ -14,6 +14,10 @@ node :author do |story|
user_name(story, true)
end

node :author_avatar do |story|
avatar_url story.user
end

node :reference_url do |story|
story.source
end
Expand Down

0 comments on commit 81ba5a9

Please sign in to comment.