tunecore_direct 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data.tar.gz.sig +0 -0
- data/lib/tunecore_direct/album.rb +43 -13
- data/lib/tunecore_direct/base.rb +12 -1
- data/lib/tunecore_direct/person.rb +1 -1
- data/lib/tunecore_direct/request.rb +10 -2
- data/lib/tunecore_direct/response.rb +0 -5
- data/lib/tunecore_direct/version.rb +1 -1
- data/test/test_tunecore_direct.rb +73 -11
- metadata +2 -2
- metadata.gz.sig +2 -2
data.tar.gz.sig
CHANGED
Binary file
|
@@ -23,13 +23,12 @@ module TunecoreDirect
|
|
23
23
|
class Album < TunecoreDirect::Base
|
24
24
|
include TunecoreDirect
|
25
25
|
|
26
|
-
attr_accessor :album_id, :person_id, :name, :
|
27
|
-
attr_accessor :artist_name, :label_name, :c_copyright, :p_copyright, :recording_location
|
28
|
-
attr_accessor :
|
29
|
-
attr_accessor :
|
26
|
+
attr_accessor :album_id, :person_id, :name, :orig_release_date, :sale_date, :primary_genre, :secondary_genre
|
27
|
+
attr_accessor :artist_name, :label_name, :c_copyright, :p_copyright, :recording_location, :parental_advisory
|
28
|
+
attr_accessor :artwork_s3_id, :takedown_at
|
29
|
+
attr_accessor :errors
|
30
30
|
attr_accessor :stores, :state
|
31
31
|
|
32
|
-
|
33
32
|
def initialize(options = {})
|
34
33
|
options.each do |k,v|
|
35
34
|
self.send("#{k}=", v)
|
@@ -38,20 +37,23 @@ module TunecoreDirect
|
|
38
37
|
|
39
38
|
# Creates an Album object from a Rexml:Element
|
40
39
|
def self.from_xml_element( album_element)
|
40
|
+
@xml = album_element
|
41
|
+
#puts @xml
|
41
42
|
album = self.new
|
42
43
|
album.album_id = album_element.elements["id"].text
|
43
44
|
album.person_id = album_element.elements["person-id"].text
|
44
45
|
album.name = album_element.elements["name"].text
|
45
|
-
album.
|
46
|
+
album.orig_release_date = album_element.elements["orig-release-year"].text
|
46
47
|
album.sale_date = album_element.elements["sale-date"].text
|
47
48
|
album.primary_genre = album_element.elements["primary-genre"].text
|
48
49
|
album.secondary_genre = album_element.elements["secondary-genre"].text unless album_element.elements["secondary-genre"].nil?
|
49
50
|
album.artist_name = album_element.elements["artist"].elements["name"].text
|
50
|
-
album.label_name = album_element.elements["label
|
51
|
+
album.label_name = album_element.elements["label-name"].text
|
51
52
|
album.c_copyright = album_element.elements["c-copyright"].text
|
52
53
|
album.p_copyright = album_element.elements["p-copyright"].text
|
53
54
|
album.recording_location = album_element.elements["recording-location"].text
|
54
55
|
album.state = album_element.elements["state"].text
|
56
|
+
album.takedown_at = album_element.elements["takedown-at"].text
|
55
57
|
return album
|
56
58
|
end
|
57
59
|
|
@@ -60,7 +62,7 @@ module TunecoreDirect
|
|
60
62
|
req = Request.new
|
61
63
|
params = { "person_id" => @person_id,
|
62
64
|
"name" => @name,
|
63
|
-
"orig_release_year" => @
|
65
|
+
"orig_release_year" => @orig_release_date,
|
64
66
|
"sale_date" => @sale_date,
|
65
67
|
"primary_genre" => @primary_genre,
|
66
68
|
"secondary_genre" => @secondary_genre,
|
@@ -68,7 +70,8 @@ module TunecoreDirect
|
|
68
70
|
"label_name" => @label_name,
|
69
71
|
"c_copyright" => @c_copyright,
|
70
72
|
"p_copyright" => @p_copyright,
|
71
|
-
"recording_location" => @recording_location
|
73
|
+
"recording_location" => @recording_location,
|
74
|
+
"stores" => @stores }
|
72
75
|
res = req.create_album(params)
|
73
76
|
raise "Unexpected return type: #{res.type}" unless res.type == "album"
|
74
77
|
if res.status == "created"
|
@@ -79,6 +82,22 @@ module TunecoreDirect
|
|
79
82
|
return false
|
80
83
|
end
|
81
84
|
end
|
85
|
+
|
86
|
+
# Returns an Album
|
87
|
+
def self.get(album_id)
|
88
|
+
req = Request.new
|
89
|
+
res = req.get_album(album_id)
|
90
|
+
raise "Unexpected return type: #{res.type}" unless res.type == "album"
|
91
|
+
return res.object
|
92
|
+
end
|
93
|
+
|
94
|
+
# Returns all your albums. If a person_id is specified it will return only albums for that person.
|
95
|
+
def self.get_all(person_id=nil)
|
96
|
+
req = Request.new
|
97
|
+
res = req.get_albums(person_id)
|
98
|
+
raise "Unexpected return type: #{res.type}" unless res.type == "albums"
|
99
|
+
return res.object
|
100
|
+
end
|
82
101
|
|
83
102
|
# Returns an array that contains every Song in this Album
|
84
103
|
def songs
|
@@ -96,10 +115,21 @@ module TunecoreDirect
|
|
96
115
|
raise "Album#finalize is not implemented in this version of the SDK"
|
97
116
|
end
|
98
117
|
|
99
|
-
#
|
100
|
-
def
|
101
|
-
|
118
|
+
# Takes down an album from the stores
|
119
|
+
def self.takedown(album_id)
|
120
|
+
req = Request.new
|
121
|
+
res = req.takedown_album(album_id)
|
122
|
+
raise "Unexpected return type: #{res.type}" unless res.type == "album"
|
123
|
+
if res.object.takedown_at != nil
|
124
|
+
return true
|
125
|
+
else
|
126
|
+
return false
|
127
|
+
end
|
102
128
|
end
|
103
|
-
|
129
|
+
|
130
|
+
def is_taken_down?
|
131
|
+
!@takedown.nil?
|
132
|
+
end
|
133
|
+
|
104
134
|
end
|
105
135
|
end
|
data/lib/tunecore_direct/base.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'Logger'
|
1
2
|
module TunecoreDirect
|
2
3
|
|
3
4
|
# = TunecoreDirect
|
@@ -58,9 +59,15 @@ module TunecoreDirect
|
|
58
59
|
# Copyright:: Copyright (c) 2008 Tunecore
|
59
60
|
# License:: GNU LPGPL
|
60
61
|
class TunecoreDirect::Base
|
62
|
+
attr_accessor :log
|
61
63
|
@@tunecore_server = nil
|
62
64
|
@@api_key = nil
|
63
|
-
|
65
|
+
|
66
|
+
def log( method, params=nil )
|
67
|
+
@log = Logger.new(STDOUT) if @log.nil?
|
68
|
+
@log.send(method, params)
|
69
|
+
end
|
70
|
+
|
64
71
|
def self.tunecore_server=(uri)
|
65
72
|
@@tunecore_server = uri
|
66
73
|
end
|
@@ -84,6 +91,10 @@ module TunecoreDirect
|
|
84
91
|
def api_key
|
85
92
|
@@api_key
|
86
93
|
end
|
94
|
+
|
95
|
+
def to_xml
|
96
|
+
@xml
|
97
|
+
end
|
87
98
|
|
88
99
|
end
|
89
100
|
|
@@ -30,7 +30,7 @@ module TunecoreDirect
|
|
30
30
|
def self.from_xml_element(person_element)
|
31
31
|
@xml_element = person_element
|
32
32
|
person = self.new
|
33
|
-
person.person_id = person_element.
|
33
|
+
person.person_id = person_element.elements["id"].text
|
34
34
|
person.email = person_element.elements["email"].text
|
35
35
|
person.name = person_element.elements["name"].text
|
36
36
|
person.phone_number = person_element.elements["phone_number"].text
|
@@ -44,7 +44,7 @@ module TunecoreDirect
|
|
44
44
|
def get_albums(person_id=nil)
|
45
45
|
params = { "person_id" => person_id }
|
46
46
|
http_res = http_post("get_albums", params )
|
47
|
-
tc_res = Response.new( http_res.body )
|
47
|
+
tc_res = Response.new( http_res.body )
|
48
48
|
return tc_res
|
49
49
|
end
|
50
50
|
|
@@ -62,7 +62,15 @@ module TunecoreDirect
|
|
62
62
|
tc_res = Response.new( http_res.body )
|
63
63
|
return tc_res
|
64
64
|
end
|
65
|
-
|
65
|
+
|
66
|
+
# Sends a takedown request for this album
|
67
|
+
def takedown_album(album_id)
|
68
|
+
params = {"album_id" => album_id}
|
69
|
+
http_res = http_post("takedown_album", params )
|
70
|
+
tc_res = Response.new( http_res.body )
|
71
|
+
return tc_res
|
72
|
+
end
|
73
|
+
|
66
74
|
private
|
67
75
|
|
68
76
|
# Make contact with TC. API key is inserted here automatically and is used to authenticate and authorize the request.
|
@@ -1,11 +1,73 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
|
-
|
3
|
-
class TestTunecoreDirect < Test::Unit::TestCase
|
4
|
-
|
5
|
-
def setup
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
1
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
|
+
|
3
|
+
class TestTunecoreDirect < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
TunecoreDirect::Base.tunecore_server = "http://test.tunecore.com"
|
7
|
+
TunecoreDirect::Base.api_key = "testkey"
|
8
|
+
|
9
|
+
#random email address so we dont get collisions after the first test
|
10
|
+
chars = ["A".."Z","a".."z","0".."9"].collect { |r| r.to_a }.join
|
11
|
+
@email = (1..8).collect { chars[rand(chars.size)] }.pack("C*") + "@domain.com"
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_can_create_person
|
15
|
+
person = TunecoreDirect::Person.new
|
16
|
+
person.name = "Joe Schmoe"
|
17
|
+
person.email = @email
|
18
|
+
person.password = "my_pas$word"
|
19
|
+
person.phone_number = "212-555-1212"
|
20
|
+
person.country = "United States"
|
21
|
+
person.postal_code = "11201"
|
22
|
+
created = person.create
|
23
|
+
assert created == true
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_can_create_person_and_album_and_song
|
27
|
+
# create the person
|
28
|
+
person = TunecoreDirect::Person.new
|
29
|
+
person.name = "Joe Schmoe"
|
30
|
+
person.email = @email
|
31
|
+
person.password = "my_pas$word"
|
32
|
+
person.phone_number = "212-555-1212"
|
33
|
+
person.country = "United States"
|
34
|
+
person.postal_code = "11201"
|
35
|
+
assert person.create
|
36
|
+
|
37
|
+
# create the album
|
38
|
+
album = TunecoreDirect::Album.new
|
39
|
+
album.name = "My Album"
|
40
|
+
album.person_id = person.person_id
|
41
|
+
album.orig_release_date = "2008-02-23"
|
42
|
+
album.sale_date = "2008-02-23"
|
43
|
+
album.primary_genre = "Rock"
|
44
|
+
album.secondary_genre = "Alternative"
|
45
|
+
album.artist_name = "Alex Kane"
|
46
|
+
album.label_name = "Shochu"
|
47
|
+
album.c_copyright = "1999"
|
48
|
+
album.p_copyright = "1999"
|
49
|
+
album.recording_location = "Bucktown"
|
50
|
+
album.parental_advisory = false
|
51
|
+
album.stores = "iTunesUS,iTunesAU,iTunesCA,iTunesEU,iTunesJP,iTunesEU,RhapsodyRH,MusicNet,Napster,eMusic,Amazon,Lala"
|
52
|
+
created = album.create
|
53
|
+
assert created == true
|
54
|
+
|
55
|
+
#create the song
|
56
|
+
song = TunecoreDirect::Song.new
|
57
|
+
song.album_id = album.album_id
|
58
|
+
song.name = "My song"
|
59
|
+
assert song.save == true
|
60
|
+
|
61
|
+
# get all albums
|
62
|
+
albums = TunecoreDirect::Album.get_all
|
63
|
+
puts albums.inspect
|
64
|
+
assert albums.size > 0
|
65
|
+
|
66
|
+
# takedown the first album
|
67
|
+
album_id = albums.first.album_id
|
68
|
+
assert TunecoreDirect::Album.takedown( album_id ) != nil
|
69
|
+
|
70
|
+
end
|
71
|
+
|
72
|
+
|
73
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tunecore_direct
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex Kane
|
@@ -30,7 +30,7 @@ cert_chain:
|
|
30
30
|
f3TSOQ==
|
31
31
|
-----END CERTIFICATE-----
|
32
32
|
|
33
|
-
date: 2008-04-
|
33
|
+
date: 2008-04-11 00:00:00 -04:00
|
34
34
|
default_executable:
|
35
35
|
dependencies: []
|
36
36
|
|
metadata.gz.sig
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
e�U[S2��,n��TBL`M#��`c�mSIy��Y�|���.W�e��@���0��2~�aR�,@���:��c��-B�J)�5�TV����˱�W���e���O�'�a�r~ꅈa�]����#7
|
2
|
+
iZZ?���~̯==j�uFu�/�-e������g�V[��4a������%V�Cg�6+d�(U���u8㼿��>�ԁ$���)�����ɑ�\.�+9���p���A��o3�M9�^�I�ߢf�<
|