ruby-last.fm-wrapper 0.0.2

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/.DS_Store ADDED
Binary file
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ lfm.yml
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Luke van der Hoeven
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/README.rdoc ADDED
@@ -0,0 +1,29 @@
1
+ = ruby-last.fm-wrapper
2
+
3
+ ruby-last.fm-wrapper
4
+
5
+ A ruby wrapper for the Last.fm API. Forking for the purpose of extending and using in some of my own projects from: http://github.com/digitalscientists/ruby-last.fm-wrapper
6
+
7
+ http://www.last.fm/api
8
+
9
+ Examples (to be updated):
10
+
11
+ lfm = LastFM.new()
12
+ tracks = lfm.track.search(:track=>'redline')
13
+ similar = lfm.artist.getSimilar(:artist=>'radiohead',:limit=>5)
14
+ loved = lfm.user.getLoved(:user=>'myuser')
15
+
16
+ == Note on Patches/Pull Requests
17
+
18
+ * Fork the project.
19
+ * Make your feature addition or bug fix.
20
+ * Add tests for it. This is important so I don't break it in a
21
+ future version unintentionally.
22
+ * Commit, do not mess with rakefile, version, or history.
23
+ (if you want to have your own version, that is fine but
24
+ bump version in a commit by itself I can ignore when I pull)
25
+ * Send me a pull request. Bonus points for topic branches.
26
+
27
+ == Copyright
28
+
29
+ Copyright (c) 2009 Luke van der Hoeven. See LICENSE for details.
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.2
data/lib/.DS_Store ADDED
Binary file
data/lib/last_fm.rb ADDED
@@ -0,0 +1,22 @@
1
+ require 'rubygems'
2
+ require 'net/http'
3
+ require 'active_resource'
4
+ require 'hpricot'
5
+ class LastFM
6
+ VERSION = '0.0.1'
7
+ end
8
+ require File.dirname(__FILE__) + '/last_fm/meta'
9
+ require File.dirname(__FILE__) + '/last_fm/base'
10
+ require File.dirname(__FILE__) + '/last_fm/artist'
11
+ require File.dirname(__FILE__) + '/last_fm/album'
12
+ require File.dirname(__FILE__) + '/last_fm/auth'
13
+ require File.dirname(__FILE__) + '/last_fm/event'
14
+ require File.dirname(__FILE__) + '/last_fm/geo'
15
+ require File.dirname(__FILE__) + '/last_fm/group'
16
+ require File.dirname(__FILE__) + '/last_fm/library'
17
+ require File.dirname(__FILE__) + '/last_fm/playlist'
18
+ require File.dirname(__FILE__) + '/last_fm/tag'
19
+ require File.dirname(__FILE__) + '/last_fm/tastometer'
20
+ require File.dirname(__FILE__) + '/last_fm/track'
21
+ require File.dirname(__FILE__) + '/last_fm/user'
22
+
@@ -0,0 +1,2 @@
1
+ class LastFM::Album < LastFM
2
+ end
@@ -0,0 +1,3 @@
1
+ class LastFM::Artist < LastFM
2
+ #resp['results']['artistmatches']['artist'] rescue []
3
+ end
@@ -0,0 +1,2 @@
1
+ class LastFM::Auth < LastFM
2
+ end
@@ -0,0 +1,38 @@
1
+ class LastFM
2
+ include LastFM::Meta
3
+ attr_reader :url
4
+
5
+ def initialize
6
+ @@cnf = YAML.load_file "lfm.yml"
7
+ @@url = "http://ws.audioscrobbler.com/2.0/?api_key=#{@@cnf['LAST_FM_KEY']}&"
8
+ end
9
+
10
+ def get uri
11
+ begin
12
+ url = URI.parse(uri)
13
+ req = Net::HTTP::Get.new(url.path+"?"+url.query)
14
+ @response = Net::HTTP.start(url.host, url.port) {|http| http.request(req) }
15
+ result = Hpricot::XML(@response.body)
16
+ rescue
17
+ puts "Request failed for #{uri} - #{$!}"
18
+ end
19
+ end
20
+
21
+ def lfm_query method,params
22
+ klass = self.class.to_s.gsub("LastFM::","").downcase
23
+ "#{@@url}method=#{klass}.#{method}&#{params.to_query}"
24
+ end
25
+
26
+ def album() @track ||= Album.new() end
27
+ def artist() @artist ||= Artist.new() end
28
+ def event() @event ||= Event.new() end
29
+ def geo() @geo ||= Geo.new() end
30
+ def group() @group ||= Group.new() end
31
+ def library() @library ||= Library.new() end
32
+ def playlist() @playlist ||= Playlist.new() end
33
+ def tag() @tag ||= Tag.new() end
34
+ def tastometer() @tastometer ||= Tastometer.new() end
35
+ def track() @track ||= Track.new() end
36
+ def user() @user ||= User.new() end
37
+
38
+ end
@@ -0,0 +1,2 @@
1
+ class LastFM::Event < LastFM
2
+ end
@@ -0,0 +1,2 @@
1
+ class LastFM::Geo < LastFM
2
+ end
@@ -0,0 +1,2 @@
1
+ class LastFM::Group < LastFM
2
+ end
@@ -0,0 +1,2 @@
1
+ class LastFM::Library < LastFM
2
+ end
@@ -0,0 +1,8 @@
1
+ module LastFM::Meta
2
+ # This method handles and return most API
3
+ # call in their default format. Override
4
+ # as needed within each class
5
+ def method_missing(method,args = {:page=>1,:limit=>20})
6
+ get lfm_query(method,args)
7
+ end
8
+ end
@@ -0,0 +1,2 @@
1
+ class LastFM::Playlist < LastFM
2
+ end
@@ -0,0 +1,2 @@
1
+ class LastFM::Tag < LastFM
2
+ end
@@ -0,0 +1,2 @@
1
+ class LastFM::Tasteometer < LastFM
2
+ end
@@ -0,0 +1,21 @@
1
+ class LastFM::Track < LastFM
2
+ @@elements = [
3
+ "id",
4
+ "name",
5
+ "mbid",
6
+ "url",
7
+ "duration",
8
+ "streamable",
9
+ "listeners",
10
+ "playcount"
11
+ ]
12
+
13
+ attr_accessor(*@@elements)
14
+
15
+ def get_info(params)
16
+ data = get lfm_query("getInfo", params)
17
+ @@elements.each do |val|
18
+ eval "@#{val} = (data/'track/#{val}').text"
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,3 @@
1
+ class LastFM::User < LastFM
2
+
3
+ end
data/test.rb ADDED
@@ -0,0 +1,5 @@
1
+ require 'lib/last_fm'
2
+ lfm = LastFM.new()
3
+ res = lfm.artist.search(:artist=>'radiohead')
4
+ p res
5
+
metadata ADDED
@@ -0,0 +1,77 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruby-last.fm-wrapper
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Luke van der Hoeven
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-01-08 00:00:00 -05:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: "A ruby wrapper for the Last.fm API. Forking for the purpose of extending and using in some of my own projects from: http://github.com/digitalscientists/ruby-last.fm-wrapper / http://www.last.fm/api"
17
+ email: hungerandthirst@gmail.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - LICENSE
24
+ - README.rdoc
25
+ files:
26
+ - .DS_Store
27
+ - .gitignore
28
+ - VERSION
29
+ - lib/.DS_Store
30
+ - lib/last_fm.rb
31
+ - lib/last_fm/album.rb
32
+ - lib/last_fm/artist.rb
33
+ - lib/last_fm/auth.rb
34
+ - lib/last_fm/base.rb
35
+ - lib/last_fm/event.rb
36
+ - lib/last_fm/geo.rb
37
+ - lib/last_fm/group.rb
38
+ - lib/last_fm/library.rb
39
+ - lib/last_fm/meta.rb
40
+ - lib/last_fm/playlist.rb
41
+ - lib/last_fm/tag.rb
42
+ - lib/last_fm/tastometer.rb
43
+ - lib/last_fm/track.rb
44
+ - lib/last_fm/user.rb
45
+ - test.rb
46
+ - LICENSE
47
+ - README.rdoc
48
+ has_rdoc: true
49
+ homepage: http://github.com/plukevdh/ruby-last.fm-wrapper
50
+ licenses: []
51
+
52
+ post_install_message:
53
+ rdoc_options:
54
+ - --charset=UTF-8
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: "0"
62
+ version:
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: "0"
68
+ version:
69
+ requirements: []
70
+
71
+ rubyforge_project:
72
+ rubygems_version: 1.3.5
73
+ signing_key:
74
+ specification_version: 3
75
+ summary: This is intended to be a dynamic wrapper for the Last.FM API
76
+ test_files: []
77
+