Module: Genius::WebPages

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

Overview

A web page is a single, publicly accessible page to which annotations may be attached. Web pages map 1-to-1 with unique, canonical URLs.

Class Method Summary collapse

Class Method Details

.lookup(token: nil, options: {}) ⇒ Hash

Genius::WebPages.lookup -> value

Information about a web page retrieved by the page's full URL (including protocol). The returned data includes Genius's ID for the page, which may be used to look up associated referents with the /referents endpoint.

Data is only available for pages that already have at least one annotation.

Provide as many of the following variants of the URL as possible:

Parameters:

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

Options Hash (options:):

  • :raw_annotatable_url (String)

    The URL as it would appear in a browser.

  • :canonical_url (String)

    The URL as specified by an appropriate <link> tag in a page's <head>.

  • :og_url (String)

    The URL as specified by an og:url <meta> tag in a page's <head>.

Returns:

Raises:

  • (ArgumentError)

    if song_id is blank.

  • (TokenError)

    if token or Genius::Auth.token are invalid.



29
30
31
32
33
34
35
36
37
# File 'lib/genius/api/web_pages.rb', line 29

def lookup(token: nil, options: {})
  return if token.nil? && !Auth.authorized?.nil?

  Errors.validate_token(token) unless token.nil?

  params = options_helper(options, %i[raw_annotatable_url canonical_url og_url])
  response = HTTParty.get("#{Api::RESOURCE}/?access_token=#{token_ext(token)}#{params}")
  JSON.parse(response)
end