class Homophone::Service::DummySpotify

Public Instance Methods

cassette_path(components, params) click to toggle source
# File lib/homophone/service.rb, line 47
def cassette_path(components, params)
  case components.first
  when 'search'
    type = params['type'].first
    name = params['q'].first.gsub(/[+ ]/, '_')
    "search/#{type}/#{name}"
  when 'artists'
    "artists/#{components.last}/#{components[1]}"
  else
    nil
  end
end
get(url) click to toggle source
# File lib/homophone/service.rb, line 31
  def get(url)
    uri = URI(url)
    params = begin CGI::parse(uri.query) rescue nil end
    path_parts = uri.path.split('/').reject { |p| p == '' }
    path = cassette_path(path_parts, params)
    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

  private

  def source_path
    File.join(File.dirname(__FILE__), '..', '..', 'features', 'fixtures', 'cassettes')
  end

  def cassette_path(components, params)
    case components.first
    when 'search'
      type = params['type'].first
      name = params['q'].first.gsub(/[+ ]/, '_')
      "search/#{type}/#{name}"
    when 'artists'
      "artists/#{components.last}/#{components[1]}"
    else
      nil
    end
  end
end
source_path() click to toggle source
# File lib/homophone/service.rb, line 43
def source_path
  File.join(File.dirname(__FILE__), '..', '..', 'features', 'fixtures', 'cassettes')
end