Class: ADN::Post
- Inherits:
-
Object
- Object
- ADN::Post
- Defined in:
- lib/adn/post.rb
Instance Attribute Summary collapse
-
#annotations ⇒ Object
Returns the value of attribute annotations.
-
#canonical_url ⇒ Object
Returns the value of attribute canonical_url.
- #created_at ⇒ Object
-
#entities ⇒ Object
Returns the value of attribute entities.
-
#html ⇒ Object
Returns the value of attribute html.
-
#id ⇒ Object
Returns the value of attribute id.
-
#machine_only ⇒ Object
Returns the value of attribute machine_only.
-
#num_replies ⇒ Object
Returns the value of attribute num_replies.
-
#num_reposts ⇒ Object
Returns the value of attribute num_reposts.
-
#num_stars ⇒ Object
Returns the value of attribute num_stars.
-
#post_id ⇒ Object
Returns the value of attribute post_id.
-
#reply_to ⇒ Object
Returns the value of attribute reply_to.
-
#reposters ⇒ Object
Returns the value of attribute reposters.
-
#source ⇒ Object
Returns the value of attribute source.
-
#starred_by ⇒ Object
Returns the value of attribute starred_by.
-
#text ⇒ Object
Returns the value of attribute text.
-
#thread_id ⇒ Object
Returns the value of attribute thread_id.
- #user ⇒ Object
-
#you_reposted ⇒ Object
Returns the value of attribute you_reposted.
-
#you_starred ⇒ Object
Returns the value of attribute you_starred.
Class Method Summary collapse
Instance Method Summary collapse
- #delete ⇒ Object
- #details ⇒ Object
-
#initialize(raw_post) ⇒ Post
constructor
A new instance of Post.
- #replies(params = nil) ⇒ Object
- #reply_to_post ⇒ Object
- #set_values(values) ⇒ Object
Constructor Details
#initialize(raw_post) ⇒ Post
Returns a new instance of Post.
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/adn/post.rb', line 25 def initialize(raw_post) if raw_post.respond_to?(:each_pair) set_values(raw_post) post_id = id else post_id = raw_post post_details = details if post_details.has_key? "data" set_values(post_details["data"]) end end end |
Instance Attribute Details
#annotations ⇒ Object
Returns the value of attribute annotations.
5 6 7 |
# File 'lib/adn/post.rb', line 5 def annotations @annotations end |
#canonical_url ⇒ Object
Returns the value of attribute canonical_url.
5 6 7 |
# File 'lib/adn/post.rb', line 5 def canonical_url @canonical_url end |
#created_at ⇒ Object
49 50 51 |
# File 'lib/adn/post.rb', line 49 def created_at DateTime.parse(@created_at) end |
#entities ⇒ Object
Returns the value of attribute entities.
5 6 7 |
# File 'lib/adn/post.rb', line 5 def entities @entities end |
#html ⇒ Object
Returns the value of attribute html.
5 6 7 |
# File 'lib/adn/post.rb', line 5 def html @html end |
#id ⇒ Object
Returns the value of attribute id.
5 6 7 |
# File 'lib/adn/post.rb', line 5 def id @id end |
#machine_only ⇒ Object
Returns the value of attribute machine_only.
5 6 7 |
# File 'lib/adn/post.rb', line 5 def machine_only @machine_only end |
#num_replies ⇒ Object
Returns the value of attribute num_replies.
5 6 7 |
# File 'lib/adn/post.rb', line 5 def num_replies @num_replies end |
#num_reposts ⇒ Object
Returns the value of attribute num_reposts.
5 6 7 |
# File 'lib/adn/post.rb', line 5 def num_reposts @num_reposts end |
#num_stars ⇒ Object
Returns the value of attribute num_stars.
5 6 7 |
# File 'lib/adn/post.rb', line 5 def num_stars @num_stars end |
#post_id ⇒ Object
Returns the value of attribute post_id.
5 6 7 |
# File 'lib/adn/post.rb', line 5 def post_id @post_id end |
#reply_to ⇒ Object
Returns the value of attribute reply_to.
5 6 7 |
# File 'lib/adn/post.rb', line 5 def reply_to @reply_to end |
#reposters ⇒ Object
Returns the value of attribute reposters.
5 6 7 |
# File 'lib/adn/post.rb', line 5 def reposters @reposters end |
#source ⇒ Object
Returns the value of attribute source.
5 6 7 |
# File 'lib/adn/post.rb', line 5 def source @source end |
#starred_by ⇒ Object
Returns the value of attribute starred_by.
5 6 7 |
# File 'lib/adn/post.rb', line 5 def starred_by @starred_by end |
#text ⇒ Object
Returns the value of attribute text.
5 6 7 |
# File 'lib/adn/post.rb', line 5 def text @text end |
#thread_id ⇒ Object
Returns the value of attribute thread_id.
5 6 7 |
# File 'lib/adn/post.rb', line 5 def thread_id @thread_id end |
#you_reposted ⇒ Object
Returns the value of attribute you_reposted.
5 6 7 |
# File 'lib/adn/post.rb', line 5 def you_reposted @you_reposted end |
#you_starred ⇒ Object
Returns the value of attribute you_starred.
5 6 7 |
# File 'lib/adn/post.rb', line 5 def you_starred @you_starred end |
Class Method Details
Instance Method Details
#delete ⇒ Object
67 68 69 70 |
# File 'lib/adn/post.rb', line 67 def delete result = ADN::API::Post.delete(id) ADN.create_instance(result["data"], Post) end |
#details ⇒ Object
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/adn/post.rb', line 38 def details if id value = self.instance_variables.map do |i| [i.to_s.slice(1..-1), self.instance_variable_get(i)] end Hash[value] else ADN::API::Post.by_id(post_id) end end |
#replies(params = nil) ⇒ Object
62 63 64 65 |
# File 'lib/adn/post.rb', line 62 def replies(params = nil) result = ADN::API::Post.replies(id, params) ADN.create_collection(result["data"], Post) end |
#reply_to_post ⇒ Object
57 58 59 60 |
# File 'lib/adn/post.rb', line 57 def reply_to_post result = ADN::API::Post.by_id(reply_to) ADN.create_instance(result["data"], Post) end |
#set_values(values) ⇒ Object
72 73 74 |
# File 'lib/adn/post.rb', line 72 def set_values(values) values.each_pair { |k, v| send("#{k}=", v) if respond_to?("#{k}=") } end |