tunecore_direct 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data.tar.gz.sig ADDED
Binary file
data/History.txt ADDED
@@ -0,0 +1,4 @@
1
+ == 0.0.1 2008-04-09
2
+
3
+ * 1 major enhancement:
4
+ * Initial release
data/License.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008 FIXME full name
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Manifest.txt ADDED
@@ -0,0 +1,26 @@
1
+ History.txt
2
+ License.txt
3
+ Manifest.txt
4
+ README.txt
5
+ Rakefile
6
+ config/hoe.rb
7
+ config/requirements.rb
8
+ lib/tunecore_direct.rb
9
+ lib/tunecore_direct/album.rb
10
+ lib/tunecore_direct/base.rb
11
+ lib/tunecore_direct/person.rb
12
+ lib/tunecore_direct/request.rb
13
+ lib/tunecore_direct/response.rb
14
+ lib/tunecore_direct/song.rb
15
+ lib/tunecore_direct/version.rb
16
+ log/debug.log
17
+ script/console
18
+ script/destroy
19
+ script/generate
20
+ script/txt2html
21
+ setup.rb
22
+ tasks/deployment.rake
23
+ tasks/environment.rake
24
+ tasks/website.rake
25
+ test/test_helper.rb
26
+ test/test_tunecore_direct.rb
data/README.txt ADDED
@@ -0,0 +1,48 @@
1
+ = tunecore_direct
2
+
3
+ * FIX (url)
4
+
5
+ == DESCRIPTION:
6
+
7
+ FIX (describe your package)
8
+
9
+ == FEATURES/PROBLEMS:
10
+
11
+ * FIX (list of features or problems)
12
+
13
+ == SYNOPSIS:
14
+
15
+ FIX (code sample of usage)
16
+
17
+ == REQUIREMENTS:
18
+
19
+ * FIX (list of requirements)
20
+
21
+ == INSTALL:
22
+
23
+ * FIX (sudo gem install, anything else)
24
+
25
+ == LICENSE:
26
+
27
+ (The MIT License)
28
+
29
+ Copyright (c) 2008 FIX
30
+
31
+ Permission is hereby granted, free of charge, to any person obtaining
32
+ a copy of this software and associated documentation files (the
33
+ 'Software'), to deal in the Software without restriction, including
34
+ without limitation the rights to use, copy, modify, merge, publish,
35
+ distribute, sublicense, and/or sell copies of the Software, and to
36
+ permit persons to whom the Software is furnished to do so, subject to
37
+ the following conditions:
38
+
39
+ The above copyright notice and this permission notice shall be
40
+ included in all copies or substantial portions of the Software.
41
+
42
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
43
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
44
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
45
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
46
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
47
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
48
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ require 'config/requirements'
2
+ require 'config/hoe' # setup Hoe + all gem configuration
3
+
4
+ Dir['tasks/**/*.rake'].each { |rake| load rake }
data/config/hoe.rb ADDED
@@ -0,0 +1,70 @@
1
+ require 'tunecore_direct/version'
2
+
3
+ AUTHOR = 'Alex Kane' # can also be an array of Authors
4
+ EMAIL = "alex@tunecore.com"
5
+ DESCRIPTION = "Ruby SDK for TuneCore web services"
6
+ GEM_NAME = 'tunecore_direct' # what ppl will type to install your gem
7
+ RUBYFORGE_PROJECT = 'tunecoredirect' # The unix name for your project
8
+ HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
9
+ DOWNLOAD_PATH = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
10
+
11
+ @config_file = "~/.rubyforge/user-config.yml"
12
+ @config = nil
13
+ RUBYFORGE_USERNAME = "alexkane"
14
+ def rubyforge_username
15
+ unless @config
16
+ begin
17
+ @config = YAML.load(File.read(File.expand_path(@config_file)))
18
+ rescue
19
+ puts <<-EOS
20
+ ERROR: No rubyforge config file found: #{@config_file}
21
+ Run 'rubyforge setup' to prepare your env for access to Rubyforge
22
+ - See http://newgem.rubyforge.org/rubyforge.html for more details
23
+ EOS
24
+ exit
25
+ end
26
+ end
27
+ RUBYFORGE_USERNAME.replace @config["username"]
28
+ end
29
+
30
+
31
+ REV = nil
32
+ # UNCOMMENT IF REQUIRED:
33
+ # REV = YAML.load(`svn info`)['Revision']
34
+ VERS = TunecoreDirect::VERSION::STRING + (REV ? ".#{REV}" : "")
35
+ RDOC_OPTS = ['--quiet', '--title', 'tunecore_direct documentation',
36
+ "--opname", "index.html",
37
+ "--line-numbers",
38
+ "--main", "README",
39
+ "--inline-source"]
40
+
41
+ class Hoe
42
+ def extra_deps
43
+ @extra_deps.reject! { |x| Array(x).first == 'hoe' }
44
+ @extra_deps
45
+ end
46
+ end
47
+
48
+ # Generate all the Rake tasks
49
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
50
+ $hoe = Hoe.new(GEM_NAME, VERS) do |p|
51
+ p.developer(AUTHOR, EMAIL)
52
+ p.description = DESCRIPTION
53
+ p.summary = DESCRIPTION
54
+ p.url = HOMEPATH
55
+ p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
56
+ p.test_globs = ["test/**/test_*.rb"]
57
+ p.clean_globs |= ['**/.*.sw?', '*.gem', '.config', '**/.DS_Store'] #An array of file patterns to delete on clean.
58
+
59
+ # == Optional
60
+ p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
61
+ #p.extra_deps = [] # An array of rubygem dependencies [name, version], e.g. [ ['active_support', '>= 1.3.1'] ]
62
+
63
+ #p.spec_extras = {} # A hash of extra values to set in the gemspec.
64
+
65
+ end
66
+
67
+ CHANGES = $hoe.paragraphs_of('History.txt', 0..1).join("\\n\\n")
68
+ PATH = (RUBYFORGE_PROJECT == GEM_NAME) ? RUBYFORGE_PROJECT : "#{RUBYFORGE_PROJECT}/#{GEM_NAME}"
69
+ $hoe.remote_rdoc_dir = File.join(PATH.gsub(/^#{RUBYFORGE_PROJECT}\/?/,''), 'rdoc')
70
+ $hoe.rsync_args = '-av --delete --ignore-errors'
@@ -0,0 +1,15 @@
1
+ require 'fileutils'
2
+ include FileUtils
3
+
4
+ require 'rubygems'
5
+ %w[rake hoe newgem rubigen].each do |req_gem|
6
+ begin
7
+ require req_gem
8
+ rescue LoadError
9
+ puts "This Rakefile requires the '#{req_gem}' RubyGem."
10
+ puts "Installation: gem install #{req_gem} -y"
11
+ exit
12
+ end
13
+ end
14
+
15
+ $:.unshift(File.join(File.dirname(__FILE__), %w[.. lib]))
@@ -0,0 +1,14 @@
1
+ # See TunecoreDirect::Base
2
+ module TunecoreDirect
3
+ require 'rexml/document'
4
+ require 'net/http'
5
+ require 'uri'
6
+
7
+ require "tunecore_direct"
8
+ require "tunecore_direct/base"
9
+ require "tunecore_direct/request"
10
+ require "tunecore_direct/response"
11
+ require "tunecore_direct/person"
12
+ require "tunecore_direct/album"
13
+ require "tunecore_direct/song"
14
+ end
@@ -0,0 +1,105 @@
1
+ # See TunecoreDirect#Base
2
+ module TunecoreDirect
3
+
4
+ # Represents an individual TuneCore Album. Each album belongs to a Person and has one or more Song objects attached to it.
5
+ # To attach artwork to the Album you should place the Artwork file on Amazon S3 and provide the S3 location in the #artwork_s3_url accessor.
6
+ # You can upload the artwork file using !TuneCore's web-based upload tool or you can use a 3rd party S3 interface such as the
7
+ # Amazon_S3_Library_for_REST_in_Ruby[http://developer.amazonwebservices.com/connect/entry.jspa?externalID=135].
8
+ #
9
+ # Stores should be defined using the following abbreviations, seperated by commas:
10
+ # iTunesUS
11
+ # iTunesAU
12
+ # iTunesCA
13
+ # iTunesEU
14
+ # iTunesJP
15
+ # iTunesUK
16
+ # RhapsodyRH
17
+ # MusicNet
18
+ # Napster
19
+ # eMusic
20
+ # Amazon
21
+ # Lala
22
+ #
23
+ class Album < TunecoreDirect::Base
24
+ include TunecoreDirect
25
+
26
+ attr_accessor :album_id, :person_id, :name, :orig_release_year, :sale_date, :primary_genre, :secondary_genre
27
+ attr_accessor :artist_name, :label_name, :c_copyright, :p_copyright, :recording_location
28
+ attr_accessor :errors
29
+ attr_accessor :artwork_s3_url
30
+ attr_accessor :stores, :state
31
+
32
+
33
+ def initialize(options = {})
34
+ options.each do |k,v|
35
+ self.send("#{k}=", v)
36
+ end
37
+ end
38
+
39
+ # Creates an Album object from a Rexml:Element
40
+ def self.from_xml_element( album_element)
41
+ album = self.new
42
+ album.album_id = album_element.elements["id"].text
43
+ album.person_id = album_element.elements["person-id"].text
44
+ album.name = album_element.elements["name"].text
45
+ album.orig_release_year = album_element.elements["orig-release-year"].text
46
+ album.sale_date = album_element.elements["sale-date"].text
47
+ album.primary_genre = album_element.elements["primary-genre"].text
48
+ album.secondary_genre = album_element.elements["secondary-genre"].text unless album_element.elements["secondary-genre"].nil?
49
+ album.artist_name = album_element.elements["artist"].elements["name"].text
50
+ album.label_name = album_element.elements["label"].elements["name"].text
51
+ album.c_copyright = album_element.elements["c-copyright"].text
52
+ album.p_copyright = album_element.elements["p-copyright"].text
53
+ album.recording_location = album_element.elements["recording-location"].text
54
+ album.state = album_element.elements["state"].text
55
+ return album
56
+ end
57
+
58
+ # Creates a new album
59
+ def create
60
+ req = Request.new
61
+ params = { "person_id" => @person_id,
62
+ "name" => @name,
63
+ "orig_release_year" => @orig_release_year,
64
+ "sale_date" => @sale_date,
65
+ "primary_genre" => @primary_genre,
66
+ "secondary_genre" => @secondary_genre,
67
+ "artist_name" => @artist_name,
68
+ "label_name" => @label_name,
69
+ "c_copyright" => @c_copyright,
70
+ "p_copyright" => @p_copyright,
71
+ "recording_location" => @recording_location }
72
+ res = req.create_album(params)
73
+ raise "Unexpected return type: #{res.type}" unless res.type == "album"
74
+ if res.status == "created"
75
+ @album_id = res.object.album_id
76
+ return true
77
+ else
78
+ @errors = res.errors
79
+ return false
80
+ end
81
+ end
82
+
83
+ # Returns an array that contains every Song in this Album
84
+ def songs
85
+ raise "Album#songs is not implemented in this version of the SDK"
86
+ end
87
+
88
+ # Returns the number of songs that have been created for this album
89
+ def song_count
90
+ raise "Album#song_count is not implemented in this version of the SDK"
91
+ end
92
+
93
+ # Once you call Album#finalize the album will be queued for delivery to the stores. After you call finalize you can no longer make changes to the Album.
94
+ # All the songs should be created and media assets for the Album should be uploaded to S3.
95
+ def finalize
96
+ raise "Album#finalize is not implemented in this version of the SDK"
97
+ end
98
+
99
+ # Returns the XML element for this Album, if it was created from the api.
100
+ def to_xml
101
+ raise "Album#to_xml is not implemented in this version of the SDK"
102
+ end
103
+
104
+ end
105
+ end
@@ -0,0 +1,90 @@
1
+ module TunecoreDirect
2
+
3
+ # = TunecoreDirect
4
+ # TunecoreDirect is a REST/XML based web service API that allows Tunecore partners to "white label" the Tunecore
5
+ # media distribution platform, letting you offer Tunecore's services to your customers transparently.
6
+ # The web service allows a partner to:
7
+ #
8
+ # 1. Create/Query customer accounts
9
+ # 2. Publish albums that belong to customer accounts
10
+ #
11
+ # To get started with the API first obtain an API key, then have a look at these three class which you will use to interact with TuneCore:
12
+ # * Person
13
+ # * Album
14
+ # * Song
15
+ # These three classes provide all the functionality you will need to easily manage your accounts and publish albums through TuneCore. Under the hood they use the
16
+ # Request and Response classes to interact with the TunecoreDirect REST API.
17
+ # ---
18
+ # === Short Example
19
+ # Set up your environment:
20
+ #
21
+ # require 'tunecore_direct'
22
+ # TunecoreDirect::Base.tunecore_server = "http://localhost:3000"
23
+ # TunecoreDirect::Base.api_key = "57247d992de24d7840a1b75dc2e5c30a"
24
+ # request = TunecoreDirect::Request.new
25
+ #
26
+ # Create a person:
27
+ # # Make a new a person object and set all the attributes
28
+ # person = TunecoreDirect::Person.new( :name => "Alex Kane",
29
+ # :email => "alex@gmail.com",
30
+ # :phone_number => "212-555-1212",
31
+ # :country => "United States",
32
+ # :postal_code => "11201" )
33
+ # # Create the person on the Tunecore server
34
+ # person.create
35
+ # => false
36
+ # # Hmm it didn't work. Let's find out why.
37
+ # person.errors
38
+ # => [{:message=>"can't be blank", :attribute=>"password"}]
39
+ # # Doh! We forgot to set a password.
40
+ # person.password = "paSSword"
41
+ # person.create
42
+ # => true
43
+ # # It worked, and we can now get the person_id which we will use later to create albums for this person
44
+ # person.person_id
45
+ # => 55342
46
+ #
47
+ # Get a list of your people:
48
+ #
49
+ # response = request.list_people
50
+ # response.status
51
+ # => "complete"
52
+ # response.type
53
+ # => "people"
54
+ # response.object.first.email
55
+ # => "joe1243@blow.com"
56
+ #
57
+ # Author:: Alex Kane (mailto:alex@tunecore.com)
58
+ # Copyright:: Copyright (c) 2008 Tunecore
59
+ # License:: GNU LPGPL
60
+ class TunecoreDirect::Base
61
+ @@tunecore_server = nil
62
+ @@api_key = nil
63
+
64
+ def self.tunecore_server=(uri)
65
+ @@tunecore_server = uri
66
+ end
67
+
68
+ def self.tunecore_server
69
+ @@tunecore_server
70
+ end
71
+
72
+ def tunecore_server
73
+ @@tunecore_server
74
+ end
75
+
76
+ def self.api_key=(key)
77
+ @@api_key = key
78
+ end
79
+
80
+ def self.api_key
81
+ @@api_key
82
+ end
83
+
84
+ def api_key
85
+ @@api_key
86
+ end
87
+
88
+ end
89
+
90
+ end
@@ -0,0 +1,83 @@
1
+ module TunecoreDirect
2
+
3
+ # Represents a individual TuneCore account
4
+ #
5
+ # Required fields are:
6
+ # * email
7
+ # * name
8
+ # * phone_number
9
+ # * postal_code
10
+ # * country
11
+ # * password
12
+ #
13
+ # Once you set these instance variables you can call Person#create to create the account at TuneCore. When the account is created the person_id will be
14
+ # set which you should use to track the user in your system.
15
+ #
16
+ # If you don't set these instance variables before calling Person#create the call will return false and the Person#errors accessor will be
17
+ # populated with a list of errors that you will need to fix.
18
+ class TunecoreDirect::Person < TunecoreDirect::Base
19
+ include TunecoreDirect
20
+
21
+ attr_accessor :person_id, :email, :name, :phone_number, :postal_code, :country, :password, :errors
22
+
23
+ def initialize(options = {})
24
+ options.each do |k,v|
25
+ self.send("#{k}=", v)
26
+ end
27
+ end
28
+
29
+ # takes an Rexml::Element and builds a person out of it
30
+ def self.from_xml_element(person_element)
31
+ @xml_element = person_element
32
+ person = self.new
33
+ person.person_id = person_element.attributes["person_id"]
34
+ person.email = person_element.elements["email"].text
35
+ person.name = person_element.elements["name"].text
36
+ person.phone_number = person_element.elements["phone_number"].text
37
+ return person
38
+ end
39
+
40
+ # Returns the XML representation of this person
41
+ def to_xml
42
+ return false if @xml_element.nil?
43
+ @xml_element.text
44
+ end
45
+
46
+ # Creates this person record in the Tunecore system
47
+ def create
48
+ req = Request.new
49
+ res = req.create_person(@email, @password, @name, @phone_number, @country, @postal_code)
50
+ raise "Unexpected return type: #{res.type}" unless res.type == "person"
51
+ if res.status == "complete"
52
+ @person_id = res.object.person_id
53
+ return true
54
+ else
55
+ @errors = res.errors
56
+ return false
57
+ end
58
+ end
59
+
60
+ # Creates a new album for this Person
61
+ def create_album(params={})
62
+ params[:person_id] = self.person_id
63
+ album = TunecoreDirect::Album.new(params)
64
+ album.create
65
+ return album
66
+ end
67
+
68
+ # Returns an array of people associated with your account
69
+ def self.get_people
70
+ req = Request.new
71
+ req.get_people.object
72
+ end
73
+
74
+ # Returns an array of albums owned by this person
75
+ def albums
76
+ req = Request.new
77
+ req.get_albums(person_id).object
78
+ end
79
+
80
+
81
+
82
+ end
83
+ end