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,14 @@
1
+ require "geonames_client/version"
2
+
3
+ module GeonamesClient
4
+ autoload :Location, 'geonames_client/location'
5
+ autoload :NearbyStreet, 'geonames_client/nearby_street'
6
+ autoload :Service, 'geonames_client/service'
7
+ autoload :ServiceDefinition, 'geonames_client/service_definition'
8
+ end
9
+
10
+ class Numeric
11
+ def degrees
12
+ self * Math::PI / 180
13
+ end
14
+ end
@@ -0,0 +1,16 @@
1
+ --- !ruby/object:HTTParty::Response::Headers
2
+ header:
3
+ access-control-allow-origin:
4
+ - "*"
5
+ connection:
6
+ - close
7
+ content-type:
8
+ - text/xml;charset=UTF-8
9
+ date:
10
+ - Thu, 15 Sep 2011 23:09:37 GMT
11
+ server:
12
+ - Apache/2.2.15 (Linux/SUSE)
13
+ cache-control:
14
+ - no-cache
15
+ transfer-encoding:
16
+ - chunked
@@ -0,0 +1,153 @@
1
+ ---
2
+ geonames:
3
+ streetSegment:
4
+ - placename: Houston
5
+ fraddr: "38"
6
+ name: Detering St
7
+ adminCode1: TX
8
+ adminCode2: "201"
9
+ line: -95.416216 29.762065,-95.416239 29.763079
10
+ toaddr: "98"
11
+ postalcode: "77007"
12
+ countryCode: US
13
+ adminName1: Texas
14
+ fraddl: "37"
15
+ adminName2: Harris
16
+ toaddl: "95"
17
+ mtfcc: S1400
18
+ distance: "0.02"
19
+ - placename: Houston
20
+ fraddr: "2"
21
+ name: Detering St
22
+ adminCode1: TX
23
+ adminCode2: "201"
24
+ line: -95.41621 29.761482,-95.416216 29.762065
25
+ toaddr: "36"
26
+ postalcode: "77007"
27
+ countryCode: US
28
+ adminName1: Texas
29
+ fraddl: "1"
30
+ adminName2: Harris
31
+ toaddl: "35"
32
+ mtfcc: S1400
33
+ distance: "0.02"
34
+ - placename: Houston
35
+ fraddr: "5300"
36
+ name: Memorial Dr
37
+ adminCode1: TX
38
+ adminCode2: "201"
39
+ line: -95.415808 29.761663,-95.41621 29.761482
40
+ toaddr: "5398"
41
+ postalcode: "77007"
42
+ countryCode: US
43
+ adminName1: Texas
44
+ fraddl: "5301"
45
+ adminName2: Harris
46
+ toaddl: "5399"
47
+ mtfcc: S1400
48
+ distance: "0.07"
49
+ - placename: Houston
50
+ fraddr: "5270"
51
+ name: Memorial Dr
52
+ adminCode1: TX
53
+ adminCode2: "201"
54
+ line: -95.414351 29.762661,-95.414506 29.762576,-95.414876 29.762343,-95.415249 29.762011,-95.415699 29.761712,-95.415808 29.761663
55
+ toaddr: "5298"
56
+ postalcode: "77007"
57
+ countryCode: US
58
+ adminName1: Texas
59
+ fraddl: "5239"
60
+ adminName2: Harris
61
+ toaddl: "5299"
62
+ mtfcc: S1400
63
+ distance: "0.07"
64
+ - placename: Houston
65
+ fraddr:
66
+ name: Memorial Dr
67
+ adminCode1: TX
68
+ adminCode2: "201"
69
+ line: -95.415537 29.761664,-95.415582 29.76164,-95.415705 29.761596,-95.41621 29.761482
70
+ toaddr:
71
+ postalcode:
72
+ countryCode: US
73
+ adminName1: Texas
74
+ fraddl:
75
+ adminName2: Harris
76
+ toaddl:
77
+ mtfcc: S1400
78
+ distance: "0.08"
79
+ - placename: Houston
80
+ fraddr: "5400"
81
+ name: Memorial Dr
82
+ adminCode1: TX
83
+ adminCode2: "201"
84
+ line: -95.41621 29.761482,-95.416936 29.761412,-95.417563 29.761378
85
+ toaddr: "5498"
86
+ postalcode: "77007"
87
+ countryCode: US
88
+ adminName1: Texas
89
+ fraddl: "5401"
90
+ adminName2: Harris
91
+ toaddl: "5499"
92
+ mtfcc: S1400
93
+ distance: "0.08"
94
+ - placename: Houston
95
+ fraddr: "100"
96
+ name: Detering St
97
+ adminCode1: TX
98
+ adminCode2: "201"
99
+ line: -95.416239 29.763079,-95.41624 29.763143,-95.416248 29.763319
100
+ toaddr: "104"
101
+ postalcode: "77007"
102
+ countryCode: US
103
+ adminName1: Texas
104
+ fraddl: "97"
105
+ adminName2: Harris
106
+ toaddl: "103"
107
+ mtfcc: S1400
108
+ distance: "0.09"
109
+ - placename: Houston
110
+ fraddr: "2"
111
+ name: Aloe St
112
+ adminCode1: TX
113
+ adminCode2: "201"
114
+ line: -95.415507 29.760736,-95.415512 29.761566,-95.415537 29.761664
115
+ toaddr: "98"
116
+ postalcode: "77007"
117
+ countryCode: US
118
+ adminName1: Texas
119
+ fraddl: "1"
120
+ adminName2: Harris
121
+ toaddl: "99"
122
+ mtfcc: S1400
123
+ distance: "0.09"
124
+ - placename: Houston
125
+ fraddr:
126
+ name: Memorial Dr
127
+ adminCode1: TX
128
+ adminCode2: "201"
129
+ line: -95.411139 29.762166,-95.411423 29.762329,-95.412009 29.762617,-95.412455 29.762732,-95.412977 29.762836,-95.41339 29.762829,-95.413666 29.762772,-95.414041 29.762652,-95.414363 29.762522,-95.414682 29.762295,-95.414966 29.762058,-95.415191 29.761853,-95.415537 29.761664
130
+ toaddr:
131
+ postalcode: "77007"
132
+ countryCode: US
133
+ adminName1: Texas
134
+ fraddl: "601"
135
+ adminName2: Harris
136
+ toaddl: "699"
137
+ mtfcc: S1400
138
+ distance: "0.09"
139
+ - placename: Houston
140
+ fraddr: "5200"
141
+ name: Hohl St
142
+ adminCode1: TX
143
+ adminCode2: "201"
144
+ line: -95.414597 29.761651,-95.415382 29.761639,-95.415537 29.761664
145
+ toaddr: "5298"
146
+ postalcode: "77007"
147
+ countryCode: US
148
+ adminName1: Texas
149
+ fraddl: "5201"
150
+ adminName2: Harris
151
+ toaddl: "5299"
152
+ mtfcc: S1400
153
+ distance: "0.09"
@@ -0,0 +1,196 @@
1
+ --- !ruby/object:Net::HTTPOK
2
+ body: |-
3
+ <?xml version="1.0" encoding="UTF-8" standalone="no"?>
4
+ <geonames>
5
+ <streetSegment>
6
+ <line>-95.416216 29.762065,-95.416239 29.763079</line>
7
+ <distance>0.02</distance>
8
+ <mtfcc>S1400</mtfcc>
9
+ <name>Detering St</name>
10
+ <fraddl>37</fraddl>
11
+ <fraddr>38</fraddr>
12
+ <toaddl>95</toaddl>
13
+ <toaddr>98</toaddr>
14
+ <postalcode>77007</postalcode>
15
+ <placename>Houston</placename>
16
+ <adminCode2>201</adminCode2>
17
+ <adminName2>Harris</adminName2>
18
+ <adminCode1>TX</adminCode1>
19
+ <adminName1>Texas</adminName1>
20
+ <countryCode>US</countryCode>
21
+ </streetSegment>
22
+ <streetSegment>
23
+ <line>-95.41621 29.761482,-95.416216 29.762065</line>
24
+ <distance>0.02</distance>
25
+ <mtfcc>S1400</mtfcc>
26
+ <name>Detering St</name>
27
+ <fraddl>1</fraddl>
28
+ <fraddr>2</fraddr>
29
+ <toaddl>35</toaddl>
30
+ <toaddr>36</toaddr>
31
+ <postalcode>77007</postalcode>
32
+ <placename>Houston</placename>
33
+ <adminCode2>201</adminCode2>
34
+ <adminName2>Harris</adminName2>
35
+ <adminCode1>TX</adminCode1>
36
+ <adminName1>Texas</adminName1>
37
+ <countryCode>US</countryCode>
38
+ </streetSegment>
39
+ <streetSegment>
40
+ <line>-95.415808 29.761663,-95.41621 29.761482</line>
41
+ <distance>0.07</distance>
42
+ <mtfcc>S1400</mtfcc>
43
+ <name>Memorial Dr</name>
44
+ <fraddl>5301</fraddl>
45
+ <fraddr>5300</fraddr>
46
+ <toaddl>5399</toaddl>
47
+ <toaddr>5398</toaddr>
48
+ <postalcode>77007</postalcode>
49
+ <placename>Houston</placename>
50
+ <adminCode2>201</adminCode2>
51
+ <adminName2>Harris</adminName2>
52
+ <adminCode1>TX</adminCode1>
53
+ <adminName1>Texas</adminName1>
54
+ <countryCode>US</countryCode>
55
+ </streetSegment>
56
+ <streetSegment>
57
+ <line>-95.414351 29.762661,-95.414506 29.762576,-95.414876 29.762343,-95.415249 29.762011,-95.415699 29.761712,-95.415808 29.761663</line>
58
+ <distance>0.07</distance>
59
+ <mtfcc>S1400</mtfcc>
60
+ <name>Memorial Dr</name>
61
+ <fraddl>5239</fraddl>
62
+ <fraddr>5270</fraddr>
63
+ <toaddl>5299</toaddl>
64
+ <toaddr>5298</toaddr>
65
+ <postalcode>77007</postalcode>
66
+ <placename>Houston</placename>
67
+ <adminCode2>201</adminCode2>
68
+ <adminName2>Harris</adminName2>
69
+ <adminCode1>TX</adminCode1>
70
+ <adminName1>Texas</adminName1>
71
+ <countryCode>US</countryCode>
72
+ </streetSegment>
73
+ <streetSegment>
74
+ <line>-95.415537 29.761664,-95.415582 29.76164,-95.415705 29.761596,-95.41621 29.761482</line>
75
+ <distance>0.08</distance>
76
+ <mtfcc>S1400</mtfcc>
77
+ <name>Memorial Dr</name>
78
+ <fraddl/>
79
+ <fraddr/>
80
+ <toaddl/>
81
+ <toaddr/>
82
+ <postalcode/>
83
+ <placename>Houston</placename>
84
+ <adminCode2>201</adminCode2>
85
+ <adminName2>Harris</adminName2>
86
+ <adminCode1>TX</adminCode1>
87
+ <adminName1>Texas</adminName1>
88
+ <countryCode>US</countryCode>
89
+ </streetSegment>
90
+ <streetSegment>
91
+ <line>-95.41621 29.761482,-95.416936 29.761412,-95.417563 29.761378</line>
92
+ <distance>0.08</distance>
93
+ <mtfcc>S1400</mtfcc>
94
+ <name>Memorial Dr</name>
95
+ <fraddl>5401</fraddl>
96
+ <fraddr>5400</fraddr>
97
+ <toaddl>5499</toaddl>
98
+ <toaddr>5498</toaddr>
99
+ <postalcode>77007</postalcode>
100
+ <placename>Houston</placename>
101
+ <adminCode2>201</adminCode2>
102
+ <adminName2>Harris</adminName2>
103
+ <adminCode1>TX</adminCode1>
104
+ <adminName1>Texas</adminName1>
105
+ <countryCode>US</countryCode>
106
+ </streetSegment>
107
+ <streetSegment>
108
+ <line>-95.416239 29.763079,-95.41624 29.763143,-95.416248 29.763319</line>
109
+ <distance>0.09</distance>
110
+ <mtfcc>S1400</mtfcc>
111
+ <name>Detering St</name>
112
+ <fraddl>97</fraddl>
113
+ <fraddr>100</fraddr>
114
+ <toaddl>103</toaddl>
115
+ <toaddr>104</toaddr>
116
+ <postalcode>77007</postalcode>
117
+ <placename>Houston</placename>
118
+ <adminCode2>201</adminCode2>
119
+ <adminName2>Harris</adminName2>
120
+ <adminCode1>TX</adminCode1>
121
+ <adminName1>Texas</adminName1>
122
+ <countryCode>US</countryCode>
123
+ </streetSegment>
124
+ <streetSegment>
125
+ <line>-95.415507 29.760736,-95.415512 29.761566,-95.415537 29.761664</line>
126
+ <distance>0.09</distance>
127
+ <mtfcc>S1400</mtfcc>
128
+ <name>Aloe St</name>
129
+ <fraddl>1</fraddl>
130
+ <fraddr>2</fraddr>
131
+ <toaddl>99</toaddl>
132
+ <toaddr>98</toaddr>
133
+ <postalcode>77007</postalcode>
134
+ <placename>Houston</placename>
135
+ <adminCode2>201</adminCode2>
136
+ <adminName2>Harris</adminName2>
137
+ <adminCode1>TX</adminCode1>
138
+ <adminName1>Texas</adminName1>
139
+ <countryCode>US</countryCode>
140
+ </streetSegment>
141
+ <streetSegment>
142
+ <line>-95.411139 29.762166,-95.411423 29.762329,-95.412009 29.762617,-95.412455 29.762732,-95.412977 29.762836,-95.41339 29.762829,-95.413666 29.762772,-95.414041 29.762652,-95.414363 29.762522,-95.414682 29.762295,-95.414966 29.762058,-95.415191 29.761853,-95.415537 29.761664</line>
143
+ <distance>0.09</distance>
144
+ <mtfcc>S1400</mtfcc>
145
+ <name>Memorial Dr</name>
146
+ <fraddl>601</fraddl>
147
+ <fraddr/>
148
+ <toaddl>699</toaddl>
149
+ <toaddr/>
150
+ <postalcode>77007</postalcode>
151
+ <placename>Houston</placename>
152
+ <adminCode2>201</adminCode2>
153
+ <adminName2>Harris</adminName2>
154
+ <adminCode1>TX</adminCode1>
155
+ <adminName1>Texas</adminName1>
156
+ <countryCode>US</countryCode>
157
+ </streetSegment>
158
+ <streetSegment>
159
+ <line>-95.414597 29.761651,-95.415382 29.761639,-95.415537 29.761664</line>
160
+ <distance>0.09</distance>
161
+ <mtfcc>S1400</mtfcc>
162
+ <name>Hohl St</name>
163
+ <fraddl>5201</fraddl>
164
+ <fraddr>5200</fraddr>
165
+ <toaddl>5299</toaddl>
166
+ <toaddr>5298</toaddr>
167
+ <postalcode>77007</postalcode>
168
+ <placename>Houston</placename>
169
+ <adminCode2>201</adminCode2>
170
+ <adminName2>Harris</adminName2>
171
+ <adminCode1>TX</adminCode1>
172
+ <adminName1>Texas</adminName1>
173
+ <countryCode>US</countryCode>
174
+ </streetSegment>
175
+ </geonames>
176
+ body_exist: true
177
+ code: "200"
178
+ header:
179
+ content-type:
180
+ - text/xml;charset=UTF-8
181
+ connection:
182
+ - close
183
+ access-control-allow-origin:
184
+ - "*"
185
+ server:
186
+ - Apache/2.2.15 (Linux/SUSE)
187
+ date:
188
+ - Thu, 15 Sep 2011 23:09:37 GMT
189
+ cache-control:
190
+ - no-cache
191
+ transfer-encoding:
192
+ - chunked
193
+ http_version: "1.1"
194
+ message: OK
195
+ read: true
196
+ socket:
@@ -0,0 +1,221 @@
1
+ require 'spec_helper'
2
+
3
+ describe GeonamesClient::Location do
4
+
5
+ let :location do
6
+ described_class.new( 41.889118, -87.632146 )
7
+ end
8
+
9
+ context '#initialize' do
10
+
11
+ it "should accept and set #latitude_in_decimal_degrees" do
12
+ location.latitude_in_decimal_degrees.should == 41.889118
13
+ end
14
+
15
+ it "should accept and set #longitude_in_decimal_degrees" do
16
+ location.longitude_in_decimal_degrees.should == -87.632146
17
+ end
18
+
19
+ end
20
+
21
+ {
22
+ :northeast_theta => 45,
23
+ :northwest_theta => 135,
24
+ :southwest_theta => 225,
25
+ :southeast_theta => 315
26
+ }.each do |name, value|
27
+
28
+ context "##{name}" do
29
+
30
+ subject { location.send( name ) }
31
+
32
+ it { should == value }
33
+
34
+ end
35
+
36
+ end
37
+
38
+ {
39
+ :dx_northeast => 353.55,
40
+ :dx_northwest => -353.55,
41
+ :dx_southwest => -353.55,
42
+ :dx_southeast => 353.55
43
+ }.each do |name, value|
44
+
45
+ context "##{name}" do
46
+
47
+ subject { location.send( name, 500 ) }
48
+
49
+ it { should == value }
50
+
51
+ end
52
+
53
+ end
54
+
55
+ {
56
+ :dy_northeast => 353.55,
57
+ :dy_northwest => 353.55,
58
+ :dy_southwest => -353.55,
59
+ :dy_southeast => -353.55
60
+ }.each do |name, value|
61
+
62
+ context "##{name}" do
63
+
64
+ subject { location.send( name, 500 ) }
65
+
66
+ it { should == value }
67
+
68
+ end
69
+
70
+ end
71
+
72
+ {
73
+ :delta_latitude_northeast => 0.003198,
74
+ :delta_latitude_northwest => 0.003198,
75
+ :delta_latitude_southwest => -0.003198,
76
+ :delta_latitude_southeast => -0.003198
77
+ }.each do |name, value|
78
+
79
+ context "##{name}" do
80
+
81
+ subject { location.send( name, 500 ) }
82
+
83
+ it { should == value }
84
+
85
+ end
86
+
87
+ end
88
+
89
+ {
90
+ :delta_longitude_northeast => 0.004266,
91
+ :delta_longitude_northwest => -0.004266,
92
+ :delta_longitude_southwest => -0.004266,
93
+ :delta_longitude_southeast => 0.004266
94
+ }.each do |name, value|
95
+
96
+ context "##{name}" do
97
+
98
+ subject { location.send( name, 500 ) }
99
+
100
+ it { should == value }
101
+
102
+ end
103
+
104
+ end
105
+
106
+ {
107
+ :latitude_northeast => 41.892316,
108
+ :latitude_northwest => 41.892316,
109
+ :latitude_southwest => 41.88592,
110
+ :latitude_southeast => 41.88592
111
+ }.each do |name, value|
112
+
113
+ context "##{name}" do
114
+
115
+ subject { location.send( name, 500 ) }
116
+
117
+ it { should == value }
118
+
119
+ end
120
+
121
+ end
122
+
123
+ {
124
+ :longitude_northeast => -87.62788,
125
+ :longitude_northwest => -87.636412,
126
+ :longitude_southwest => -87.636412,
127
+ :longitude_southeast => -87.62788
128
+ }.each do |name, value|
129
+
130
+ context "##{name}" do
131
+
132
+ subject { location.send( name, 500 ) }
133
+
134
+ it { should == value }
135
+
136
+ end
137
+
138
+ end
139
+
140
+ {
141
+ :bounding_box_northeast_location => GeonamesClient::Location.new( 41.892316, -87.62788 ),
142
+ :bounding_box_northwest_location => GeonamesClient::Location.new( 41.892316, -87.636412 ),
143
+ :bounding_box_southwest_location => GeonamesClient::Location.new( 41.88592, -87.636412 ),
144
+ :bounding_box_southeast_location => GeonamesClient::Location.new( 41.88592, -87.62788 )
145
+ }.each do |name, value|
146
+
147
+ context "##{name}" do
148
+
149
+ subject { location.send( name, 500 ) }
150
+
151
+ it { should == value }
152
+
153
+ end
154
+
155
+ end
156
+
157
+ context "#bounding_box_locations" do
158
+
159
+ subject { location.bounding_box_locations( 500 ) }
160
+
161
+ it { should == [
162
+ GeonamesClient::Location.new( 41.892316, -87.62788 ),
163
+ GeonamesClient::Location.new( 41.892316, -87.636412 ),
164
+ GeonamesClient::Location.new( 41.88592, -87.636412 ),
165
+ GeonamesClient::Location.new( 41.88592, -87.62788 )
166
+ ]
167
+ }
168
+
169
+ end
170
+
171
+ context '#bounding_box_locations_as_array' do
172
+
173
+ subject { location.bounding_box_locations_as_array( 500 ) }
174
+
175
+ it { should == [
176
+ [41.892316, -87.62788],
177
+ [41.892316, -87.636412],
178
+ [41.88592, -87.636412],
179
+ [41.88592, -87.62788]
180
+ ]
181
+ }
182
+
183
+ end
184
+
185
+ context '#bounding_box_locations_as_hash_like_array' do
186
+
187
+ subject { location.bounding_box_locations_as_hash_like_array( 500 ) }
188
+
189
+ it { should == [
190
+ [:northeast, [41.892316, -87.62788]],
191
+ [:northwest, [41.892316, -87.636412]],
192
+ [:southwest, [41.88592, -87.636412]],
193
+ [:southeast, [41.88592, -87.62788]]
194
+ ]
195
+ }
196
+
197
+ end
198
+
199
+ context '#bounding_box_locations_as_hash' do
200
+
201
+ subject { location.bounding_box_locations_as_hash( 500 ) }
202
+
203
+ it { should == {
204
+ :northeast => [41.892316, -87.62788],
205
+ :northwest => [41.892316, -87.636412],
206
+ :southwest => [41.88592, -87.636412],
207
+ :southeast => [41.88592, -87.62788]
208
+ }
209
+ }
210
+
211
+ end
212
+
213
+ context '#to_a' do
214
+
215
+ subject { location.to_a }
216
+
217
+ it { should == [41.889118, -87.632146] }
218
+
219
+ end
220
+
221
+ end
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ describe GeonamesClient::NearbyStreet do
4
+
5
+ context '#initialize' do
6
+
7
+ context "accepting a name" do
8
+
9
+ subject { described_class.new( :name => 'Some St.' ).name }
10
+
11
+ it { should == 'Some St.' }
12
+
13
+ end
14
+
15
+ end
16
+
17
+ context '.all' do
18
+
19
+ subject { described_class.all( 'Some St.', 'Another St.' ) }
20
+
21
+ it { should == [
22
+ GeonamesClient::NearbyStreet.new( :name => 'Some St.' ),
23
+ GeonamesClient::NearbyStreet.new( :name => 'Another St.' )
24
+ ] }
25
+
26
+ end
27
+
28
+ end