wimp 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +18 -0
  3. data/.rspec +5 -0
  4. data/Gemfile +4 -0
  5. data/LICENSE.txt +22 -0
  6. data/README.md +154 -0
  7. data/Rakefile +6 -0
  8. data/lib/gen/README.md +6 -0
  9. data/lib/gen/client_api_login_service.rb +270 -0
  10. data/lib/gen/client_api_service.rb +3016 -0
  11. data/lib/gen/services_constants.rb +13 -0
  12. data/lib/gen/services_types.rb +1035 -0
  13. data/lib/wimp.rb +66 -0
  14. data/lib/wimp/base.rb +30 -0
  15. data/lib/wimp/error.rb +4 -0
  16. data/lib/wimp/playlist.rb +93 -0
  17. data/lib/wimp/simple_artist.rb +10 -0
  18. data/lib/wimp/track.rb +91 -0
  19. data/lib/wimp/version.rb +3 -0
  20. data/resources/skipped-methods.md +44 -0
  21. data/resources/thrift/services.thrift +396 -0
  22. data/spec/fixtures/vcr_cassettes/WiMP_Playlist/should_add_my_track_id.yml +263 -0
  23. data/spec/fixtures/vcr_cassettes/WiMP_Playlist/should_be_able_to_add_tracks_to_playlist.yml +445 -0
  24. data/spec/fixtures/vcr_cassettes/WiMP_Playlist/should_be_able_to_remove_tracks.yml +452 -0
  25. data/spec/fixtures/vcr_cassettes/WiMP_Playlist/should_create_a_playlist.yml +98 -0
  26. data/spec/fixtures/vcr_cassettes/WiMP_Playlist/should_find_by_uuid.yml +49 -0
  27. data/spec/fixtures/vcr_cassettes/WiMP_Playlist/should_not_crash_on_invalid_pos.yml +372 -0
  28. data/spec/fixtures/vcr_cassettes/WiMP_Track/.yml +169 -0
  29. data/spec/fixtures/vcr_cassettes/WiMP_Track/should_be_searchable.yml +169 -0
  30. data/spec/fixtures/vcr_cassettes/WiMP_Track/should_paginate.yml +61 -0
  31. data/spec/fixtures/vcr_cassettes/login/should_raise_error_using_invalid_credentials.yml +47 -0
  32. data/spec/fixtures/vcr_cassettes/login/should_return_sesson_id_on_successfull_login.yml +53 -0
  33. data/spec/login_spec.rb +21 -0
  34. data/spec/playlist_spec.rb +37 -0
  35. data/spec/spec_helper.rb +19 -0
  36. data/spec/track_spec.rb +26 -0
  37. data/wimp.gemspec +30 -0
  38. metadata +207 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 33f696af3b35c37758582a083c1819ca8018bd5e
4
+ data.tar.gz: 9900a5d12eb6860e89ee257c2e4a4d12caf158a8
5
+ SHA512:
6
+ metadata.gz: e31aac6e779ded4353db920af4090919028bb891ce7317730d11fe4dd898501b3f37d2e2ce23f7633c3a06c0cc06573f5602bcaf8d8d1071bdba8e4ed1c7daf6
7
+ data.tar.gz: 37183d695c5193fe32f57d108c7967c4242c0da55d95dd01b8edc188062700667e83c3beb3e633500ea59cbe0d204373405253adb245bc18f65648a8839c166f
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .rake_tasks~
data/.rspec ADDED
@@ -0,0 +1,5 @@
1
+ --color
2
+ -fs
3
+ -Ilib
4
+ -Ispec
5
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in wimp.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Linus Oleander
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,154 @@
1
+ # WiMP
2
+
3
+ Ruby bindings for [WiMP](http://wimpmusic.com). The library uses WiMPs
4
+ internal RPC API. Take a look at the [FAQ](#faq) for frequently asked
5
+ questions and how to port this library to any language using
6
+ [thrift](http://thrift.apache.org/).
7
+
8
+ ## Installation
9
+
10
+ ```
11
+ $ gem install wimp
12
+ ```
13
+
14
+ ## Usage
15
+
16
+ Keep in mind that you need premium acount for this to work.
17
+
18
+ ``` ruby
19
+ WiMP.configure do |config|
20
+ config.username = "email@example.com"
21
+ config.password = "my-password"
22
+ end
23
+ ```
24
+
25
+ ### WiMP::Track
26
+
27
+ #### Search
28
+
29
+ ``` ruby
30
+ tracks = WiMP::Track.search(query, {
31
+ limit: 10
32
+ })
33
+ ```
34
+
35
+ ### WiMP::Playlist
36
+
37
+ Note that you can only read and update your own playlists,
38
+ not someone else's.
39
+
40
+ #### Find a playlist
41
+
42
+ ``` ruby
43
+ playlist = WiMP::Playlist.find(uuid)
44
+ ```
45
+
46
+ #### Create a playlist
47
+
48
+ ``` ruby
49
+ playlist = WiMP::Playlist.create(title)
50
+ ```
51
+
52
+ #### Add tracks to playlist
53
+
54
+ ``` ruby
55
+ status = playlist.add_tracks(tracks, {
56
+ start_position: 1
57
+ })
58
+ ```
59
+
60
+ #### Add tracks to playlist using Track#id
61
+
62
+ ``` ruby
63
+ status = playlist.add_tracks_by_id(track_ids, {
64
+ start_position: 1
65
+ })
66
+ ```
67
+
68
+ #### Remove tracks from playlist
69
+
70
+ ``` ruby
71
+ status = playlist.remove_tracks_by_indices(tracks)
72
+ ```
73
+
74
+ ## Containers
75
+
76
+ ### WiMP::Track
77
+
78
+ - title **String**
79
+ - album_id **Integer**
80
+ - duration **Integer**
81
+ - id **Integer**
82
+ - popularity **Integer**
83
+ - artist **WiMP::SimpleArtist**
84
+ - url **String**
85
+
86
+ ### WiMP::Playlist
87
+
88
+ - count **Integer**
89
+ - url **String**
90
+ - tracks **Array< WiMP::Track >**
91
+ - uuid **String**
92
+ - id **Integer**
93
+
94
+ ### WiMP::SimpleArtist
95
+
96
+ - id **Integer**
97
+ - name **String**
98
+ - url **String**
99
+
100
+ ## FAQ
101
+
102
+ ### Can I port this library to language X?
103
+
104
+ Probably. WiMP uses [thrift](http://thrift.apache.org/) behind the scene,
105
+ which means that code for C++, C#, Erlang, Haskell, Java, Objective
106
+ C/Cocoa, OCaml, Perl, PHP, Python, and Squeak can be generated. Take a look
107
+ at the `resources/thrift` folder and the `Rakefile` file for more
108
+ information on how this could be done.
109
+
110
+ [Here is a good thrift tutorial](http://diwakergupta.github.io/thrift-missing-guide/)
111
+ that explains the basics.
112
+
113
+ ### Can I stream music using this library?
114
+
115
+ The WiMP API has support for streaming, but I've chosen not to include
116
+ those methods.
117
+
118
+ ### Where is the rest of the implementation?
119
+
120
+ Take a look at the `lib/gen` folder for more, undocumented code. Code
121
+ exists for all 50 some methods in the thirft directory, but only a few are
122
+ ported to a Ruby-friendly syntax and documented above. You're more than
123
+ welcome to help me migrate all these methods.
124
+
125
+ Some methods from the offical API isn't ported to thrift. You'll find a list
126
+ of these in the `resources/skipped-methods.md` file.
127
+
128
+ ### I'm get an `Thrift::ApplicationException` error
129
+
130
+ The `Thrift::ApplicationException` error indicates that the returning data
131
+ from WiMP isn't what we think it is. It's usually caused by invalid data being passed
132
+ to thrift.
133
+
134
+ In other words; check the data being passed from this library. Is it correct?
135
+
136
+ ## Notes
137
+
138
+ 1. Not all methods existing in the offical API are documented above, but
139
+ the code for all of them exists. Navigate the `lib` folder for more information.
140
+ 2. The first request to the API will be slower than the rest.
141
+ That's because a session is created.
142
+ 3. None of the credentials in this project are my own. They're
143
+ only created to be used in the specs. They might therefore already
144
+ be expired when you read this.
145
+ 4. This library has been created for educational purposes. You shouldn't
146
+ use it without first consulting WiMP.
147
+
148
+ ## Contributing
149
+
150
+ 1. Fork it ( http://github.com/oleander/wimp-api-rb/fork )
151
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
152
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
153
+ 4. Push to the branch (`git push origin my-new-feature`)
154
+ 5. Create new Pull Request
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ desc "Regenerates classes using thrift"
4
+ task :thrift do
5
+ puts `thrift --gen rb -out lib/gen -v resources/thrift/services.thrift`
6
+ end
@@ -0,0 +1,6 @@
1
+ # Thrift Compiler info
2
+
3
+ This code is autogenerated by the Thrift Compiler.
4
+ Do not edit this code. You should instead edit the
5
+ thrift files in `resources/thrift`. To update your
6
+ changes run `rake thrift` in the home folder of this project.
@@ -0,0 +1,270 @@
1
+ #
2
+ # Autogenerated by Thrift Compiler (0.9.1)
3
+ #
4
+ # DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
5
+ #
6
+
7
+ require 'thrift'
8
+ require 'services_types'
9
+
10
+ module WiMP
11
+ module Gen
12
+ module ClientApiLoginService
13
+ class Client
14
+ include ::Thrift::Client
15
+
16
+ def getClientConfig(partnerUsername, partnerPassword, clientName)
17
+ send_getClientConfig(partnerUsername, partnerPassword, clientName)
18
+ return recv_getClientConfig()
19
+ end
20
+
21
+ def send_getClientConfig(partnerUsername, partnerPassword, clientName)
22
+ send_message('getClientConfig', GetClientConfig_args, :partnerUsername => partnerUsername, :partnerPassword => partnerPassword, :clientName => clientName)
23
+ end
24
+
25
+ def recv_getClientConfig()
26
+ result = receive_message(GetClientConfig_result)
27
+ return result.success unless result.success.nil?
28
+ raise ::Thrift::ApplicationException.new(::Thrift::ApplicationException::MISSING_RESULT, 'getClientConfig failed: unknown result')
29
+ end
30
+
31
+ def simpleLogin(userName, password, partnerUsername, partnerPassword, clientName, clientUniqueKey)
32
+ send_simpleLogin(userName, password, partnerUsername, partnerPassword, clientName, clientUniqueKey)
33
+ return recv_simpleLogin()
34
+ end
35
+
36
+ def send_simpleLogin(userName, password, partnerUsername, partnerPassword, clientName, clientUniqueKey)
37
+ send_message('simpleLogin', SimpleLogin_args, :userName => userName, :password => password, :partnerUsername => partnerUsername, :partnerPassword => partnerPassword, :clientName => clientName, :clientUniqueKey => clientUniqueKey)
38
+ end
39
+
40
+ def recv_simpleLogin()
41
+ result = receive_message(SimpleLogin_result)
42
+ return result.success unless result.success.nil?
43
+ raise ::Thrift::ApplicationException.new(::Thrift::ApplicationException::MISSING_RESULT, 'simpleLogin failed: unknown result')
44
+ end
45
+
46
+ def recoverPassword(userName, partnerUsername, partnerPassword)
47
+ send_recoverPassword(userName, partnerUsername, partnerPassword)
48
+ return recv_recoverPassword()
49
+ end
50
+
51
+ def send_recoverPassword(userName, partnerUsername, partnerPassword)
52
+ send_message('recoverPassword', RecoverPassword_args, :userName => userName, :partnerUsername => partnerUsername, :partnerPassword => partnerPassword)
53
+ end
54
+
55
+ def recv_recoverPassword()
56
+ result = receive_message(RecoverPassword_result)
57
+ return result.success unless result.success.nil?
58
+ raise ::Thrift::ApplicationException.new(::Thrift::ApplicationException::MISSING_RESULT, 'recoverPassword failed: unknown result')
59
+ end
60
+
61
+ def loginWithToken(userName, password, partnerUsername, partnerPassword, clientName)
62
+ send_loginWithToken(userName, password, partnerUsername, partnerPassword, clientName)
63
+ return recv_loginWithToken()
64
+ end
65
+
66
+ def send_loginWithToken(userName, password, partnerUsername, partnerPassword, clientName)
67
+ send_message('loginWithToken', LoginWithToken_args, :userName => userName, :password => password, :partnerUsername => partnerUsername, :partnerPassword => partnerPassword, :clientName => clientName)
68
+ end
69
+
70
+ def recv_loginWithToken()
71
+ result = receive_message(LoginWithToken_result)
72
+ return result.success unless result.success.nil?
73
+ raise ::Thrift::ApplicationException.new(::Thrift::ApplicationException::MISSING_RESULT, 'loginWithToken failed: unknown result')
74
+ end
75
+
76
+ end
77
+
78
+ class Processor
79
+ include ::Thrift::Processor
80
+
81
+ def process_getClientConfig(seqid, iprot, oprot)
82
+ args = read_args(iprot, GetClientConfig_args)
83
+ result = GetClientConfig_result.new()
84
+ result.success = @handler.getClientConfig(args.partnerUsername, args.partnerPassword, args.clientName)
85
+ write_result(result, oprot, 'getClientConfig', seqid)
86
+ end
87
+
88
+ def process_simpleLogin(seqid, iprot, oprot)
89
+ args = read_args(iprot, SimpleLogin_args)
90
+ result = SimpleLogin_result.new()
91
+ result.success = @handler.simpleLogin(args.userName, args.password, args.partnerUsername, args.partnerPassword, args.clientName, args.clientUniqueKey)
92
+ write_result(result, oprot, 'simpleLogin', seqid)
93
+ end
94
+
95
+ def process_recoverPassword(seqid, iprot, oprot)
96
+ args = read_args(iprot, RecoverPassword_args)
97
+ result = RecoverPassword_result.new()
98
+ result.success = @handler.recoverPassword(args.userName, args.partnerUsername, args.partnerPassword)
99
+ write_result(result, oprot, 'recoverPassword', seqid)
100
+ end
101
+
102
+ def process_loginWithToken(seqid, iprot, oprot)
103
+ args = read_args(iprot, LoginWithToken_args)
104
+ result = LoginWithToken_result.new()
105
+ result.success = @handler.loginWithToken(args.userName, args.password, args.partnerUsername, args.partnerPassword, args.clientName)
106
+ write_result(result, oprot, 'loginWithToken', seqid)
107
+ end
108
+
109
+ end
110
+
111
+ # HELPER FUNCTIONS AND STRUCTURES
112
+
113
+ class GetClientConfig_args
114
+ include ::Thrift::Struct, ::Thrift::Struct_Union
115
+ PARTNERUSERNAME = 1
116
+ PARTNERPASSWORD = 2
117
+ CLIENTNAME = 3
118
+
119
+ FIELDS = {
120
+ PARTNERUSERNAME => {:type => ::Thrift::Types::STRING, :name => 'partnerUsername'},
121
+ PARTNERPASSWORD => {:type => ::Thrift::Types::STRING, :name => 'partnerPassword'},
122
+ CLIENTNAME => {:type => ::Thrift::Types::STRING, :name => 'clientName'}
123
+ }
124
+
125
+ def struct_fields; FIELDS; end
126
+
127
+ def validate
128
+ end
129
+
130
+ ::Thrift::Struct.generate_accessors self
131
+ end
132
+
133
+ class GetClientConfig_result
134
+ include ::Thrift::Struct, ::Thrift::Struct_Union
135
+ SUCCESS = 0
136
+
137
+ FIELDS = {
138
+ SUCCESS => {:type => ::Thrift::Types::MAP, :name => 'success', :key => {:type => ::Thrift::Types::STRING}, :value => {:type => ::Thrift::Types::STRING}}
139
+ }
140
+
141
+ def struct_fields; FIELDS; end
142
+
143
+ def validate
144
+ end
145
+
146
+ ::Thrift::Struct.generate_accessors self
147
+ end
148
+
149
+ class SimpleLogin_args
150
+ include ::Thrift::Struct, ::Thrift::Struct_Union
151
+ USERNAME = 1
152
+ PASSWORD = 2
153
+ PARTNERUSERNAME = 3
154
+ PARTNERPASSWORD = 4
155
+ CLIENTNAME = 5
156
+ CLIENTUNIQUEKEY = 6
157
+
158
+ FIELDS = {
159
+ USERNAME => {:type => ::Thrift::Types::STRING, :name => 'userName'},
160
+ PASSWORD => {:type => ::Thrift::Types::STRING, :name => 'password'},
161
+ PARTNERUSERNAME => {:type => ::Thrift::Types::STRING, :name => 'partnerUsername'},
162
+ PARTNERPASSWORD => {:type => ::Thrift::Types::STRING, :name => 'partnerPassword'},
163
+ CLIENTNAME => {:type => ::Thrift::Types::STRING, :name => 'clientName'},
164
+ CLIENTUNIQUEKEY => {:type => ::Thrift::Types::STRING, :name => 'clientUniqueKey'}
165
+ }
166
+
167
+ def struct_fields; FIELDS; end
168
+
169
+ def validate
170
+ end
171
+
172
+ ::Thrift::Struct.generate_accessors self
173
+ end
174
+
175
+ class SimpleLogin_result
176
+ include ::Thrift::Struct, ::Thrift::Struct_Union
177
+ SUCCESS = 0
178
+
179
+ FIELDS = {
180
+ SUCCESS => {:type => ::Thrift::Types::STRUCT, :name => 'success', :class => ::WiMP::Gen::Profile}
181
+ }
182
+
183
+ def struct_fields; FIELDS; end
184
+
185
+ def validate
186
+ end
187
+
188
+ ::Thrift::Struct.generate_accessors self
189
+ end
190
+
191
+ class RecoverPassword_args
192
+ include ::Thrift::Struct, ::Thrift::Struct_Union
193
+ USERNAME = 1
194
+ PARTNERUSERNAME = 2
195
+ PARTNERPASSWORD = 3
196
+
197
+ FIELDS = {
198
+ USERNAME => {:type => ::Thrift::Types::STRING, :name => 'userName'},
199
+ PARTNERUSERNAME => {:type => ::Thrift::Types::STRING, :name => 'partnerUsername'},
200
+ PARTNERPASSWORD => {:type => ::Thrift::Types::STRING, :name => 'partnerPassword'}
201
+ }
202
+
203
+ def struct_fields; FIELDS; end
204
+
205
+ def validate
206
+ end
207
+
208
+ ::Thrift::Struct.generate_accessors self
209
+ end
210
+
211
+ class RecoverPassword_result
212
+ include ::Thrift::Struct, ::Thrift::Struct_Union
213
+ SUCCESS = 0
214
+
215
+ FIELDS = {
216
+ SUCCESS => {:type => ::Thrift::Types::STRUCT, :name => 'success', :class => ::WiMP::Gen::Profile}
217
+ }
218
+
219
+ def struct_fields; FIELDS; end
220
+
221
+ def validate
222
+ end
223
+
224
+ ::Thrift::Struct.generate_accessors self
225
+ end
226
+
227
+ class LoginWithToken_args
228
+ include ::Thrift::Struct, ::Thrift::Struct_Union
229
+ USERNAME = 1
230
+ PASSWORD = 2
231
+ PARTNERUSERNAME = 3
232
+ PARTNERPASSWORD = 4
233
+ CLIENTNAME = 5
234
+
235
+ FIELDS = {
236
+ USERNAME => {:type => ::Thrift::Types::STRING, :name => 'userName'},
237
+ PASSWORD => {:type => ::Thrift::Types::STRING, :name => 'password'},
238
+ PARTNERUSERNAME => {:type => ::Thrift::Types::STRING, :name => 'partnerUsername'},
239
+ PARTNERPASSWORD => {:type => ::Thrift::Types::STRING, :name => 'partnerPassword'},
240
+ CLIENTNAME => {:type => ::Thrift::Types::STRING, :name => 'clientName'}
241
+ }
242
+
243
+ def struct_fields; FIELDS; end
244
+
245
+ def validate
246
+ end
247
+
248
+ ::Thrift::Struct.generate_accessors self
249
+ end
250
+
251
+ class LoginWithToken_result
252
+ include ::Thrift::Struct, ::Thrift::Struct_Union
253
+ SUCCESS = 0
254
+
255
+ FIELDS = {
256
+ SUCCESS => {:type => ::Thrift::Types::STRUCT, :name => 'success', :class => ::WiMP::Gen::Profile}
257
+ }
258
+
259
+ def struct_fields; FIELDS; end
260
+
261
+ def validate
262
+ end
263
+
264
+ ::Thrift::Struct.generate_accessors self
265
+ end
266
+
267
+ end
268
+
269
+ end
270
+ end