soundcloud-ruby-api-wrapper 0.3.3 → 0.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION.yml +1 -1
- data/lib/soundcloud/models/base.rb +24 -1
- data/lib/soundcloud/models/playlist.rb +22 -0
- data/lib/soundcloud/models/track.rb +9 -23
- data/ruby-api-wrapper.gemspec +3 -2
- data/spec/fixtures/test_artwork.gif +0 -0
- data/spec/soundcloud_playlist_spec.rb +19 -0
- data/spec/soundcloud_track_spec.rb +69 -2
- metadata +3 -2
data/VERSION.yml
CHANGED
@@ -4,6 +4,29 @@ module Soundcloud
|
|
4
4
|
# self.site = 'http://api.soundcloud.dev'
|
5
5
|
|
6
6
|
|
7
|
+
def send_files(method,path,resource)
|
8
|
+
params = ActiveSupport::OrderedHash.new
|
9
|
+
self.attributes.reject { |k,v| data_attributes.include?(k)}.each { |k,v|
|
10
|
+
params["#{resource}[#{k}]".to_sym] = v
|
11
|
+
}
|
12
|
+
|
13
|
+
# ignore is added because the multipart gem is adding an extra new line
|
14
|
+
# to the last parameter which will break parsing of track[sharing]
|
15
|
+
params[:ignore] = 'multipart bug'
|
16
|
+
|
17
|
+
files = {}
|
18
|
+
data_attributes.each do |attr|
|
19
|
+
files["#{resource}[#{attr}]".to_sym] = self.attributes[attr] if self.attributes.has_key?(attr)
|
20
|
+
self.attributes[attr] = nil
|
21
|
+
end
|
22
|
+
|
23
|
+
response = connection.handle_response(self.class.send_multipart_request(method,path,files,params))
|
24
|
+
|
25
|
+
self.id = id_from_response(response)
|
26
|
+
load_attributes_from_response(response)
|
27
|
+
|
28
|
+
end
|
29
|
+
|
7
30
|
# has_many_single_changeable and can_be_a_single_changeable is mostly used in combination with has_many.
|
8
31
|
#
|
9
32
|
# can_be_a_single_changeable expects to have a resource /me which is the logged-in user
|
@@ -39,7 +62,7 @@ module Soundcloud
|
|
39
62
|
#
|
40
63
|
# friend.has_friend?(stranger.id)
|
41
64
|
# => checks if stranger and friend are friend, returns true or false
|
42
|
-
|
65
|
+
|
43
66
|
def self.can_be_a_single_changeable(*args)
|
44
67
|
args.each do |k|
|
45
68
|
singular = k.to_s
|
@@ -41,6 +41,8 @@ module Soundcloud
|
|
41
41
|
class Playlist < Base
|
42
42
|
belongs_to :user
|
43
43
|
# has_many :permissions
|
44
|
+
cattr_accessor :data_attributes
|
45
|
+
self.data_attributes = ['artwork_data']
|
44
46
|
cattr_accessor :element_name
|
45
47
|
self.element_name = 'playlist'
|
46
48
|
def initialize(*args)
|
@@ -48,6 +50,26 @@ module Soundcloud
|
|
48
50
|
#create empty tracks array if not existing
|
49
51
|
attributes['tracks'] = Array.new if not self.tracks?
|
50
52
|
end
|
53
|
+
|
54
|
+
def update
|
55
|
+
if data_attributes.all? { |attr| self.attributes[attr].nil? }
|
56
|
+
super
|
57
|
+
else
|
58
|
+
send_files(:put,"/playlists/#{self.id}",'playlist')
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def create
|
63
|
+
if data_attributes.all? { |attr| self.attributes[attr].nil? }
|
64
|
+
super
|
65
|
+
else
|
66
|
+
# default to private
|
67
|
+
if self.sharing?.nil?
|
68
|
+
self.sharing = 'private'
|
69
|
+
end
|
70
|
+
send_files(:post,'/playlists', 'playlist')
|
71
|
+
end
|
72
|
+
end
|
51
73
|
end
|
52
74
|
end
|
53
75
|
end
|
@@ -85,7 +85,9 @@ module Soundcloud
|
|
85
85
|
belongs_to :user
|
86
86
|
has_many :permissions, :comments
|
87
87
|
can_be_a_single_changeable :favorite
|
88
|
-
|
88
|
+
cattr_accessor :data_attributes
|
89
|
+
self.data_attributes = ['asset_data', 'artwork_data']
|
90
|
+
|
89
91
|
cattr_accessor :element_name
|
90
92
|
self.element_name = 'track'
|
91
93
|
|
@@ -111,38 +113,22 @@ module Soundcloud
|
|
111
113
|
end
|
112
114
|
|
113
115
|
def update
|
114
|
-
|
115
|
-
|
116
|
-
|
116
|
+
if data_attributes.all? { |attr| self.attributes[attr].nil? }
|
117
|
+
super
|
118
|
+
else
|
119
|
+
send_files(:put,"/tracks/#{self.id}",'track')
|
117
120
|
end
|
118
|
-
super
|
119
121
|
end
|
120
122
|
|
121
123
|
def create
|
122
|
-
if self.
|
124
|
+
if data_attributes.all? { |attr| self.attributes[attr].nil? }
|
123
125
|
super
|
124
126
|
else
|
125
|
-
#post asset_data
|
126
|
-
|
127
127
|
# default to private
|
128
128
|
if self.sharing?.nil?
|
129
129
|
self.sharing = 'private'
|
130
130
|
end
|
131
|
-
|
132
|
-
params = ActiveSupport::OrderedHash.new
|
133
|
-
self.attributes.reject { |k,v| k.to_s == 'asset_data'}.each { |k,v|
|
134
|
-
params["track[#{k}]".to_sym] = v
|
135
|
-
}
|
136
|
-
|
137
|
-
# ignore is added because the multipart gem is adding an extra new line
|
138
|
-
# to the last parameter which will break parsing of track[sharing]
|
139
|
-
params[:ignore] = 'multipart bug'
|
140
|
-
|
141
|
-
response = connection.handle_response(self.class.send_multipart_request(:post,'/tracks','track[asset_data]',self.asset_data,params))
|
142
|
-
|
143
|
-
self.id = id_from_response(response)
|
144
|
-
load_attributes_from_response(response)
|
145
|
-
self.asset_data = nil
|
131
|
+
send_files(:post,'/tracks','track')
|
146
132
|
end
|
147
133
|
end
|
148
134
|
end
|
data/ruby-api-wrapper.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{ruby-api-wrapper}
|
5
|
-
s.version = "0.3.
|
5
|
+
s.version = "0.3.4"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Johannes Wagener"]
|
9
|
-
s.date = %q{2009-
|
9
|
+
s.date = %q{2009-09-03}
|
10
10
|
s.email = %q{johannes@wagener.cc}
|
11
11
|
s.extra_rdoc_files = [
|
12
12
|
"LICENSE",
|
@@ -29,6 +29,7 @@ Gem::Specification.new do |s|
|
|
29
29
|
"lib/soundcloud/models/track.rb",
|
30
30
|
"lib/soundcloud/models/user.rb",
|
31
31
|
"ruby-api-wrapper.gemspec",
|
32
|
+
"spec/fixtures/test_artwork.gif",
|
32
33
|
"spec/fixtures/test_track.mp3",
|
33
34
|
"spec/soundcloud_comment_spec.rb",
|
34
35
|
"spec/soundcloud_event_spec.rb",
|
Binary file
|
@@ -43,4 +43,23 @@ describe 'Soundcloud::Models::Playlist' do
|
|
43
43
|
pl.user.online.should_not be nil
|
44
44
|
end
|
45
45
|
|
46
|
+
|
47
|
+
it "should be able to update a playlist artwork" do
|
48
|
+
test_artwork_file = File.new( File.dirname(__FILE__) + '/fixtures/test_artwork.gif')
|
49
|
+
playlist = @sc.Playlist.find('my-static-playlist')
|
50
|
+
old_artwork = playlist.artwork_url
|
51
|
+
playlist.artwork_data = test_artwork_file
|
52
|
+
|
53
|
+
playlist.save
|
54
|
+
playlist.artwork_url.should_not == old_artwork
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should be able to create a new playlist with artwork" do
|
58
|
+
#track = @sc.Track.find('static-test-track')
|
59
|
+
test_artwork_file = File.new( File.dirname(__FILE__) + '/fixtures/test_artwork.gif')
|
60
|
+
|
61
|
+
playlist = @sc.Playlist.create({:title => 'test', :artwork_data => test_artwork_file})
|
62
|
+
playlist.artwork_url.should_not == nil
|
63
|
+
#playlist.destroy
|
64
|
+
end
|
46
65
|
end
|
@@ -25,6 +25,7 @@ describe "Soundcloud::Models::Track" do
|
|
25
25
|
|
26
26
|
end
|
27
27
|
|
28
|
+
|
28
29
|
it "should be able to create a new track and default to sharing=private" do
|
29
30
|
test_track_file = File.new( File.dirname(__FILE__) + '/fixtures/test_track.mp3')
|
30
31
|
track = @sc.Track.create({:title => "test", :asset_data => test_track_file})
|
@@ -33,6 +34,15 @@ describe "Soundcloud::Models::Track" do
|
|
33
34
|
track.destroy
|
34
35
|
end
|
35
36
|
|
37
|
+
it "should be able to create a new track with artwork" do
|
38
|
+
test_track_file = File.new( File.dirname(__FILE__) + '/fixtures/test_track.mp3')
|
39
|
+
test_artwork_file = File.new( File.dirname(__FILE__) + '/fixtures/test_artwork.gif')
|
40
|
+
track = @sc.Track.create({:title => "test", :asset_data => test_track_file, :artwork_data => test_artwork_file})
|
41
|
+
|
42
|
+
track.artwork_url.should_not == nil
|
43
|
+
track.destroy
|
44
|
+
end
|
45
|
+
|
36
46
|
it "should be able to create a new public track and sharing should stay public" do
|
37
47
|
test_track_file = File.new( File.dirname(__FILE__) + '/fixtures/test_track.mp3')
|
38
48
|
track = @sc.Track.create({:title => "test", :sharing => 'public', :asset_data => test_track_file})
|
@@ -41,6 +51,17 @@ describe "Soundcloud::Models::Track" do
|
|
41
51
|
track.destroy
|
42
52
|
end
|
43
53
|
|
54
|
+
it "should be able to update a track artwork" do
|
55
|
+
test_artwork_file = File.new( File.dirname(__FILE__) + '/fixtures/test_artwork.gif')
|
56
|
+
track = @sc.Track.find('static-test-track')
|
57
|
+
old_artwork = track.artwork_url
|
58
|
+
track.artwork_data = test_artwork_file
|
59
|
+
|
60
|
+
track.save
|
61
|
+
track.artwork_url.should_not == old_artwork
|
62
|
+
end
|
63
|
+
|
64
|
+
|
44
65
|
it 'should be able to create a new track and remove it' do
|
45
66
|
test_track_file = File.new(File.dirname(__FILE__) + '/fixtures/test_track.mp3')
|
46
67
|
|
@@ -57,15 +78,61 @@ describe "Soundcloud::Models::Track" do
|
|
57
78
|
|
58
79
|
it 'should be able to update an attribute' do
|
59
80
|
track = @sc.Track.find('static-test-track')
|
81
|
+
time = Time.now
|
82
|
+
track.title = "T #{time}"
|
83
|
+
track.save
|
84
|
+
track.title = 'something else'
|
85
|
+
|
86
|
+
track.reload
|
60
87
|
|
61
|
-
track.title
|
88
|
+
track.title.should == "T #{time}"
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'should be able to update tag_list directly' do
|
92
|
+
track = @sc.Track.find('static-test-track')
|
93
|
+
time = Time.now
|
94
|
+
track.tag_list = "T#{time} B#{time}"
|
62
95
|
track.save
|
96
|
+
track.tag_list = 'something else'
|
63
97
|
|
64
98
|
track.reload
|
65
99
|
|
66
|
-
track.
|
100
|
+
track.tag_list.should == "T#{time} B#{time}"
|
67
101
|
end
|
68
102
|
|
103
|
+
# it 'should be able to read the tags array' do
|
104
|
+
# track = @sc.Track.new
|
105
|
+
#
|
106
|
+
# track.tag_list = "bla blub"
|
107
|
+
#
|
108
|
+
# track.tags.include?('bla').should == true
|
109
|
+
# track.tags.include?('blub').should == true
|
110
|
+
# end
|
111
|
+
#
|
112
|
+
#
|
113
|
+
# it 'should be able to write to the tags array' do
|
114
|
+
# track = @sc.Track.new
|
115
|
+
#
|
116
|
+
# track.tags << 'bla'
|
117
|
+
# track.tags << 'blub'
|
118
|
+
#
|
119
|
+
# track.tag_list.should == "bla blub"
|
120
|
+
# end
|
121
|
+
|
122
|
+
#it 'should be able to update the tags array' do
|
123
|
+
# track = @sc.Track.find('static-test-track')
|
124
|
+
# time = Time.now
|
125
|
+
# track.tags << "'bl ub'"
|
126
|
+
# track.save
|
127
|
+
# track.tags.include?("'bl ub'").should == true
|
128
|
+
#
|
129
|
+
# track.tags.delete('')
|
130
|
+
#
|
131
|
+
# #reload
|
132
|
+
# #tag_list.should_contain
|
133
|
+
# #tags.include? 'bla
|
134
|
+
#end
|
135
|
+
|
69
136
|
it 'should be able to add a user to permissions of a track and delete it again' do
|
70
137
|
track = @sc.Track.find(:one, :from => '/users/api-test-1/tracks/static-test-track')
|
71
138
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: soundcloud-ruby-api-wrapper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Johannes Wagener
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-09-03 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -58,6 +58,7 @@ files:
|
|
58
58
|
- lib/soundcloud/models/track.rb
|
59
59
|
- lib/soundcloud/models/user.rb
|
60
60
|
- ruby-api-wrapper.gemspec
|
61
|
+
- spec/fixtures/test_artwork.gif
|
61
62
|
- spec/fixtures/test_track.mp3
|
62
63
|
- spec/soundcloud_comment_spec.rb
|
63
64
|
- spec/soundcloud_event_spec.rb
|