Class: Xing::Post

Inherits:
Base
  • Object
show all
Defined in:
lib/xing/post.rb

Instance Attribute Summary

Attributes inherited from Base

#attrs

Instance Method Summary collapse

Methods inherited from Base

#[], lazy_attr_reader

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

#activitiesXing::Activity

Returns:



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

#commentableBoolean

Returns:

  • (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

#commentsXing::Comments

Returns:

  • (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

#deletableBoolean

Returns:

  • (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

#imageObject

Returns String.

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

#likableBoolean

Returns:

  • (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_countObject

Returns Fixnum.

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

#likedBoolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/xing/post.rb', line 47

def liked
  @liked ||= @attrs["likes"]["current_user_liked"] unless @attrs["likes"].nil?
end

Returns String.

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

Returns String.

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_typeObject

Returns Symbol.

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_atObject

Returns Time.

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

#sharableObject



86
87
88
# File 'lib/xing/post.rb', line 86

def sharable
  @commentable ||= @attrs["possible_actions"].include?("SHARE") unless @attrs["possible_actions"].nil?
end

#textObject

Returns String.

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

#userObject

Returns Xing::User.

Returns:

  • Xing::User



104
105
106
# File 'lib/xing/post.rb', line 104

def user
  @user ||= Xing::User.new(@attrs.dup['actors'].first) unless @attrs["actors"].nil?
end