public
Description: Scrobbler is a wrapper for the audioscrobbler (last.fm) web services.
Homepage: http://scrobbler.rubyforge.org/
Clone URL: git://github.com/jnunemaker/scrobbler.git
Search Repo:
scrobbler / test / mocks / rest.rb
100644 26 lines (23 sloc) 0.858 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
require File.dirname(__FILE__) + '/../../lib/scrobbler/rest'
 
module Scrobbler
  module REST
    class Connection
     # reads xml fixture file instead of hitting up the internets
     def request(resource, method = "get", args = nil)
     pieces = resource.split('/')
     pieces.shift
     pieces.shift
     folder = pieces.shift
     file = pieces.last[0, pieces.last.index('.xml')]
     base_pieces = pieces.last.split('?')
    
     file = if base_pieces.size > 1
     # if query string params are in resource they are underscore separated for filenames
     base_pieces.last.split('&').inject("#{file}_") { |str, pair| str << pair.split('=').join('_') + '_'; str }.chop!
   else
   file
        end
    
     File.read(File.dirname(__FILE__) + "/../fixtures/xml/#{folder}/#{file}.xml")
   end
   end
  end
end