Class: Genius::Annotation

Inherits:
Resource show all
Defined in:
lib/genius/annotation.rb

Instance Attribute Summary collapse

Attributes inherited from Resource

#raw_response, #resource

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Resource

default_headers, default_params, find, from_hash, handle_response, http_delete, http_get, http_post, http_put, #initialize, #reload, resource_name

Constructor Details

This class inherits a constructor from Genius::Resource

Instance Attribute Details

#authorsObject (readonly)

Returns the value of attribute authors.



3
4
5
# File 'lib/genius/annotation.rb', line 3

def authors
  @authors
end

#bodyObject (readonly)

Returns the value of attribute body.



3
4
5
# File 'lib/genius/annotation.rb', line 3

def body
  @body
end

#comment_countObject (readonly)

Returns the value of attribute comment_count.



3
4
5
# File 'lib/genius/annotation.rb', line 3

def comment_count
  @comment_count
end

#current_user_metadataObject (readonly)

Returns the value of attribute current_user_metadata.



3
4
5
# File 'lib/genius/annotation.rb', line 3

def 
  @current_user_metadata
end

#idObject (readonly)

Returns the value of attribute id.



3
4
5
# File 'lib/genius/annotation.rb', line 3

def id
  @id
end

#share_urlObject (readonly)

Returns the value of attribute share_url.



3
4
5
# File 'lib/genius/annotation.rb', line 3

def share_url
  @share_url
end

#stateObject (readonly)

Returns the value of attribute state.



3
4
5
# File 'lib/genius/annotation.rb', line 3

def state
  @state
end

#urlObject (readonly)

Returns the value of attribute url.



3
4
5
# File 'lib/genius/annotation.rb', line 3

def url
  @url
end

#verified_byObject (readonly)

Returns the value of attribute verified_by.



3
4
5
# File 'lib/genius/annotation.rb', line 3

def verified_by
  @verified_by
end

#votes_totalObject (readonly)

Returns the value of attribute votes_total.



3
4
5
# File 'lib/genius/annotation.rb', line 3

def votes_total
  @votes_total
end

Class Method Details

.create!(body = {}) ⇒ Object



54
55
56
# File 'lib/genius/annotation.rb', line 54

def self.create!(body = {})
  new(http_post("/annotations", body: body, headers: default_headers))
end

Instance Method Details

#destroy!Object



27
28
29
30
31
# File 'lib/genius/annotation.rb', line 27

def destroy!
  self.class.http_delete("/annotations/#{id}", headers: self.class.default_headers)

  true
end

#downvote!Object



47
48
49
50
51
52
# File 'lib/genius/annotation.rb', line 47

def downvote!
  self.class.http_put("/annotations/#{id}/downvote",
                      headers: self.class.default_headers)

  true
end

#parse_resource!Object



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/genius/annotation.rb', line 6

def parse_resource!
  @verified_by = Account.from_hash(resource["verified_by"])
  @share_url = resource["share_url"]
  @body = formatted_attribute("body")
  @votes_total = resource["votes_total"]
  @comment_count = resource["comment_count"]
  @authors = resource["authors"]
  @state = resource["state"]
  @current_user_metadata = resource["current_user_metadata"]
  @id = resource["id"]
  @url = resource["url"]
end

#unvote!Object



40
41
42
43
44
45
# File 'lib/genius/annotation.rb', line 40

def unvote!
  self.class.http_put("/annotations/#{id}/unvote",
                      headers: self.class.default_headers)

  true
end

#update!(body = {}) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/genius/annotation.rb', line 19

def update!(body = {})
  response = self.class.http_put("/annotations/#{id}",
                                 body: body,
                                 headers: self.class.default_headers)

  self.class.new(response, text_format: text_format)
end

#upvote!Object



33
34
35
36
37
38
# File 'lib/genius/annotation.rb', line 33

def upvote!
  self.class.http_put("/annotations/#{id}/upvote",
                      headers: self.class.default_headers)

  true
end