Class: ADN::Post

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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_atObject

Returns the value of attribute created_at.



5
6
7
# File 'lib/adn/post.rb', line 5

def created_at
  @created_at
end

#entitiesObject

Returns the value of attribute entities.



5
6
7
# File 'lib/adn/post.rb', line 5

def entities
  @entities
end

#htmlObject

Returns the value of attribute html.



5
6
7
# File 'lib/adn/post.rb', line 5

def html
  @html
end

#idObject

Returns the value of attribute id.



5
6
7
# File 'lib/adn/post.rb', line 5

def id
  @id
end

#num_repliesObject

Returns the value of attribute num_replies.



5
6
7
# File 'lib/adn/post.rb', line 5

def num_replies
  @num_replies
end

#post_idObject

Returns the value of attribute post_id.



5
6
7
# File 'lib/adn/post.rb', line 5

def post_id
  @post_id
end

#reply_toObject

Returns the value of attribute reply_to.



5
6
7
# File 'lib/adn/post.rb', line 5

def reply_to
  @reply_to
end

#sourceObject

Returns the value of attribute source.



5
6
7
# File 'lib/adn/post.rb', line 5

def source
  @source
end

#textObject

Returns the value of attribute text.



5
6
7
# File 'lib/adn/post.rb', line 5

def text
  @text
end

#thread_idObject

Returns the value of attribute thread_id.



5
6
7
# File 'lib/adn/post.rb', line 5

def thread_id
  @thread_id
end

#userObject

Returns the value of attribute user.



5
6
7
# File 'lib/adn/post.rb', line 5

def user
  @user
end

Class Method Details

.send_post(params) ⇒ Object



9
10
11
12
# File 'lib/adn/post.rb', line 9

def self.send_post(params)
  result = ADN::API::Post.create(params)
  Post.new(result["data"])
end

Instance Method Details

#deleteObject



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

#detailsObject



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_postObject



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