Module: Genius::Annotations

Defined in:
lib/genius/api/annotations.rb

Overview

An annotation is a piece of content about a part of a document. The document may be a song (hosted on Genius) or a web page (hosted anywhere). The part of a document that an annotation is attached to is called a referent.

Class Method Summary collapse

Class Method Details

.annotations(id:, action:, token:, http_verb: 'get', options: {}) ⇒ Hash?

Data for a specific annotation. Supports GET, POST, PUT, DELETE verbs with optional voting actions.

Parameters:

  • id (Integer)

    ID of the annotation.

  • action (String?)

    Action for PUT request: nil, upvote, downvote, or unvote.

  • token (String?)

    Token to access api.genius.com.

  • http_verb (String) (defaults to: 'get')

    HTTP verb: get, post, put, delete.

  • options (Hash) (defaults to: {})

    Options for POST/PUT payload.

Returns:

Raises:

  • (ArgumentError)

    if action is set for non-PUT request.



17
18
19
20
21
22
23
24
# File 'lib/genius/api/annotations.rb', line 17

def annotations(id:, action:, token:, http_verb: 'get', options: {})
  return if token.nil? && !Auth.authorized?.nil?

  Errors.validate_token(token) unless token.nil?
  raise ArgumentError, 'only PUT accepts `action` param' if http_verb != 'put' && !action.nil?

  JSON.parse(request(id: id, action: action, token: token, http_verb: http_verb, options: options).body)
end