Module: Echowrap::API::Track

Includes:
Utils
Included in:
Client
Defined in:
lib/echowrap/api/track.rb

Constant Summary

Constants included from Utils

Utils::API_KEY_CANNOT_CALL_THIS_METHOD, Utils::INVALID_PARAMETER, Utils::MISSING_OR_INVALID_KEY, Utils::MISSING_PARAMETER, Utils::RATE_LIMIT_EXCEEDED, Utils::SUCCESS

Instance Method Summary collapse

Instance Method Details

#track_analysis(options = {}) ⇒ Echowrap::Track

Get analysis info on tracks given an analysis_url. This method is not explicitly described by the Echowrap API and is provided as a helper.

Examples:

Analysis

Echowrap.track_analysis(:url => "http://echonest-analysis.s3.amazonaws.com/TR/TREYOVK13C9786E66B/3/full.json?AWSAccessKeyId=AKIAJRDFEY23UEVW42BQ&Expires=1367708437&Signature=pPUyoKFvgwXj2FORgohKOA6pRPc%3D")

Parameters:

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

    A customizable set of options.

Options Hash (options):

Returns:

Raises:

See Also:



56
57
58
59
60
# File 'lib/echowrap/api/track.rb', line 56

def track_analysis(options={})
  url = options.delete(:url)
  response = send(:get, url, options)
  Echowrap::Analysis.new(response[:body])
end

#track_profile(options = {}) ⇒ Echowrap::Track

Get info about tracks given an id or md5. The md5 parameter is the file md5.

Examples:

Profile via id

Echowrap.track_profile(:id => "TRTLKZV12E5AC92E11")

Parameters:

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

    A customizable set of options.

Options Hash (options):

  • :id (String)

    The ID of the track. Required if md5 is not provided. Example: ‘TRTLKZV12E5AC92E11’.

  • :md5 (String)

    The MD5 of the track. Required if ID is not provided. Example: ‘881f4e47e88e8b570e34a3b49c8262ac’.

  • :bucket (String)

    The type of track data that should be returned. Example: audio_summary.

Returns:

Raises:

  • (Echowrap::Error::Unauthorized)

    Error raised when supplied api key is not valid. # @raise [Echowrap::Error::Unauthorized] Error raised when supplied user credentials are not valid.

See Also:



20
21
22
23
# File 'lib/echowrap/api/track.rb', line 20

def track_profile(options={})
  options.merge(:bucket => 'audio_summary') if options[:bucket].nil?
  object_from_response(Echowrap::Track, :get, '/api/v4/track/profile', :track, options)
end

#track_upload(options = {}) ⇒ Echowrap::Track

Upload a track to The Echo Nest’s analyzer for analysis. The track will be analyzed. This method takes either a url parameter, or a local audio file, which should be the contents of the request body.

combined with url option

Examples:

Upload

Echowrap.track_upload(:url => "http://example.com/audio.mp3")
Echowrap.track_upload(:track => File.new('audio.mp3'))

Parameters:

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

    A customizable set of options.

Options Hash (options):

  • :url (String)

    A url to an audio file. Cannot be combined with uploading local audio file. Example: example.com/audio.mp3.

  • :track (File)

    The track data. Cannot be

  • :filetype (String)

    The type of audio file to be analyzed. Optional if uploading a local file, will be determined from file if not explicitly passed. Must be one of [‘wav’, ‘mp3’, ‘au’, ‘ogg’, ‘m4a’, ‘mp4’].

Returns:

Raises:

See Also:



40
41
42
43
# File 'lib/echowrap/api/track.rb', line 40

def track_upload(options={})
  options.merge(filetype: File.extname(options[:track]).gsub('.', '')) if options[:track] && options[:filetype].nil?
  object_from_response(Echowrap::Track, :post, '/api/v4/track/upload', :track, options)
end