Class: ADN::Post
- Inherits:
-
Object
- Object
- ADN::Post
- Defined in:
- lib/adn/post.rb
Instance Attribute Summary collapse
-
#created_at ⇒ Object
Returns the value of attribute created_at.
-
#entities ⇒ Object
Returns the value of attribute entities.
-
#html ⇒ Object
Returns the value of attribute html.
-
#id ⇒ Object
Returns the value of attribute id.
-
#num_replies ⇒ Object
Returns the value of attribute num_replies.
-
#post_id ⇒ Object
Returns the value of attribute post_id.
-
#reply_to ⇒ Object
Returns the value of attribute reply_to.
-
#source ⇒ Object
Returns the value of attribute source.
-
#text ⇒ Object
Returns the value of attribute text.
-
#thread_id ⇒ Object
Returns the value of attribute thread_id.
-
#user ⇒ Object
Returns the value of attribute user.
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.
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/adn/post.rb', line 14 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
#created_at ⇒ Object
Returns the value of attribute created_at.
5 6 7 |
# File 'lib/adn/post.rb', line 5 def created_at @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 |
#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 |
#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 |
#source ⇒ Object
Returns the value of attribute source.
5 6 7 |
# File 'lib/adn/post.rb', line 5 def source @source 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 |
#user ⇒ Object
Returns the value of attribute user.
5 6 7 |
# File 'lib/adn/post.rb', line 5 def user @user end |
Class Method Details
Instance Method Details
#delete ⇒ Object
53 54 55 56 |
# File 'lib/adn/post.rb', line 53 def delete result = ADN::API::Post.delete(id) ADN.create_instance(result["data"], Post) end |
#details ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/adn/post.rb', line 27 def details if id Hash[self.instance_variables.map { |i| [i.to_s.slice(1..-1), self.instance_variable_get(i)]}] else ADN::API::Post.by_id(post_id) end end |
#replies(params = nil) ⇒ Object
48 49 50 51 |
# File 'lib/adn/post.rb', line 48 def replies(params = nil) result = ADN::API::Post.replies(id, params) ADN.create_collection(result["data"], Post) end |
#reply_to_post ⇒ Object
43 44 45 46 |
# File 'lib/adn/post.rb', line 43 def reply_to_post result = ADN::API::Post.by_id(reply_to) ADN.create_instance(result["data"], Post) end |
#set_values(values) ⇒ Object
58 59 60 |
# File 'lib/adn/post.rb', line 58 def set_values(values) values.each_pair { |k, v| send("#{k}=", v) if respond_to?("#{k}=") } end |