Class: TunecoreDirect::Song

Inherits:
Base
  • Object
show all
Includes:
TunecoreDirect
Defined in:
lib/tunecore_direct/song.rb

Overview

Represents a song in TuneCore. Every song must belong to an #Album, which in turn must belong to a #Person. The actual media file (wav, mp3, flac, etc.) should be placed on Amazon S3, either using the TuneCore uploaders or a 3rd party library such as the Amazon_S3_Library_for_REST_in_Ruby.

Instance Attribute Summary collapse

Attributes inherited from Base

#log

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

api_key, #api_key, api_key=, #to_xml, tunecore_server, #tunecore_server, tunecore_server=

Constructor Details

#initialize(options = {}) ⇒ Song

Returns a new instance of Song.



13
14
15
16
17
# File 'lib/tunecore_direct/song.rb', line 13

def initialize(options = {})
  options.each do |k,v|
    self.send("#{k}=", v)
  end
end

Instance Attribute Details

#album_idObject

Returns the value of attribute album_id.



10
11
12
# File 'lib/tunecore_direct/song.rb', line 10

def album_id
  @album_id
end

#artist_nameObject

Returns the value of attribute artist_name.



10
11
12
# File 'lib/tunecore_direct/song.rb', line 10

def artist_name
  @artist_name
end

#asset_urlObject

Returns the value of attribute asset_url.



11
12
13
# File 'lib/tunecore_direct/song.rb', line 11

def asset_url
  @asset_url
end

#errorsObject

Returns the value of attribute errors.



11
12
13
# File 'lib/tunecore_direct/song.rb', line 11

def errors
  @errors
end

#nameObject

Returns the value of attribute name.



10
11
12
# File 'lib/tunecore_direct/song.rb', line 10

def name
  @name
end

#parental_advisoryObject

Returns the value of attribute parental_advisory.



10
11
12
# File 'lib/tunecore_direct/song.rb', line 10

def parental_advisory
  @parental_advisory
end

#s3_bucket_nameObject

Returns the value of attribute s3_bucket_name.



11
12
13
# File 'lib/tunecore_direct/song.rb', line 11

def s3_bucket_name
  @s3_bucket_name
end

#s3_keyObject

Returns the value of attribute s3_key.



11
12
13
# File 'lib/tunecore_direct/song.rb', line 11

def s3_key
  @s3_key
end

#s3_urlObject

Returns the value of attribute s3_url.



10
11
12
# File 'lib/tunecore_direct/song.rb', line 10

def s3_url
  @s3_url
end

#song_idObject

Returns the value of attribute song_id.



10
11
12
# File 'lib/tunecore_direct/song.rb', line 10

def song_id
  @song_id
end

#track_numObject

Returns the value of attribute track_num.



10
11
12
# File 'lib/tunecore_direct/song.rb', line 10

def track_num
  @track_num
end

Class Method Details

.from_xml_element(song_element) ⇒ Object

Creates an Album object from a Rexml:Element



51
52
53
54
55
56
57
58
59
60
# File 'lib/tunecore_direct/song.rb', line 51

def self.from_xml_element( song_element)
  song = self.new
  song.song_id            = song_element.elements["id"].text
  song.album_id           = song_element.elements["album-id"].text
  song.name               = song_element.elements["name"].text
  song.artist_name        = song_element.elements["artist-name"].text unless song_element.elements["artist-name"].nil?
  song.parental_advisory  = song_element.elements["parental-advisory"].text
  song.track_num          = song_element.elements["track-num"].text
  return song
end

Instance Method Details

#albumObject

Returns that Album that this Song belongs to



20
21
22
# File 'lib/tunecore_direct/song.rb', line 20

def album
  raise "Song#album is not supported in this version of the SDK"
end

#personObject

Returns the Person that this Song belongs to



25
26
27
# File 'lib/tunecore_direct/song.rb', line 25

def person
  raise "Song#person is not supported in this version of the SDK"
end

#saveObject

Save’s the song in Tunecore’s system



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/tunecore_direct/song.rb', line 30

def save
  req = Request.new
  params = {  "album_id"          => @album_id,
              "name"              => @name,
              "artist_name"       => @artist_name,
              "track_num"         => @track_num,
              "parental_advisory" => @parental_advisory,
              "asset_url"         => @asset_url }
  
  res = req.create_song( params )
  raise "Unexpected return type: #{res.type}" unless res.type == "song"
  if res.status == "created"
    @song_id = res.object.song_id
    return true
  else
    @errors = res.errors
    return false
  end
end

#upload_urlObject

Returns the URL for the upload tool



63
64
65
# File 'lib/tunecore_direct/song.rb', line 63

def upload_url
  "#{tunecore_server}/partner/track_upload?api_key=#{api_key}&song_id=#{self.song_id}"
end