grooveshark 0.2.11 → 0.2.12

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,43 @@
1
+ require_relative '../helper'
2
+
3
+ require 'grooveshark'
4
+
5
+ describe 'Song' do
6
+ it 'should initialize without data' do
7
+ expect(Grooveshark::Song.new.id).to be_nil
8
+ end
9
+
10
+ it 'should initialize with data' do
11
+ song = Grooveshark::Song.new('song_id' => '2',
12
+ 'song_name' => 'Test',
13
+ 'artist_name' => 'Me',
14
+ 'artist_id' => '1337',
15
+ 'album_name' => 'Ruby4Ever',
16
+ 'album_id' => '42',
17
+ 'track_num' => '26',
18
+ 'estimate_duration' => '17',
19
+ 'cover_art_filename' => nil,
20
+ 'song_plays' => nil,
21
+ 'year' => '2015')
22
+
23
+ expect(song.id).to eq('2')
24
+ expect(song.name).to eq('Test')
25
+ expect(song.artist).to eq('Me')
26
+ expect(song.artist_id).to eq('1337')
27
+ expect(song.album).to eq('Ruby4Ever')
28
+ expect(song.track).to eq('26')
29
+ expect(song.duration).to eq('17')
30
+ expect(song.artwork).to be_nil
31
+ expect(song.playcount).to be_nil
32
+ expect(song.year).to eq('2015')
33
+
34
+ expect(song.to_s).to eq('2 - Test - Me')
35
+ expect(song.to_hash).to eq('albumID' => '42',
36
+ 'albumName' => 'Ruby4Ever',
37
+ 'artistID' => '1337',
38
+ 'artistName' => 'Me',
39
+ 'songID' => '2',
40
+ 'songName' => 'Test',
41
+ 'track' => '26')
42
+ end
43
+ end
@@ -0,0 +1,233 @@
1
+ require_relative '../helper'
2
+
3
+ require 'grooveshark'
4
+
5
+ describe 'User' do
6
+ it 'should initialize without data' do
7
+ expect(Grooveshark::User.new(double).id).to be_nil
8
+ end
9
+
10
+ it 'should initialize with data' do
11
+ user = Grooveshark::User.new(double,
12
+ 'user_id' => '1',
13
+ 'f_name' => 'Pierre Rambaud',
14
+ 'is_premium' => '0',
15
+ 'email' => 'pierre.rambaud86@gmail.com',
16
+ 'city' => 'Paris',
17
+ 'country' => 'FR',
18
+ 'sex' => 'M')
19
+ expect(user.id).to eq('1')
20
+ expect(user.name).to eq('Pierre Rambaud')
21
+ expect(user.premium).to eq('0')
22
+ expect(user.email).to eq('pierre.rambaud86@gmail.com')
23
+ expect(user.city).to eq('Paris')
24
+ expect(user.country).to eq('FR')
25
+ expect(user.sex).to eq('M')
26
+ end
27
+
28
+ it 'should return avar url' do
29
+ user = Grooveshark::User.new(double,
30
+ 'user_id' => '2')
31
+ expect(user.avatar)
32
+ .to eq('http://images.grooveshark.com/static/userimages/2.jpg')
33
+ end
34
+
35
+ it 'should retrieve user activiy' do
36
+ client = double
37
+ allow(client).to receive(:request)
38
+ .with('getProcessedUserFeedData',
39
+ userID: '2',
40
+ day: '201411220101')
41
+ .and_return(true)
42
+ user = Grooveshark::User.new(client,
43
+ 'user_id' => '2')
44
+ expect(user.feed(Time.new('20141122')))
45
+ .to eq(true)
46
+ end
47
+
48
+ it 'should not fetch for songs in library if response is empty' do
49
+ client = double
50
+ allow(client).to receive(:request)
51
+ .with('userGetSongsInLibrary',
52
+ userID: '2',
53
+ page: '1')
54
+ .and_return({})
55
+ user = Grooveshark::User.new(client,
56
+ 'user_id' => '2')
57
+ expect(user.library(1))
58
+ .to eq([])
59
+ end
60
+
61
+ it 'should fetch for songs in library' do
62
+ client = double
63
+ allow(client).to receive(:request)
64
+ .with('userGetSongsInLibrary',
65
+ userID: '2',
66
+ page: '1')
67
+ .and_return('songs' => ['song_id' => 1])
68
+ user = Grooveshark::User.new(client,
69
+ 'user_id' => '2')
70
+ expect(user.library(1).first)
71
+ .to be_a(Grooveshark::Song)
72
+ end
73
+
74
+ it 'should add song to user library' do
75
+ song = Grooveshark::Song.new
76
+ client = double
77
+ allow(client).to receive(:request)
78
+ .with('userAddSongsToLibrary',
79
+ songs: [song.to_hash])
80
+ .and_return(true)
81
+
82
+ user = Grooveshark::User.new(client,
83
+ 'user_id' => '2')
84
+ expect(user.library_add([song]))
85
+ .to eq(true)
86
+ end
87
+
88
+ it 'should raise error when library does not receive Song' do
89
+ user = Grooveshark::User.new(double)
90
+ expect { user.library_remove('something') }
91
+ .to raise_error(ArgumentError)
92
+ end
93
+
94
+ it 'should remove song from user library' do
95
+ song = Grooveshark::Song.new('song_id' => '42',
96
+ 'album_id' => '43',
97
+ 'artist_id' => '44')
98
+ client = double
99
+ allow(client).to receive(:request)
100
+ .with('userRemoveSongFromLibrary',
101
+ userID: '2',
102
+ songID: '42',
103
+ albumID: '43',
104
+ artistID: '44')
105
+ .and_return(true)
106
+
107
+ user = Grooveshark::User.new(client,
108
+ 'user_id' => '2')
109
+ expect(user.library_remove(song))
110
+ .to eq(true)
111
+ end
112
+
113
+ it 'should retrieve library timestamp' do
114
+ client = double
115
+ allow(client).to receive(:request)
116
+ .with('userGetLibraryTSModified',
117
+ userID: '2')
118
+ .and_return(true)
119
+
120
+ user = Grooveshark::User.new(client,
121
+ 'user_id' => '2')
122
+ expect(user.library_ts_modified)
123
+ .to eq(true)
124
+ end
125
+
126
+ it 'should list user playlists and retrieve playlist from id' do
127
+ client = double
128
+ allow(client).to receive(:request)
129
+ .with('userGetPlaylists',
130
+ userID: '2')
131
+ .and_return('playlists' => ['playlist_id' => '1337'])
132
+
133
+ user = Grooveshark::User.new(client,
134
+ 'user_id' => '2')
135
+ expect(user.playlists).to be_a(Array)
136
+ expect(user.playlists.first).to be_a(Grooveshark::Playlist)
137
+ expect(user.playlists.first.id).to eq('1337')
138
+ expect(user.playlists.first.user_id).to eq('2')
139
+
140
+ expect(user.get_playlist('1337')).to be_a(Grooveshark::Playlist)
141
+ expect(user.get_playlist('1337').id).to eq('1337')
142
+ expect(user.get_playlist('1337').user_id).to eq('2')
143
+
144
+ expect(user.get_playlist('42')).to be_nil
145
+ end
146
+
147
+ it 'should create playlist' do
148
+ client = double
149
+ allow(client).to receive(:request)
150
+ .with('createPlaylist',
151
+ 'playlistName' => 'GoT',
152
+ 'playlistAbout' => 'Description',
153
+ 'songIDs' => %w(10 11))
154
+ .and_return(true)
155
+
156
+ user = Grooveshark::User.new(client,
157
+ 'user_id' => '2')
158
+ expect(user.create_playlist('GoT',
159
+ 'Description',
160
+ [Grooveshark::Song.new('song_id' => '10'),
161
+ 11]))
162
+ .to eq(true)
163
+ end
164
+
165
+ it 'should return favorites songs' do
166
+ client = double
167
+ allow(client).to receive(:request)
168
+ .with('getFavorites',
169
+ ofWhat: 'Songs',
170
+ userID: '2')
171
+ .and_return(['song_id' => '42'])
172
+
173
+ user = Grooveshark::User.new(client,
174
+ 'user_id' => '2')
175
+ expect(user.favorites).to be_a(Array)
176
+ expect(user.favorites.first).to be_a(Grooveshark::Song)
177
+ expect(user.favorites.first.id).to eq('42')
178
+ end
179
+
180
+ it 'should add favorite song with song object parameter' do
181
+ client = double
182
+ allow(client).to receive(:request)
183
+ .with('favorite',
184
+ what: 'Song',
185
+ ID: '2')
186
+ .and_return(true)
187
+
188
+ user = Grooveshark::User.new(client,
189
+ 'user_id' => '2')
190
+ expect(user.add_favorite(Grooveshark::Song.new('song_id' => '2')))
191
+ .to eq(true)
192
+ end
193
+
194
+ it 'should add favorite song with string parameter' do
195
+ client = double
196
+ allow(client).to receive(:request)
197
+ .with('favorite',
198
+ what: 'Song',
199
+ ID: '2')
200
+ .and_return(true)
201
+
202
+ user = Grooveshark::User.new(client,
203
+ 'user_id' => '2')
204
+ expect(user.add_favorite('2')).to eq(true)
205
+ end
206
+
207
+ it 'should remove favorite songs with song object parameter' do
208
+ client = double
209
+ allow(client).to receive(:request)
210
+ .with('unfavorite',
211
+ what: 'Song',
212
+ ID: '2')
213
+ .and_return(true)
214
+
215
+ user = Grooveshark::User.new(client,
216
+ 'user_id' => '2')
217
+ expect(user.remove_favorite(Grooveshark::Song.new('song_id' => '2')))
218
+ .to eq(true)
219
+ end
220
+
221
+ it 'should remove favorite songs with string parameter' do
222
+ client = double
223
+ allow(client).to receive(:request)
224
+ .with('unfavorite',
225
+ what: 'Song',
226
+ ID: '2')
227
+ .and_return(true)
228
+
229
+ user = Grooveshark::User.new(client,
230
+ 'user_id' => '2')
231
+ expect(user.remove_favorite('2')).to eq(true)
232
+ end
233
+ end
@@ -0,0 +1,38 @@
1
+ require_relative '../helper'
2
+
3
+ require 'grooveshark'
4
+
5
+ describe 'String' do
6
+ it 'should normalize attributes' do
7
+ vars = %w(key_name keyName KeyName KeyNAME)
8
+ target = 'key_name'
9
+ vars.each { |s| expect(s.normalize_attribute).to eq(target) }
10
+ end
11
+ end
12
+
13
+ describe 'Hash' do
14
+ it 'should normalize simple keys' do
15
+ h = { 'KeyName' => 'Value' }.normalize
16
+
17
+ expect(h.key?('KeyName')).to be_falsy
18
+ expect(h.key?('key_name')).to eq(true)
19
+ end
20
+
21
+ it 'should normalize symbol keys' do
22
+ h = { KeyName: 'Value' }
23
+ expect(h[:KeyName]).to eq('Value')
24
+ expect(h.normalize.key?(:KeyName)).to be_falsy
25
+ expect(h.normalize.key?('key_name')).to eq(true)
26
+ end
27
+
28
+ it 'should normalize nested data' do
29
+ h = {
30
+ 'keyA' => { 'nestedKey' => 'Value' },
31
+ 'keyB' => [{ 'arrKey' => 'Value' }]
32
+ }.normalize
33
+
34
+ expect(h['key_a'].key?('nested_key')).to eq(true)
35
+ expect(h['key_b']).to be_a(Array)
36
+ expect(h['key_b'].first.key?('arr_key')).to eq(true)
37
+ end
38
+ end
@@ -1,3 +1,8 @@
1
- $:.unshift File.expand_path("../..", __FILE__)
1
+ # -*- coding: utf-8 -*-
2
+ $LOAD_PATH << File.expand_path('../lib', __FILE__)
2
3
 
3
- require 'grooveshark'
4
+ require 'simplecov'
5
+
6
+ SimpleCov.start do
7
+ add_filter '/spec/'
8
+ end
metadata CHANGED
@@ -1,93 +1,151 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grooveshark
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.11
4
+ version: 0.2.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dan Sosedoff
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-21 00:00:00.000000000 Z
11
+ date: 2014-12-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: rspec
14
+ name: json
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '2.12'
20
- type: :development
19
+ version: 1.4.6
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 1.4.6
27
+ - !ruby/object:Gem::Dependency
28
+ name: rest-client
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 1.5.1
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 1.5.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: uuid
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.0'
48
+ type: :runtime
21
49
  prerelease: false
22
50
  version_requirements: !ruby/object:Gem::Requirement
23
51
  requirements:
24
- - - ~>
52
+ - - "~>"
25
53
  - !ruby/object:Gem::Version
26
- version: '2.12'
54
+ version: '2.0'
27
55
  - !ruby/object:Gem::Dependency
28
56
  name: rake
29
57
  requirement: !ruby/object:Gem::Requirement
30
58
  requirements:
31
- - - ~>
59
+ - - "~>"
32
60
  - !ruby/object:Gem::Version
33
61
  version: '10.0'
34
62
  type: :development
35
63
  prerelease: false
36
64
  version_requirements: !ruby/object:Gem::Requirement
37
65
  requirements:
38
- - - ~>
66
+ - - "~>"
39
67
  - !ruby/object:Gem::Version
40
68
  version: '10.0'
41
69
  - !ruby/object:Gem::Dependency
42
- name: json
70
+ name: rack-test
43
71
  requirement: !ruby/object:Gem::Requirement
44
72
  requirements:
45
- - - '>='
73
+ - - "~>"
46
74
  - !ruby/object:Gem::Version
47
- version: 1.4.6
48
- type: :runtime
75
+ version: '0.6'
76
+ type: :development
49
77
  prerelease: false
50
78
  version_requirements: !ruby/object:Gem::Requirement
51
79
  requirements:
52
- - - '>='
80
+ - - "~>"
53
81
  - !ruby/object:Gem::Version
54
- version: 1.4.6
82
+ version: '0.6'
55
83
  - !ruby/object:Gem::Dependency
56
- name: rest-client
84
+ name: rspec
57
85
  requirement: !ruby/object:Gem::Requirement
58
86
  requirements:
59
- - - '>='
87
+ - - "~>"
60
88
  - !ruby/object:Gem::Version
61
- version: 1.5.1
62
- type: :runtime
89
+ version: '3.0'
90
+ type: :development
63
91
  prerelease: false
64
92
  version_requirements: !ruby/object:Gem::Requirement
65
93
  requirements:
66
- - - '>='
94
+ - - "~>"
67
95
  - !ruby/object:Gem::Version
68
- version: 1.5.1
96
+ version: '3.0'
69
97
  - !ruby/object:Gem::Dependency
70
- name: uuid
98
+ name: simplecov
71
99
  requirement: !ruby/object:Gem::Requirement
72
100
  requirements:
73
- - - ~>
101
+ - - "~>"
74
102
  - !ruby/object:Gem::Version
75
- version: '2.0'
76
- type: :runtime
103
+ version: '0.9'
104
+ type: :development
77
105
  prerelease: false
78
106
  version_requirements: !ruby/object:Gem::Requirement
79
107
  requirements:
80
- - - ~>
108
+ - - "~>"
81
109
  - !ruby/object:Gem::Version
82
- version: '2.0'
110
+ version: '0.9'
111
+ - !ruby/object:Gem::Dependency
112
+ name: fakefs
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '0.5'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '0.5'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rubocop
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '0.25'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '0.25'
83
139
  description: Unofficial ruby library for consuming the Grooveshark API.
84
140
  email: dan.sosedoff@gmail.com
85
141
  executables: []
86
142
  extensions: []
87
143
  extra_rdoc_files: []
88
144
  files:
89
- - .gitignore
90
- - .rspec
145
+ - ".gitignore"
146
+ - ".rspec"
147
+ - ".rubocop.yml"
148
+ - ".travis.yml"
91
149
  - Gemfile
92
150
  - LICENSE
93
151
  - README.md
@@ -102,10 +160,14 @@ files:
102
160
  - lib/grooveshark/user.rb
103
161
  - lib/grooveshark/utils.rb
104
162
  - lib/grooveshark/version.rb
105
- - spec/broadcast_spec.rb
106
- - spec/client_spec.rb
163
+ - spec/grooveshark/broadcast_spec.rb
164
+ - spec/grooveshark/client_spec.rb
165
+ - spec/grooveshark/errors_spec.rb
166
+ - spec/grooveshark/playlist_spec.rb
167
+ - spec/grooveshark/song_spec.rb
168
+ - spec/grooveshark/user_spec.rb
169
+ - spec/grooveshark/utils_spec.rb
107
170
  - spec/helper.rb
108
- - spec/utils_spec.rb
109
171
  homepage: http://github.com/sosedoff/grooveshark
110
172
  licenses:
111
173
  - MIT
@@ -116,22 +178,26 @@ require_paths:
116
178
  - lib
117
179
  required_ruby_version: !ruby/object:Gem::Requirement
118
180
  requirements:
119
- - - '>='
181
+ - - ">="
120
182
  - !ruby/object:Gem::Version
121
183
  version: '0'
122
184
  required_rubygems_version: !ruby/object:Gem::Requirement
123
185
  requirements:
124
- - - '>='
186
+ - - ">="
125
187
  - !ruby/object:Gem::Version
126
188
  version: '0'
127
189
  requirements: []
128
190
  rubyforge_project:
129
- rubygems_version: 2.0.5
191
+ rubygems_version: 2.4.5
130
192
  signing_key:
131
193
  specification_version: 4
132
194
  summary: Grooveshark API
133
195
  test_files:
134
- - spec/broadcast_spec.rb
135
- - spec/client_spec.rb
196
+ - spec/grooveshark/broadcast_spec.rb
197
+ - spec/grooveshark/client_spec.rb
198
+ - spec/grooveshark/errors_spec.rb
199
+ - spec/grooveshark/playlist_spec.rb
200
+ - spec/grooveshark/song_spec.rb
201
+ - spec/grooveshark/user_spec.rb
202
+ - spec/grooveshark/utils_spec.rb
136
203
  - spec/helper.rb
137
- - spec/utils_spec.rb