Class: Genius::Referent

Inherits:
Resource show all
Defined in:
lib/genius/referent.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, from_hash, handle_response, http_delete, http_get, http_post, http_put, #initialize, resource_name

Constructor Details

This class inherits a constructor from Genius::Resource

Instance Attribute Details

#annotatableObject (readonly)

Returns the value of attribute annotatable.



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

def annotatable
  @annotatable
end

#annotationsObject (readonly)

Returns the value of attribute annotations.



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

def annotations
  @annotations
end

#annotator_idObject (readonly)

Returns the value of attribute annotator_id.



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

def annotator_id
  @annotator_id
end

#classificationObject (readonly)

Returns the value of attribute classification.



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

def classification
  @classification
end

#fragmentObject (readonly)

Returns the value of attribute fragment.



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

def fragment
  @fragment
end

#idObject (readonly)

Returns the value of attribute id.



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

def id
  @id
end

#rangeObject (readonly)

Returns the value of attribute range.



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

def range
  @range
end

#song_idObject (readonly)

Returns the value of attribute song_id.



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

def song_id
  @song_id
end

#urlObject (readonly)

Returns the value of attribute url.



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

def url
  @url
end

Class Method Details

.findObject

Raises:

  • (NotImplementedError)


6
7
8
# File 'lib/genius/referent.rb', line 6

def self.find(*)
  raise NotImplementedError, "A Referent cannot be loaded by its ID in the public API"
end

.where(params = {}) ⇒ Object



10
11
12
13
14
15
16
17
18
19
# File 'lib/genius/referent.rb', line 10

def self.where(params = {})
  headers = default_headers.merge(params.delete(:headers) || {})
  params = default_params.merge(params)

  response = http_get("/#{resource_name}s/", query: params, headers: headers)

  response.parsed_response["response"]["referents"].map do |referent|
    self.from_hash(referent, text_format: params[:text_format])
  end
end

Instance Method Details

#parse_resource!Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/genius/referent.rb', line 25

def parse_resource!
  @url = resource["url"]

  @annotations = resource["annotations"].map do |annotation|
    Annotation.from_hash(annotation)
  end

  @song_id = resource["song_id"]
  @annotator_id = resource["annotator_id"]
  @fragment = resource["fragment"]
  @range = resource["range"]
  @classification = resource["classification"]
  @annotatable = resource["annotatable"]
  @id = resource["id"]
end

#reloadObject

Raises:



21
22
23
# File 'lib/genius/referent.rb', line 21

def reload
  raise NotReloadableError, "A Referent cannot be reloaded"
end

#songObject



41
42
43
44
# File 'lib/genius/referent.rb', line 41

def song
  return nil unless song_id
  Song.find(song_id)
end