locationator 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/Gemfile.lock +1 -1
- data/README.md +4 -0
- data/lib/locationator.rb +26 -0
- data/lib/locationator/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZTMzZjZmYmVmODA1ZmUxNjZkZTBlN2Y4ZTNlZmRhMGEzYjM2ZDNiMA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MmFlZjA4NzU2N2Y2NGQzYmI2Y2ViM2YyYjFiMjU3NmQ4ZGY3NDIzOQ==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
Zjg2NWFmYjMwYmJjMGIzZjQxNTVmN2EzMmE3NDg1MjUzOTA1Yjg3ZGMwZDQw
|
10
|
+
ODY2MjBmOGU5NTg3N2RlOTRkZGE4YTA0NTlhMTNiY2FmMTNiNGE1NGRlODg2
|
11
|
+
ZTMxOWMzZjg3YThlNTYyNWU2YjQ5MmU2NjMwZGVjYzg5Zjg2NjM=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MWZkMWU4YTdlZDgxOWYyMTA2YmRjZDA2YjQzMDdhNTQ3MmMzOGZkNzc2YTNj
|
14
|
+
NGRjNjU2NTFiMWQ4M2E5MzZlZDg0ZjM5ZmY3M2M2OTYyMWRmYjU4MTAzOWU4
|
15
|
+
MGM0Nzk0MjUyZDViNTUzOWIxZTQ2OWRlOWU4NzkzMDk2Mjc5MDM=
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -43,6 +43,10 @@ Return the properly formatted version of an address
|
|
43
43
|
$ Locationator.format("800 W. Huron St Chicago, IL")
|
44
44
|
=> "800 West Huron Street, Chicago, IL 60642, USA"
|
45
45
|
|
46
|
+
## TODOs
|
47
|
+
1. Find a better way of locating the postal code in Google Maps' JSON response.
|
48
|
+
2. Find a better way of validating the array generated by the lat_lng method.
|
49
|
+
|
46
50
|
## Contributing
|
47
51
|
|
48
52
|
1. Fork it
|
data/lib/locationator.rb
CHANGED
@@ -44,6 +44,26 @@ module Locationator
|
|
44
44
|
result = geocodeResponse["status"] == "ZERO_RESULTS" ? "Address not found." : geocodeResponse["results"][0]["formatted_address"]
|
45
45
|
end
|
46
46
|
|
47
|
+
# Returns the latitude based on the current user's IP address
|
48
|
+
def self.ip_lat
|
49
|
+
geocodeResponse = get_ip_data
|
50
|
+
result = geocodeResponse["latitude"]
|
51
|
+
end
|
52
|
+
|
53
|
+
# Returns the longitude based on the current user's IP address
|
54
|
+
def self.ip_lng
|
55
|
+
geocodeResponse = get_ip_data
|
56
|
+
result = geocodeResponse["longitude"]
|
57
|
+
end
|
58
|
+
|
59
|
+
# Returns an array of the latitude and longitude based on the current user's IP address
|
60
|
+
def self.ip_lat_lng
|
61
|
+
myArray = []
|
62
|
+
myArray.push(self.ip_lat)
|
63
|
+
myArray.push(self.ip_lng)
|
64
|
+
result = myArray
|
65
|
+
end
|
66
|
+
|
47
67
|
private
|
48
68
|
|
49
69
|
# Builds the URL that we need to get our JSON response from Google
|
@@ -56,4 +76,10 @@ module Locationator
|
|
56
76
|
data = JSON.parse(response.body)
|
57
77
|
end
|
58
78
|
|
79
|
+
def self.get_ip_data
|
80
|
+
geocodePrimary = "http://freegeoip.net/json/"
|
81
|
+
response = Net::HTTP.get_response(URI.parse(geocodePrimary))
|
82
|
+
data = JSON.parse(response.body)
|
83
|
+
end
|
84
|
+
|
59
85
|
end
|
data/lib/locationator/version.rb
CHANGED