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.



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

#annotationsObject

Returns the value of attribute annotations.



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

def annotations
  @annotations
end

#canonical_urlObject

Returns the value of attribute canonical_url.



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

def canonical_url
  @canonical_url
end

#created_atObject



49
50
51
# File 'lib/adn/post.rb', line 49

def created_at
  DateTime.parse(@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

#machine_onlyObject

Returns the value of attribute machine_only.



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

def machine_only
  @machine_only
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

#num_repostsObject

Returns the value of attribute num_reposts.



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

def num_reposts
  @num_reposts
end

#num_starsObject

Returns the value of attribute num_stars.



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

def num_stars
  @num_stars
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

#repostersObject

Returns the value of attribute reposters.



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

def reposters
  @reposters
end

#sourceObject

Returns the value of attribute source.



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

def source
  @source
end

#starred_byObject

Returns the value of attribute starred_by.



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

def starred_by
  @starred_by
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



53
54
55
# File 'lib/adn/post.rb', line 53

def user
  ADN::User.new(@user)
end

#you_repostedObject

Returns the value of attribute you_reposted.



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

def you_reposted
  @you_reposted
end

#you_starredObject

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

.by_id(id) ⇒ Object



20
21
22
23
# File 'lib/adn/post.rb', line 20

def self.by_id(id)
  result = ADN::API::Post.by_id(id)
  Post.new(result["data"])
end

.send_post(params) ⇒ Object



15
16
17
18
# File 'lib/adn/post.rb', line 15

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

Instance Method Details

#deleteObject



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

#detailsObject



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_postObject



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