Skip to content
This repository
tag: 0.2.10
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 86 lines (71 sloc) 2.487 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 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
require 'rubygems'
require 'active_support'
require 'hoe'
require File.join(File.dirname(__FILE__), 'lib', 'graticule', 'version.rb')

Hoe.new("graticule", Graticule::Version::STRING) do |p|
  p.rubyforge_name = "graticule"
  p.author = 'Brandon Keepers'
  p.email = 'brandon@opensoul.org'
  p.summary = "API for using all the popular geocoding services."
  p.description = 'Graticule is a geocoding API that provides a common interface to all the popular services, including Google, Yahoo, Geocoder.us, and MetaCarta.'
  p.url = 'http://graticule.rubyforge.org'
  p.need_tar = true
  p.need_zip = true
  p.test_globs = ['test/**/*_test.rb']
  p.changes = p.paragraphs_of('CHANGELOG.txt', 0..1).join("\n\n")
  p.extra_deps << ['activesupport']
end



namespace :test do
  namespace :cache do
    desc 'Cache test responses from all the free geocoders'
    task :free => [:google, :geocoder_us, :host_ip, :local_search_maps, :meta_carta, :yahoo]
    
    desc 'Cache test responses from Google'
    task :google do
      cache_responses('google')
    end
    
    desc 'Cache test responses from Geocoder.us'
    task :geocoder_us do
      cache_responses('geocoder_us')
    end
    
    desc 'Cache test responses from HostIP'
    task :host_ip do
      cache_responses('host_ip')
    end

    desc 'Cache test responses from Local Search Maps'
    task :local_search_maps do
      cache_responses('local_search_maps')
    end

    desc 'Cache test responses from Meta Carta'
    task :meta_carta do
      cache_responses('meta_carta')
    end

    desc 'Cache test responses from Yahoo'
    task :yahoo do
      cache_responses('yahoo')
    end

  end
end

require 'net/http'
require 'uri'
RESPONSES_PATH = File.dirname(__FILE__) + '/test/fixtures/responses'

def cache_responses(service)
  test_config[service.to_s]['responses'].each do |file,url|
    File.open("#{RESPONSES_PATH}/#{service}/#{file}", 'w') do |f|
      f.puts Net::HTTP.get(URI.parse(url))
    end
  end
end

def test_config
  file = File.dirname(__FILE__) + '/test/config.yml'
  raise "Copy config.yml.default to config.yml and set the API keys" unless File.exists?(file)
  @test_config ||= returning(YAML.load(File.read(file))) do |config|
    config.each do |service,values|
      values['responses'].each {|file,url| update_placeholders!(values, url) }
    end
  end
end

def update_placeholders!(config, thing)
  config.each do |option, value|
    thing.gsub!(":#{option}", value) if value.is_a?(String)
  end
end
Something went wrong with that request. Please try again.