geolocater 0.0.1 → 0.1.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.
File without changes
@@ -0,0 +1,2 @@
1
+ lib/geolocater.rb 13250f189206ce61e8f4f31e32ce87f3ddd15f9a
2
+ lib/geolocater/version.rb 0224f4ef419378e3610e7cbda0f5daebbdc8b747
Binary file
@@ -0,0 +1,2 @@
1
+ {I" Object:EF:
2
+ class
data/HISTORY.md CHANGED
@@ -1,13 +1,17 @@
1
1
  HISTORY
2
2
  =======
3
+ 0.1.0 - January 12th 2012
4
+ --------------------------
5
+ * Complete refactor based off advice from (Reddit /r/ruby thread)[http://www.reddit.com/r/ruby/comments/odfs3/just_wrote_published_my_first_simple_gem_can_i/]
6
+ * Can now call 'geolocate_ip' as a standalone Gem method and an instance method.
7
+ * Removed IP regex and moved to the IPAddr Ruby standard lib for IP validation.
3
8
 
4
9
  0.0.1 - January 11th 2012
5
10
  --------------------------
6
- * Refactored the core 'geolocater.rb' lib into 2 methods
7
- * Changed core from Module to Class
8
- * Wrote simple unit tests - PASSING
11
+ * Extract code from Rails project
12
+ * Wrote simple functionality tests - PASSED
9
13
 
10
14
  0.0.1.alpha - January 11th 2012
11
15
  --------------------------
12
16
  * Extract code from Rails project
13
- * Wrote simple functionality tests - PASSED
17
+ * Wrote simple functionality tests
data/README.md CHANGED
@@ -9,12 +9,20 @@ Yet Another IP Geolocation Gem for Fun and Profit!
9
9
  ### Usage
10
10
  Pass any properly formatted IPv4 address string to a new instance of Geolocater like so.
11
11
 
12
- `Geolocater.ip_lookup(IP_ADDRESS_STRING)`
12
+ `Geolocater.geolocate_ip(IP_ADDRESS_STRING)`
13
+
14
+ and get back a JSON Hash of the results
15
+
16
+ `=> {"city"=>"CITY", "region_code"=>"ST", "region_name"=>"Region Name",
17
+ "metrocode"=>"999", "zipcode"=>"98765", "longitude"=>"-92.23",
18
+ "country_name"=>"United States", "country_code"=>"US",
19
+ "ip"=>"IP_ADDRESS", "latitude"=>"27.54"}`
13
20
 
14
21
  ### Details
15
22
  * This library uses the free (and very good) [freegeoip.net](http://freegeoip.net) REST API.
16
23
  * Results are returned in JSON format. For friendlier Ruby object-like results (and better nil handling), pipe the result hash into a new [Hashie::Mash](https://github.com/intridea/hashie) like so:
17
- ** `Hashie::Mash.new(Geolocater.ip_lookup(IP_ADDRESS_STRING))`
24
+
25
+ `Hashie::Mash.new(Geolocater.ip_lookup(IP_ADDRESS_STRING))`
18
26
 
19
27
  ### Future Features
20
28
  * Add multiple geolocation services in the event the freegeoip service goes down
@@ -26,3 +34,4 @@ Pass any properly formatted IPv4 address string to a new instance of Geolocater
26
34
  ### Thanks!
27
35
  * <dbarrett83@gmail.com>
28
36
  * [Twitter](http://www.twitter.com/thoughtpunch)
37
+
@@ -0,0 +1,430 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4
+ <head>
5
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
6
+ <title>
7
+ Class: Geolocater
8
+
9
+ &mdash; Documentation by YARD 0.7.4
10
+
11
+ </title>
12
+
13
+ <link rel="stylesheet" href="css/style.css" type="text/css" media="screen" charset="utf-8" />
14
+
15
+ <link rel="stylesheet" href="css/common.css" type="text/css" media="screen" charset="utf-8" />
16
+
17
+ <script type="text/javascript" charset="utf-8">
18
+ relpath = '';
19
+ if (relpath != '') relpath += '/';
20
+ </script>
21
+
22
+ <script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
23
+
24
+ <script type="text/javascript" charset="utf-8" src="js/app.js"></script>
25
+
26
+
27
+ </head>
28
+ <body>
29
+ <script type="text/javascript" charset="utf-8">
30
+ if (window.top.frames.main) document.body.className = 'frames';
31
+ </script>
32
+
33
+ <div id="header">
34
+ <div id="menu">
35
+
36
+ <a href="_index.html">Index (G)</a> &raquo;
37
+
38
+
39
+ <span class="title">Geolocater</span>
40
+
41
+
42
+ <div class="noframes"><span class="title">(</span><a href="." target="_top">no frames</a><span class="title">)</span></div>
43
+ </div>
44
+
45
+ <div id="search">
46
+
47
+ <a id="class_list_link" href="#">Class List</a>
48
+
49
+ <a id="method_list_link" href="#">Method List</a>
50
+
51
+ <a id="file_list_link" href="#">File List</a>
52
+
53
+ </div>
54
+ <div class="clear"></div>
55
+ </div>
56
+
57
+ <iframe id="search_frame"></iframe>
58
+
59
+ <div id="content"><h1>Class: Geolocater
60
+
61
+
62
+
63
+ </h1>
64
+
65
+ <dl class="box">
66
+
67
+ <dt class="r1">Inherits:</dt>
68
+ <dd class="r1">
69
+ <span class="inheritName">Object</span>
70
+
71
+ <ul class="fullTree">
72
+ <li>Object</li>
73
+
74
+ <li class="next">Geolocater</li>
75
+
76
+ </ul>
77
+ <a href="#" class="inheritanceTree">show all</a>
78
+
79
+ </dd>
80
+
81
+
82
+
83
+
84
+
85
+
86
+
87
+
88
+
89
+ <dt class="r2 last">Defined in:</dt>
90
+ <dd class="r2 last">lib/geolocater.rb<span class="defines">,<br />
91
+ lib/geolocater/version.rb</span>
92
+ </dd>
93
+
94
+ </dl>
95
+ <div class="clear"></div>
96
+
97
+
98
+ <h2>Constant Summary</h2>
99
+
100
+ <dl class="constants">
101
+
102
+ <dt id="REQUEST_URI-constant" class="">REQUEST_URI =
103
+
104
+ </dt>
105
+ <dd><pre class="code"><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>http://freegeoip.net/json/</span><span class='tstring_end'>&quot;</span></span></pre></dd>
106
+
107
+ <dt id="VERSION-constant" class="">VERSION =
108
+
109
+ </dt>
110
+ <dd><pre class="code"><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>0.1.0</span><span class='tstring_end'>&quot;</span></span></pre></dd>
111
+
112
+ </dl>
113
+
114
+
115
+
116
+ <h2>Instance Attribute Summary <small>(<a href="#" class="summary_toggle">collapse</a>)</small></h2>
117
+ <ul class="summary">
118
+
119
+ <li class="public ">
120
+ <span class="summary_signature">
121
+
122
+ <a href="#ip_address-instance_method" title="#ip_address (instance method)">- (Object) <strong>ip_address</strong> </a>
123
+
124
+
125
+
126
+ </span>
127
+
128
+
129
+
130
+
131
+
132
+
133
+
134
+
135
+
136
+
137
+
138
+ <span class="summary_desc"><div class='inline'><p>
139
+ Returns the value of attribute ip_address.
140
+ </p>
141
+ </div></span>
142
+
143
+ </li>
144
+
145
+
146
+ </ul>
147
+
148
+
149
+
150
+
151
+
152
+ <h2>
153
+ Class Method Summary
154
+ <small>(<a href="#" class="summary_toggle">collapse</a>)</small>
155
+ </h2>
156
+
157
+ <ul class="summary">
158
+
159
+ <li class="public ">
160
+ <span class="summary_signature">
161
+
162
+ <a href="#geolocate_ip-class_method" title="geolocate_ip (class method)">+ (Object) <strong>geolocate_ip</strong>(ip_address) </a>
163
+
164
+
165
+
166
+ </span>
167
+
168
+
169
+
170
+
171
+
172
+
173
+
174
+
175
+ <span class="summary_desc"><div class='inline'></div></span>
176
+
177
+ </li>
178
+
179
+
180
+ </ul>
181
+
182
+ <h2>
183
+ Instance Method Summary
184
+ <small>(<a href="#" class="summary_toggle">collapse</a>)</small>
185
+ </h2>
186
+
187
+ <ul class="summary">
188
+
189
+ <li class="public ">
190
+ <span class="summary_signature">
191
+
192
+ <a href="#geolocate_ip-instance_method" title="#geolocate_ip (instance method)">- (Object) <strong>geolocate_ip</strong> </a>
193
+
194
+
195
+
196
+ </span>
197
+
198
+
199
+
200
+
201
+
202
+
203
+
204
+
205
+ <span class="summary_desc"><div class='inline'></div></span>
206
+
207
+ </li>
208
+
209
+
210
+ <li class="public ">
211
+ <span class="summary_signature">
212
+
213
+ <a href="#initialize-instance_method" title="#initialize (instance method)">- (Geolocater) <strong>initialize</strong>(ip_address) </a>
214
+
215
+
216
+
217
+ </span>
218
+
219
+ <span class="note title constructor">constructor</span>
220
+
221
+
222
+
223
+
224
+
225
+
226
+
227
+
228
+ <span class="summary_desc"><div class='inline'><p>
229
+ A new instance of Geolocater.
230
+ </p>
231
+ </div></span>
232
+
233
+ </li>
234
+
235
+
236
+ </ul>
237
+
238
+
239
+ <div id="constructor_details" class="method_details_list">
240
+ <h2>Constructor Details</h2>
241
+
242
+ <div class="method_details first">
243
+ <p class="signature first" id="initialize-instance_method">
244
+
245
+ - (<tt><span class='object_link'><a href="" title="Geolocater (class)">Geolocater</a></span></tt>) <strong>initialize</strong>(ip_address)
246
+
247
+
248
+
249
+ </p><div class="docstring">
250
+ <div class="discussion">
251
+ <p>
252
+ A new instance of Geolocater
253
+ </p>
254
+
255
+
256
+ </div>
257
+ </div>
258
+ <div class="tags">
259
+
260
+
261
+ </div><table class="source_code">
262
+ <tr>
263
+ <td>
264
+ <pre class="lines">
265
+
266
+
267
+ 11
268
+ 12
269
+ 13
270
+ 14</pre>
271
+ </td>
272
+ <td>
273
+ <pre class="code"><span class="info file"># File 'lib/geolocater.rb', line 11</span>
274
+
275
+ <span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span><span class='lparen'>(</span><span class='id identifier rubyid_ip_address'>ip_address</span><span class='rparen'>)</span>
276
+ <span class='ivar'>@ip_address</span> <span class='op'>=</span> <span class='const'>IPAddr</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span> <span class='id identifier rubyid_ip_address'>ip_address</span>
277
+ <span class='id identifier rubyid_raise'>raise</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>IPv6 NOT SUPPORTED</span><span class='tstring_end'>&quot;</span></span> <span class='kw'>if</span> <span class='ivar'>@ip_address</span><span class='period'>.</span><span class='id identifier rubyid_ipv6?'>ipv6?</span>
278
+ <span class='kw'>end</span></pre>
279
+ </td>
280
+ </tr>
281
+ </table>
282
+ </div>
283
+
284
+ </div>
285
+
286
+ <div id="instance_attr_details" class="attr_details">
287
+ <h2>Instance Attribute Details</h2>
288
+
289
+
290
+ <span id="ip_address=-instance_method"></span>
291
+ <span id="ip_address-instance_method"></span>
292
+ <div class="method_details first">
293
+ <p class="signature first" id="ip_address-instance_method">
294
+
295
+ - (<tt>Object</tt>) <strong>ip_address</strong>
296
+
297
+
298
+
299
+ </p><div class="docstring">
300
+ <div class="discussion">
301
+ <p>
302
+ Returns the value of attribute ip_address
303
+ </p>
304
+
305
+
306
+ </div>
307
+ </div>
308
+ <div class="tags">
309
+
310
+
311
+ </div><table class="source_code">
312
+ <tr>
313
+ <td>
314
+ <pre class="lines">
315
+
316
+
317
+ 9
318
+ 10
319
+ 11</pre>
320
+ </td>
321
+ <td>
322
+ <pre class="code"><span class="info file"># File 'lib/geolocater.rb', line 9</span>
323
+
324
+ <span class='kw'>def</span> <span class='id identifier rubyid_ip_address'>ip_address</span>
325
+ <span class='ivar'>@ip_address</span>
326
+ <span class='kw'>end</span></pre>
327
+ </td>
328
+ </tr>
329
+ </table>
330
+ </div>
331
+
332
+ </div>
333
+
334
+
335
+ <div id="class_method_details" class="method_details_list">
336
+ <h2>Class Method Details</h2>
337
+
338
+
339
+ <div class="method_details first">
340
+ <p class="signature first" id="geolocate_ip-class_method">
341
+
342
+ + (<tt>Object</tt>) <strong>geolocate_ip</strong>(ip_address)
343
+
344
+
345
+
346
+ </p><table class="source_code">
347
+ <tr>
348
+ <td>
349
+ <pre class="lines">
350
+
351
+
352
+ 29
353
+ 30
354
+ 31
355
+ 32</pre>
356
+ </td>
357
+ <td>
358
+ <pre class="code"><span class="info file"># File 'lib/geolocater.rb', line 29</span>
359
+
360
+ <span class='kw'>def</span> <span class='id identifier rubyid_geolocate_ip'>geolocate_ip</span><span class='lparen'>(</span><span class='id identifier rubyid_ip_address'>ip_address</span><span class='rparen'>)</span>
361
+ <span class='id identifier rubyid_geolocator'>geolocator</span> <span class='op'>=</span> <span class='const'>Geolocater</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_ip_address'>ip_address</span><span class='rparen'>)</span>
362
+ <span class='id identifier rubyid_geolocator'>geolocator</span><span class='period'>.</span><span class='id identifier rubyid_geolocate_ip'>geolocate_ip</span>
363
+ <span class='kw'>end</span></pre>
364
+ </td>
365
+ </tr>
366
+ </table>
367
+ </div>
368
+
369
+ </div>
370
+
371
+ <div id="instance_method_details" class="method_details_list">
372
+ <h2>Instance Method Details</h2>
373
+
374
+
375
+ <div class="method_details first">
376
+ <p class="signature first" id="geolocate_ip-instance_method">
377
+
378
+ - (<tt>Object</tt>) <strong>geolocate_ip</strong>
379
+
380
+
381
+
382
+ </p><table class="source_code">
383
+ <tr>
384
+ <td>
385
+ <pre class="lines">
386
+
387
+
388
+ 16
389
+ 17
390
+ 18
391
+ 19
392
+ 20
393
+ 21
394
+ 22
395
+ 23
396
+ 24
397
+ 25
398
+ 26</pre>
399
+ </td>
400
+ <td>
401
+ <pre class="code"><span class="info file"># File 'lib/geolocater.rb', line 16</span>
402
+
403
+ <span class='kw'>def</span> <span class='id identifier rubyid_geolocate_ip'>geolocate_ip</span>
404
+ <span class='id identifier rubyid_http_response'>http_response</span> <span class='op'>=</span> <span class='const'>Faraday</span><span class='period'>.</span><span class='id identifier rubyid_get'>get</span> <span class='const'>REQUEST_URI</span> <span class='op'>+</span> <span class='id identifier rubyid_ip_address'>ip_address</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span>
405
+ <span class='kw'>if</span> <span class='id identifier rubyid_http_response'>http_response</span><span class='period'>.</span><span class='id identifier rubyid_success?'>success?</span> <span class='op'>==</span> <span class='kw'>true</span> <span class='op'>&amp;&amp;</span> <span class='id identifier rubyid_http_response'>http_response</span><span class='period'>.</span><span class='id identifier rubyid_status'>status</span> <span class='op'>==</span> <span class='int'>200</span><span class='semicolon'>;</span>
406
+ <span class='id identifier rubyid_geolocated_info'>geolocated_info</span> <span class='op'>=</span> <span class='const'>JSON</span><span class='period'>.</span><span class='id identifier rubyid_parse'>parse</span><span class='lparen'>(</span><span class='id identifier rubyid_http_response'>http_response</span><span class='period'>.</span><span class='id identifier rubyid_body'>body</span><span class='rparen'>)</span>
407
+ <span class='kw'>if</span> <span class='id identifier rubyid_geolocated_info'>geolocated_info</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>city</span><span class='tstring_end'>&quot;</span></span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_empty?'>empty?</span>
408
+ <span class='id identifier rubyid_raise'>raise</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Incomplete record. Please try another IP address</span><span class='tstring_end'>&quot;</span></span>
409
+ <span class='kw'>else</span>
410
+ <span class='kw'>return</span> <span class='id identifier rubyid_geolocated_info'>geolocated_info</span>
411
+ <span class='kw'>end</span>
412
+ <span class='kw'>end</span>
413
+ <span class='kw'>end</span></pre>
414
+ </td>
415
+ </tr>
416
+ </table>
417
+ </div>
418
+
419
+ </div>
420
+
421
+ </div>
422
+
423
+ <div id="footer">
424
+ Generated on Thu Jan 12 14:07:32 2012 by
425
+ <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
426
+ 0.7.4 (ruby-1.9.2).
427
+ </div>
428
+
429
+ </body>
430
+ </html>