31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/homophone/service.rb', line 31
def get(url)
uri = URI(url)
path_parts = uri.path.split('/').reject { |p| p == '' }
path_base = path_parts.first
path = case path_base
when 'search'
params = CGI::parse(uri.query)
type = params['type'].first
name = params['q'].first.gsub(/[+ ]/, '_')
"search/#{type}/#{name}"
when 'artists'
"artists/#{path_parts.last}/#{path_parts[1]}"
else
nil
end
raise ArgumentError, "No cassette for #{url}" unless path
path = File.join(source_path, "#{path}.yml")
JSON.load(YAML.load(IO.read(path))['http_interactions'][0]['response']['body']['string'])
end
|