geonames_client 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,122 @@
1
+ require 'spec_helper'
2
+
3
+ describe GeonamesClient::ServiceDefinition do
4
+
5
+ let :service_definition do
6
+ described_class.new
7
+ end
8
+
9
+ context '.address' do
10
+
11
+ subject { GeonamesClient::ServiceDefinition.address }
12
+
13
+ it { should == 'api.geonames.org' }
14
+
15
+ end
16
+
17
+ {
18
+ 'base_uri' => 'http://api.geonames.org',
19
+ 'nearby_streets_path' => '/findNearbyStreets',
20
+ 'nearby_streets_json_path' => '/findNearbyStreetsJSON',
21
+ 'latitude_parameter' => 'lat',
22
+ 'longitude_parameter' => 'lng',
23
+ 'username_parameter' => 'username'
24
+
25
+ }.each do |method_name, value|
26
+
27
+ context "##{method_name}" do
28
+
29
+ subject { service_definition.send( method_name ) }
30
+
31
+ it { should == value }
32
+
33
+ end
34
+
35
+ end
36
+
37
+ context '#nearby_streets_base_path' do
38
+
39
+ {
40
+ :xml => 'http://api.geonames.org/findNearbyStreets',
41
+ :json => 'http://api.geonames.org/findNearbyStreetsJSON',
42
+ 'xml' => 'http://api.geonames.org/findNearbyStreets',
43
+ 'json' => 'http://api.geonames.org/findNearbyStreetsJSON'
44
+ }.each do |format, value|
45
+
46
+ context "when #{format} requested" do
47
+
48
+ subject { service_definition.nearby_streets_base_path( format ) }
49
+
50
+ it { should == value }
51
+
52
+ end
53
+
54
+ end
55
+
56
+ it "should raise an exception when the format is not an avaliable format" do
57
+ lambda { service_definition.nearby_streets_base_path( :html ) }.should(
58
+ raise_error( RuntimeError, /^Invalid format: expected one of .*/ )
59
+ )
60
+ end
61
+
62
+ end
63
+
64
+ context '#full_nearby_streets_uri' do
65
+
66
+ let :params do
67
+ {
68
+ :latitude => '29.762242',
69
+ :longitude => '-95.416166',
70
+ :username => 'ncite'
71
+ }
72
+ end
73
+
74
+ context 'when given all expected paramaters in a hash' do
75
+
76
+ context 'and no format is provided do' do
77
+
78
+ subject { service_definition.full_nearby_streets_uri( params ) }
79
+
80
+ it { should == 'http://api.geonames.org/findNearbyStreets?lat=29.762242&lng=-95.416166&username=ncite' }
81
+
82
+ end
83
+
84
+ context 'and a format of :xml is provided do' do
85
+
86
+ subject { service_definition.full_nearby_streets_uri( params.merge( :format => :xml ) ) }
87
+
88
+ it { should == 'http://api.geonames.org/findNearbyStreets?lat=29.762242&lng=-95.416166&username=ncite' }
89
+
90
+ end
91
+
92
+ context 'and a format of :json is provided do' do
93
+
94
+ subject { service_definition.full_nearby_streets_uri( params.merge( :format => :json ) ) }
95
+
96
+ it { should == 'http://api.geonames.org/findNearbyStreetsJSON?lat=29.762242&lng=-95.416166&username=ncite' }
97
+
98
+ end
99
+
100
+ end
101
+
102
+ context 'when not given all of the expected params' do
103
+
104
+ %w(
105
+ latitude
106
+ longitude
107
+ username
108
+ ).each do |parameter|
109
+
110
+ it "should raise an exception when the #{parameter} parameter is not provided" do
111
+ lambda { service_definition.full_nearby_streets_uri( params.except( parameter.to_sym ) ) }.should(
112
+ raise_error( RuntimeError, "Please provide the :#{parameter} parameter" )
113
+ )
114
+ end
115
+
116
+ end
117
+
118
+ end
119
+
120
+ end
121
+
122
+ end
@@ -0,0 +1,70 @@
1
+ require 'spec_helper'
2
+
3
+ describe GeonamesClient::Service do
4
+
5
+ let :service do
6
+ described_class.new( 'test' )
7
+ end
8
+
9
+ it "should include the HTTParty module" do
10
+ described_class.included_modules.should include( HTTParty )
11
+ end
12
+
13
+ it "should have a service definition" do
14
+ service.service_definition.is_a?( GeonamesClient::ServiceDefinition ).should be_true
15
+ end
16
+
17
+ context '#initialize' do
18
+
19
+ context "accepting an api_key" do
20
+
21
+ subject { described_class.new( 'test' ).api_key }
22
+
23
+ it { should == 'test' }
24
+
25
+ end
26
+
27
+ end
28
+
29
+ context '#get_nearby_streets' do
30
+
31
+ before :each do
32
+ service.stub!( :nearby_streets ).and_return street_names
33
+ end
34
+
35
+ let :http_party_response do
36
+ base = File.join( File.dirname(__FILE__), "..", "..", "data" )
37
+
38
+ HTTParty::Response.new YAML::load_file( File.join( base, "geoname_response-headers.yml" ) ),
39
+ YAML::load_file( File.join( base, "geoname_response-response.yml" ) ),
40
+ YAML::load_file( File.join( base, "geoname_response-parsed_response.yml" ) )
41
+ end
42
+
43
+ let :street_names do
44
+ ["Detering St", "Memorial Dr", "Aloe St", "Hohl St"]
45
+ end
46
+
47
+ subject do
48
+ service.get_nearby_streets( :latitude => '29.762242',
49
+ :longitude => '-95.416166' )
50
+ end
51
+
52
+ it { should == GeonamesClient::NearbyStreet.all( 'Aloe St',
53
+ 'Detering St',
54
+ 'Hohl St',
55
+ 'Memorial Dr' ) }
56
+
57
+ end
58
+
59
+ # context '#nearby_streets_from_geonames_northeast' do
60
+ #
61
+ # subject do
62
+ # service.nearby_streets_from_geonames_northeast( :latitude => '29.762242',
63
+ # :longitude => '-95.416166' )
64
+ # end
65
+ #
66
+ # it { should == nil }
67
+ #
68
+ # end
69
+
70
+ end
@@ -0,0 +1,22 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+
4
+ require 'geonames_client'
5
+
6
+ RSpec.configure do |config|
7
+
8
+ config.mock_with :rspec
9
+
10
+ end
11
+
12
+ class Hash
13
+ # for excluding keys
14
+ def except(*exclusions)
15
+ self.reject { |key, value| exclusions.include? key.to_sym }
16
+ end
17
+
18
+ # for overriding keys
19
+ def with(overrides = {})
20
+ self.merge overrides
21
+ end
22
+ end
metadata ADDED
@@ -0,0 +1,176 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: geonames_client
3
+ version: !ruby/object:Gem::Version
4
+ hash: 23
5
+ prerelease:
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 0
10
+ version: 1.0.0
11
+ platform: ruby
12
+ authors:
13
+ - C. Jason Harrelson
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-09-16 00:00:00 -05:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: ruby-debug
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 63
30
+ segments:
31
+ - 0
32
+ - 10
33
+ - 4
34
+ version: 0.10.4
35
+ type: :development
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: rake
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ hash: 63
46
+ segments:
47
+ - 0
48
+ - 9
49
+ - 2
50
+ version: 0.9.2
51
+ type: :development
52
+ version_requirements: *id002
53
+ - !ruby/object:Gem::Dependency
54
+ name: rspec
55
+ prerelease: false
56
+ requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ hash: 23
62
+ segments:
63
+ - 2
64
+ - 6
65
+ - 0
66
+ version: 2.6.0
67
+ type: :development
68
+ version_requirements: *id003
69
+ - !ruby/object:Gem::Dependency
70
+ name: guard-rspec
71
+ prerelease: false
72
+ requirement: &id004 !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ hash: 15
78
+ segments:
79
+ - 0
80
+ - 4
81
+ - 0
82
+ version: 0.4.0
83
+ type: :development
84
+ version_requirements: *id004
85
+ - !ruby/object:Gem::Dependency
86
+ name: guard
87
+ prerelease: false
88
+ requirement: &id005 !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ hash: 11
94
+ segments:
95
+ - 0
96
+ - 4
97
+ - 2
98
+ version: 0.4.2
99
+ type: :development
100
+ version_requirements: *id005
101
+ description: A client to consume the geonames web services (www.geonames.org).
102
+ email:
103
+ - jason@lookforwardenterprises.com
104
+ executables: []
105
+
106
+ extensions: []
107
+
108
+ extra_rdoc_files: []
109
+
110
+ files:
111
+ - .gitignore
112
+ - .rspec
113
+ - .rvmrc
114
+ - Gemfile
115
+ - Guardfile
116
+ - README.rdoc
117
+ - Rakefile
118
+ - geonames_client.gemspec
119
+ - lib/geonames_client.rb
120
+ - lib/geonames_client/_location.rb
121
+ - lib/geonames_client/location.rb
122
+ - lib/geonames_client/nearby_street.rb
123
+ - lib/geonames_client/service.rb
124
+ - lib/geonames_client/service_definition.rb
125
+ - lib/geonames_client/version.rb
126
+ - spec/data/geoname_response-headers.yml
127
+ - spec/data/geoname_response-parsed_response.yml
128
+ - spec/data/geoname_response-response.yml
129
+ - spec/lib/geonames_client/location_spec.rb
130
+ - spec/lib/geonames_client/nearby_street_spec.rb
131
+ - spec/lib/geonames_client/service_definition_spec.rb
132
+ - spec/lib/geonames_client/service_spec.rb
133
+ - spec/spec_helper.rb
134
+ has_rdoc: true
135
+ homepage: ""
136
+ licenses: []
137
+
138
+ post_install_message:
139
+ rdoc_options: []
140
+
141
+ require_paths:
142
+ - lib
143
+ required_ruby_version: !ruby/object:Gem::Requirement
144
+ none: false
145
+ requirements:
146
+ - - ">="
147
+ - !ruby/object:Gem::Version
148
+ hash: 3
149
+ segments:
150
+ - 0
151
+ version: "0"
152
+ required_rubygems_version: !ruby/object:Gem::Requirement
153
+ none: false
154
+ requirements:
155
+ - - ">="
156
+ - !ruby/object:Gem::Version
157
+ hash: 3
158
+ segments:
159
+ - 0
160
+ version: "0"
161
+ requirements: []
162
+
163
+ rubyforge_project: geonames_client
164
+ rubygems_version: 1.6.0
165
+ signing_key:
166
+ specification_version: 3
167
+ summary: A client to consume the geonames web services.
168
+ test_files:
169
+ - spec/data/geoname_response-headers.yml
170
+ - spec/data/geoname_response-parsed_response.yml
171
+ - spec/data/geoname_response-response.yml
172
+ - spec/lib/geonames_client/location_spec.rb
173
+ - spec/lib/geonames_client/nearby_street_spec.rb
174
+ - spec/lib/geonames_client/service_definition_spec.rb
175
+ - spec/lib/geonames_client/service_spec.rb
176
+ - spec/spec_helper.rb