Skip to content
This repository was archived by the owner on Aug 20, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
*~
nbproject
.bundle
vendor/bundle
coverage
2 changes: 2 additions & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--color
--format nested
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
source "http://rubygems.org"

gemspec
31 changes: 31 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
PATH
remote: .
specs:
ruby-geonames (0.2.7)

GEM
remote: http://rubygems.org/
specs:
diff-lcs (1.1.2)
fakeweb (1.3.0)
rake (0.8.7)
rcov (0.9.9)
rspec (2.0.0.beta.20)
rspec-core (= 2.0.0.beta.20)
rspec-expectations (= 2.0.0.beta.20)
rspec-mocks (= 2.0.0.beta.20)
rspec-core (2.0.0.beta.20)
rspec-expectations (2.0.0.beta.20)
diff-lcs (>= 1.1.2)
rspec-mocks (2.0.0.beta.20)

PLATFORMS
ruby

DEPENDENCIES
bundler (~> 1.0.0)
fakeweb (~> 1.3.0)
rake
rcov (~> 0.9.9)
rspec (= 2.0.0.beta.20)
ruby-geonames!
14 changes: 14 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
require 'bundler/setup'
Bundler.require(:default, :development)
require 'rspec/core/rake_task'

task :default => :spec

RSpec::Core::RakeTask.new

namespace :spec do
RSpec::Core::RakeTask.new :rcov do |task|
task.rcov = true
task.rcov_opts = "--exclude spec/*,gems/*"
end
end
21 changes: 0 additions & 21 deletions lib/Rakefile.rb

This file was deleted.

8 changes: 4 additions & 4 deletions lib/postal_code_search_criteria.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,23 +49,23 @@ def to_query_params_string
end

if !@latitude.nil?
url = url + "&lat" + CGI::escape( @latitude.to_s )
url = url + "&lat=" + CGI::escape( @latitude.to_s )
end

if !@longitude.nil?
url = url + "&lng" + CGI::escape( @longitude.to_s )
url = url + "&lng=" + CGI::escape( @longitude.to_s )
end

if !@style.nil?
url = url + "&style" + CGI::escape( @style )
url = url + "&style=" + CGI::escape( @style )
end

if !@country_code.nil?
url = url + "&country=" + CGI::escape( @country_code )
end

if !@max_rows.nil?
url = url + "&maxRows=" + CGI::escape( @max_rows )
url = url + "&maxRows=" + CGI::escape( @max_rows.to_s )
end

if !@radius.nil?
Expand Down
25 changes: 15 additions & 10 deletions ruby-geonames.gemspec
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
SPEC = Gem::Specification.new do |s|
s.name = "ruby-geonames"
Gem::Specification.new do |s|
s.name = "ruby-geonames"
s.version = "0.2.7"
s.author = "Adam Wisniewski"
s.email = "adamw@tbcn.ca"
s.author = "Adam Wisniewski"
s.email = "adamw@tbcn.ca"
s.date = "2009-07-07"
s.homepage = "http://github.com/elecnix/ruby-geonames"
s.platform = Gem::Platform::RUBY
s.summary = "Ruby library for Geonames Web Services (http://www.geonames.org/export/)"
s.files = ["README.markdown", "lib/timezone.rb", "lib/wikipedia_article.rb", "lib/geonames.rb", "lib/postal_code_search_criteria.rb", "lib/intersection.rb", "lib/country_subdivision.rb", "lib/toponym.rb", "lib/toponym_search_result.rb", "lib/bounding_box.rb", "lib/web_service.rb", "lib/postal_code.rb", "lib/toponym_search_criteria.rb", "lib/tc_country_info.rb", "lib/main.rb", "lib/Rakefile.rb", "lib/address.rb", "lib/country_info.rb"]
s.platform = Gem::Platform::RUBY
s.summary = "Ruby library for Geonames Web Services (http://www.geonames.org/export/)"
s.files = ["README.markdown", "lib/timezone.rb", "lib/wikipedia_article.rb", "lib/geonames.rb", "lib/postal_code_search_criteria.rb", "lib/intersection.rb", "lib/country_subdivision.rb", "lib/toponym.rb", "lib/toponym_search_result.rb", "lib/bounding_box.rb", "lib/web_service.rb", "lib/postal_code.rb", "lib/toponym_search_criteria.rb", "lib/tc_country_info.rb", "lib/main.rb", "lib/address.rb", "lib/country_info.rb"]
s.require_path = "lib"
s.has_rdoc = true
s.has_rdoc = true
s.extra_rdoc_files = ["README.markdown"]
end

s.required_rubygems_version = ">= 1.3.6"
s.add_development_dependency "bundler", "~> 1.0.0"
s.add_development_dependency "fakeweb", "~> 1.3.0"
s.add_development_dependency "rake"
s.add_development_dependency "rcov", "~> 0.9.9"
s.add_development_dependency "rspec", "2.0.0.beta.20"
end
81 changes: 81 additions & 0 deletions spec/fixtures/find_nearby_postal_codes/lat_lng.xml.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
HTTP/1.1 200 OK
Date: Wed, 22 Sep 2010 01:12:12 GMT
Server: Apache/2.2.13 (Linux/SUSE)
Cache-Control: no-cache
Access-Control-Allow-Origin: *
Transfer-Encoding: chunked
Content-Type: text/xml;charset=UTF-8

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<geonames>
<code>
<postalcode>8750</postalcode>
<name>Klöntal</name>
<countryCode>CH</countryCode>
<lat>47.021</lat>
<lng>8.97896</lng>
<adminCode1>GL</adminCode1>
<adminName1>Glarus</adminName1>
<adminCode2>800</adminCode2>
<adminName2>Glarus</adminName2>
<adminCode3>1609</adminCode3>
<adminName3>Glarus</adminName3>
<distance>2.827649162427546</distance>
</code>
<code>
<postalcode>8750</postalcode>
<name>Glarus Zustellung</name>
<countryCode>CH</countryCode>
<lat>47.021</lat>
<lng>8.97896</lng>
<adminCode1>GL</adminCode1>
<adminName1>Glarus</adminName1>
<adminCode2>800</adminCode2>
<adminName2>Glarus</adminName2>
<adminCode3>1609</adminCode3>
<adminName3>Glarus</adminName3>
<distance>2.827649162427546</distance>
</code>
<code>
<postalcode>8772</postalcode>
<name>Nidfurn</name>
<countryCode>CH</countryCode>
<lat>46.98333</lat>
<lng>9.05</lng>
<adminCode1>GL</adminCode1>
<adminName1>Glarus</adminName1>
<adminCode2>800</adminCode2>
<adminName2>Glarus</adminName2>
<adminCode3>1621</adminCode3>
<adminName3>Nidfurn</adminName3>
<distance>4.220733421769597</distance>
</code>
<code>
<postalcode>8775</postalcode>
<name>Luchsingen</name>
<countryCode>CH</countryCode>
<lat>46.96667</lat>
<lng>9.03333</lng>
<adminCode1>GL</adminCode1>
<adminName1>Glarus</adminName1>
<adminCode2>800</adminCode2>
<adminName2>Glarus</adminName2>
<adminCode3>1614</adminCode3>
<adminName3>Luchsingen</adminName3>
<distance>4.486650531422443</distance>
</code>
<code>
<postalcode>8773</postalcode>
<name>Haslen GL</name>
<countryCode>CH</countryCode>
<lat>46.96333</lat>
<lng>9.03667</lng>
<adminCode1>GL</adminCode1>
<adminName1>Glarus</adminName1>
<adminCode2>800</adminCode2>
<adminName2>Glarus</adminName2>
<adminCode3>1610</adminCode3>
<adminName3>Haslen</adminName3>
<distance>4.93536846606444</distance>
</code>
</geonames>
31 changes: 31 additions & 0 deletions spec/geonames/postal_code_search_criteria_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
require 'spec_helper'

module Geonames
describe PostalCodeSearchCriteria do
describe "#to_query_params_string" do
context "with a numeric latitude" do
let(:latitude) { 25.123 }
before(:each) { subject.latitude = latitude }
it("contains the lat parameter") { subject.to_query_params_string.should =~ /lat=#{latitude}/ }
end

context "with a numeric longitude" do
let(:longitude) { -52.123 }
before(:each) { subject.longitude = longitude }
it("contains the lng parameter") { subject.to_query_params_string.should =~ /lng=#{longitude}/ }
end

context "with a numeric max_rows" do
let(:max_rows) { 1 }
before(:each) { subject.max_rows = max_rows }
it("contains the maxRows parameter") { subject.to_query_params_string.should =~ /maxRows=#{max_rows}/ }
end

context "with a style" do
let(:style) { "SHORT" }
before(:each) { subject.style = style }
it("contains the style parameter") { subject.to_query_params_string.should =~ /style=#{style}/ }
end
end
end
end
32 changes: 32 additions & 0 deletions spec/geonames/web_service/postal_code_search_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
require 'spec_helper'

module Geonames
describe WebService do
describe ".postal_code_search" do
subject { Geonames::WebService.postal_code_search(criteria) }

context "lookup by latitude and longitude" do
let(:criteria) do
criteria = Geonames::PostalCodeSearchCriteria.new
criteria.latitude = 47
criteria.longitude = 9
criteria
end

before(:each) do
FakeWeb.register_uri(:get, /\/postalCodeSearch\?.*&lat=47.*&lng=9/, :response => File.read(
File.join(File.dirname(__FILE__), '..', '..', 'fixtures', 'find_nearby_postal_codes', 'lat_lng.xml.http')
))
end

it { should be_a_kind_of(Array) }

it "returns PostalCode instances" do
subject.each do |postal_code|
postal_code.should be_a_kind_of PostalCode
end
end
end
end
end
end
25 changes: 25 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
require 'rubygems'

# Set up gems listed in the Gemfile.
gemfile = File.expand_path('../Gemfile', File.dirname(__FILE__))
begin
ENV['BUNDLE_GEMFILE'] = gemfile
require 'bundler'
Bundler.setup
rescue Bundler::GemNotFound => e
STDERR.puts e.message
STDERR.puts "Try running `bundle install`."
exit!
end

Bundler.require(:default, :development)

Rspec.configure do |config|
config.mock_with :rspec
end

# Requires supporting files with custom matchers and macros, etc,
# in ./support/ and its subdirectories.
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f }

require 'geonames'
7 changes: 7 additions & 0 deletions spec/support/fakeweb.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FakeWeb.allow_net_connect = false

Rspec.configure do |config|
config.before(:each) do
FakeWeb.clean_registry
end
end