Class: ADN::Post
- Inherits:
-
Object
- Object
- ADN::Post
- Defined in:
- lib/adnruby.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
Constructor Details
#initialize(raw_post) ⇒ Post
Returns a new instance of Post.
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/adnruby.rb', line 153 def initialize(raw_post) if raw_post.is_a? Hash raw_post.each do |k, v| self.instance_variable_set "@#{k}", v end @post_id = @id else @post_id = raw_post details = self.details if details.has_key? "data" details["data"].each do |k, v| self.instance_variable_set "@#{k}", v end end end end |
Instance Attribute Details
#created_at ⇒ Object
Returns the value of attribute created_at.
146 147 148 |
# File 'lib/adnruby.rb', line 146 def created_at @created_at end |
#entities ⇒ Object
Returns the value of attribute entities.
146 147 148 |
# File 'lib/adnruby.rb', line 146 def entities @entities end |
#html ⇒ Object
Returns the value of attribute html.
146 147 148 |
# File 'lib/adnruby.rb', line 146 def html @html end |
#id ⇒ Object
Returns the value of attribute id.
146 147 148 |
# File 'lib/adnruby.rb', line 146 def id @id end |
#num_replies ⇒ Object
Returns the value of attribute num_replies.
146 147 148 |
# File 'lib/adnruby.rb', line 146 def num_replies @num_replies end |
#post_id ⇒ Object
Returns the value of attribute post_id.
146 147 148 |
# File 'lib/adnruby.rb', line 146 def post_id @post_id end |
#reply_to ⇒ Object
Returns the value of attribute reply_to.
146 147 148 |
# File 'lib/adnruby.rb', line 146 def reply_to @reply_to end |
#source ⇒ Object
Returns the value of attribute source.
146 147 148 |
# File 'lib/adnruby.rb', line 146 def source @source end |
#text ⇒ Object
Returns the value of attribute text.
146 147 148 |
# File 'lib/adnruby.rb', line 146 def text @text end |
#thread_id ⇒ Object
Returns the value of attribute thread_id.
146 147 148 |
# File 'lib/adnruby.rb', line 146 def thread_id @thread_id end |
#user ⇒ Object
Returns the value of attribute user.
146 147 148 |
# File 'lib/adnruby.rb', line 146 def user @user end |
Class Method Details
.send(params) ⇒ Object
148 149 150 151 |
# File 'lib/adnruby.rb', line 148 def self.send(params) result = ADN::API::Post.new(params) Post.new(result["data"]) unless result.has_error? end |
Instance Method Details
#delete ⇒ Object
198 199 200 201 |
# File 'lib/adnruby.rb', line 198 def delete result = ADN::API::Post.delete(@id) Post.new(result["data"]) unless result.has_error? end |
#details ⇒ Object
170 171 172 173 174 175 176 177 178 |
# File 'lib/adnruby.rb', line 170 def details if self.id h = {} self.instance_variables.each { |iv| h[iv.to_s.gsub(/[^a-zA-Z0-9_]/, '')] = self.instance_variable_get(iv) } h else ADN::API::Post.by_id(@post_id) end end |
#replies(params = nil) ⇒ Object
193 194 195 196 |
# File 'lib/adnruby.rb', line 193 def replies(params = nil) result = ADN::API::Post.replies(@id, params) result["data"].collect { |p| Post.new(p) } unless result.has_error? end |
#reply_to_post ⇒ Object
188 189 190 191 |
# File 'lib/adnruby.rb', line 188 def reply_to_post result = ADN::API::Post.by_id @reply_to Post.new(result["data"]) unless result.has_error? end |