active_lastfm 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/README ADDED
@@ -0,0 +1,54 @@
1
+ = Active Last.fm
2
+
3
+ link:http://github.com/thesmith/active_lastfm/tree/master
4
+
5
+ Active Last.fm is a client wrapper around the [http://last.fm last.fm] [http://www.last.fm/api/intro 2.0 web-services] based around ActiveResource.
6
+
7
+ == Overview
8
+
9
+ This wrapper is really simple at the moment. Last.fm 2.0's web-services provide an XML-RPC over XML/HTTP style interface to a load of interesting music and user information. ActiveResource is well tailored for purist RESTful interfaces but not for action-oriented services. This project basically overrides ActiveResource's URL creation for Last.fm's static URL so that the developer can simply wrap ActiveResource's default methods to create their own models around Last.fm action types.
10
+
11
+ == References
12
+
13
+ I really haven't done all that much myself here, here are a list of articles / projects that I've borrowed from:
14
+ * link:http://www.quarkruby.com/2008/1/15/activeresource-and-youtube
15
+ * link:http://www.quarkruby.com/2008/3/11/consume-non-rails-style-rest-apis
16
+ * link:http://www.quarkruby.com/2008/2/12/active-youtube
17
+ * link:http://github.com/rails/rails/tree/master/activeresource
18
+
19
+ == Usage
20
+
21
+ For example, if you wanted to use Last.fm's music ontology to create an Artist model then you might set it up something like this:
22
+
23
+ require 'active_lastfm'
24
+ class Artist < ActiveLastfm
25
+ def search(artist)
26
+ search_result = self.find(:first, :params => {
27
+ :method => 'artist.search',
28
+ :artist => artist,
29
+ :api_key => 'b25b959554ed76058ac220b7b2e0a026'
30
+ })
31
+
32
+ search_result.results.artistmatches.artist
33
+ end
34
+ end
35
+
36
+ Now, obviously, that's fairly buggy, what with the lack of result checking and coercing, but you get the idea. The API key used is the one that Last.fm have in their examples, so I'd suggest you go get your own one.
37
+
38
+ == Testing
39
+
40
+ The current unit tests use ActiveResource::HttpMock to have the mock service respond to requests and return cached results from Last.fm, stored in 'test/fixtures/'. The current methods tested are:
41
+ * track.search
42
+ * artist.search
43
+ * artist.gettoptracks
44
+
45
+ These tests pass when run under Rake from a checked out copy, but they fail, horribly, when you test under gem (say with a: sudo gem install active_lastfm -t). Hopefully I'll get round to fixing that!
46
+
47
+ == ToDo
48
+
49
+ * Proper documentation.
50
+ * Set up a proper release process from link:http://github.com/thesmith/active_lastfm/tree/master to link:http://rubyforge.org/projects/active-lastfm/.
51
+ * Start working out / test all the ActiveResource methods other than 'find'.
52
+ * Create re-usable models.
53
+ * Make sure I remove the ActiveResource patches that I've had to use.
54
+
@@ -2,12 +2,14 @@ require 'rubygems'
2
2
  require 'activeresource'
3
3
  require 'patch'
4
4
 
5
+ # This abstract base-class extends ActiveResource::Base to make requests to last.fm
6
+ # Based largely on the ActiveYouTube examples found at:
7
+ # * link:http://www.quarkruby.com/2008/1/15/activeresource-and-youtube
8
+ # * link:http://www.quarkruby.com/2008/3/11/consume-non-rails-style-rest-apis
9
+ # * link:http://www.quarkruby.com/2008/2/12/active-youtube
5
10
  class ActiveLastfm < ActiveResource::Base
11
+ # The core Last.fm WS URL is the only URI used in this interface
6
12
  self.site = 'http://ws.audioscrobbler.com/2.0/'
7
- # This abstract base-class extends ActiveResource::Base to make requests to last.fm
8
- # Based largely on the ActiveYouTube examples found at:
9
- # - http://www.quarkruby.com/2008/1/15/activeresource-and-youtube
10
- # - http://www.quarkruby.com/2008/3/11/consume-non-rails-style-rest-apis
11
13
 
12
14
  class << self
13
15
  ## Remove format from the url.
@@ -1,3 +1,4 @@
1
+ $:.unshift "#{File.dirname(__FILE__)}/../test"
1
2
  require 'abstract_unit'
2
3
  require 'active_lastfm'
3
4
 
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_lastfm
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Smith
8
- autorequire: activeresource
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-02-03 00:00:00 +00:00
12
+ date: 2008-10-12 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -23,21 +23,23 @@ dependencies:
23
23
  version: 2.0.2
24
24
  version:
25
25
  description: Last.fm client for Ruby (and Rails) based on ActiveResource
26
- email: ben@thesmith.co.uk
26
+ email: ben [at] thesmith [dot] co [dot] uk
27
27
  executables: []
28
28
 
29
29
  extensions: []
30
30
 
31
- extra_rdoc_files: []
32
-
31
+ extra_rdoc_files:
32
+ - README
33
33
  files:
34
34
  - lib/active_lastfm.rb
35
35
  - lib/patch.rb
36
- has_rdoc: false
37
- homepage: http://thesmith.co.uk/
36
+ - README
37
+ has_rdoc: true
38
+ homepage: http://github.com/thesmith/active_lastfm
38
39
  post_install_message:
39
- rdoc_options: []
40
-
40
+ rdoc_options:
41
+ - --main
42
+ - README
41
43
  require_paths:
42
44
  - lib
43
45
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -60,6 +62,4 @@ signing_key:
60
62
  specification_version: 2
61
63
  summary: Last.fm client for Ruby (and Rails) based on ActiveResource
62
64
  test_files:
63
- - test/abstract_unit.rb
64
65
  - test/active_lastfm_test.rb
65
- - test/setter_trap.rb
@@ -1,26 +0,0 @@
1
- require 'test/unit'
2
- require 'rubygems'
3
-
4
- $:.unshift "#{File.dirname(__FILE__)}/../lib"
5
- require 'active_resource'
6
- require 'active_resource/http_mock'
7
-
8
- $:.unshift "#{File.dirname(__FILE__)}/../test"
9
- require 'setter_trap'
10
-
11
- ActiveResource::Base.logger = Logger.new("#{File.dirname(__FILE__)}/debug.log")
12
-
13
- def uses_gem(gem_name, test_name, version = '> 0')
14
- gem gem_name.to_s, version
15
- require gem_name.to_s
16
- yield
17
- rescue LoadError
18
- $stderr.puts "Skipping #{test_name} tests. `gem install #{gem_name}` and try again."
19
- end
20
-
21
- # Wrap tests that use Mocha and skip if unavailable.
22
- unless defined? uses_mocha
23
- def uses_mocha(test_name, &block)
24
- uses_gem('mocha', test_name, '>= 0.5.5', &block)
25
- end
26
- end
@@ -1,27 +0,0 @@
1
- class SetterTrap < ActiveSupport::BasicObject
2
- class << self
3
- def rollback_sets(obj)
4
- returning yield(setter_trap = new(obj)) do
5
- setter_trap.rollback_sets
6
- end
7
- end
8
- end
9
-
10
- def initialize(obj)
11
- @cache = {}
12
- @obj = obj
13
- end
14
-
15
- def respond_to?(method)
16
- @obj.respond_to?(method)
17
- end
18
-
19
- def method_missing(method, *args, &proc)
20
- @cache[method] ||= @obj.send($`) if method.to_s =~ /=$/
21
- @obj.send method, *args, &proc
22
- end
23
-
24
- def rollback_sets
25
- @cache.each { |k, v| @obj.send k, v }
26
- end
27
- end