Class: Xing::Post
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
- #activities ⇒ Xing::Activity
- #commentable ⇒ Boolean
- #comments ⇒ Xing::Comments
- #deletable ⇒ Boolean
-
#image ⇒ Object
String.
- #initialize(attrs = {}) ⇒ Xing::Post constructor
- #likable ⇒ Boolean
-
#like_count ⇒ Object
Fixnum.
- #liked ⇒ Boolean
-
#link ⇒ Object
String.
-
#link_title ⇒ Object
String.
-
#post_type ⇒ Object
Symbol.
-
#posted_at ⇒ Object
Time.
- #sharable ⇒ Object
-
#text ⇒ Object
String.
-
#user ⇒ Object
Xing::User.
Methods inherited from Base
Constructor Details
#initialize(attrs = {}) ⇒ Xing::Post
9 10 11 12 |
# File 'lib/xing/post.rb', line 9 def initialize(attrs={}) super self.activities end |
Instance Method Details
#activities ⇒ Xing::Activity
15 16 17 |
# File 'lib/xing/post.rb', line 15 def activities @activities ||= @attrs["objects"].map{|activity| Xing::Activity.new(activity)} unless @attrs["objects"].nil? end |
#commentable ⇒ Boolean
20 21 22 |
# File 'lib/xing/post.rb', line 20 def commentable @commentable ||= @attrs["possible_actions"].nil? ? false : @attrs["possible_actions"].include?("COMMENT") end |
#comments ⇒ Xing::Comments
25 26 27 |
# File 'lib/xing/post.rb', line 25 def comments @comments ||= @attrs["comments"].nil? ? [] : @attrs["comments"]["latest_comments"].map{|comment| Xing::Comment.new(comment)} end |
#deletable ⇒ Boolean
30 31 32 |
# File 'lib/xing/post.rb', line 30 def deletable @deletable ||= @attrs["possible_actions"].nil? ? false : @attrs["possible_actions"].include?("DELETE") end |
#image ⇒ Object
Returns String.
35 36 37 38 39 |
# File 'lib/xing/post.rb', line 35 def image if @activities.first && @activities.first.type == "bookmark" @image ||= @activities.first.image end end |
#likable ⇒ Boolean
42 43 44 |
# File 'lib/xing/post.rb', line 42 def likable @likable ||= @attrs["possible_actions"].nil? ? false : @attrs["possible_actions"].include?("LIKE") end |
#like_count ⇒ Object
Returns Fixnum.
52 53 54 |
# File 'lib/xing/post.rb', line 52 def like_count @like_count ||= @attrs["likes"]["amount"] unless @attrs["likes"].nil? end |
#liked ⇒ Boolean
47 48 49 |
# File 'lib/xing/post.rb', line 47 def liked @liked ||= @attrs["likes"]["current_user_liked"] unless @attrs["likes"].nil? end |
#link ⇒ Object
Returns String.
57 58 59 60 61 |
# File 'lib/xing/post.rb', line 57 def link if @activities.first && @activities.first.type == "bookmark" @link ||= @activities.first.url end end |
#link_title ⇒ Object
Returns String.
64 65 66 67 68 |
# File 'lib/xing/post.rb', line 64 def link_title if @activities.first && @activities.first.type == "bookmark" @link_title ||= @activities.first.title end end |
#post_type ⇒ Object
Returns Symbol.
71 72 73 74 75 76 77 78 79 |
# File 'lib/xing/post.rb', line 71 def post_type if @activities.first && @activities.first.text @post_type ||= :text elsif @activities.first && self.user == @activities.first.object @post_type ||= :profile_update else @post_type ||= @attrs["verb"].gsub("-","_").to_sym end end |
#posted_at ⇒ Object
Returns Time.
82 83 84 |
# File 'lib/xing/post.rb', line 82 def posted_at @posted_at ||= Time.parse(@attrs['created_at']).utc unless @attrs['created_at'].nil? end |
#sharable ⇒ Object
86 87 88 |
# File 'lib/xing/post.rb', line 86 def sharable @commentable ||= @attrs["possible_actions"].include?("SHARE") unless @attrs["possible_actions"].nil? end |
#text ⇒ Object
Returns String.
91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/xing/post.rb', line 91 def text if @activities.first.text @text ||= @activities.first.text elsif @attrs["changes"] @text ||= (@attrs["verb"] + "_" + @attrs["changes"].first.downcase).gsub("-","_") else @text ||= (@attrs["verb"] + "_" + @activities.first.type).gsub("-","_") end rescue @text ||= "" end |