where_are_you 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/where_are_you.rb +39 -0
- metadata +44 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 20c0a75e05b536627926b02983a1b04d5204968b
|
4
|
+
data.tar.gz: 0a9445e07675d1142563eb929d6f559a1c5d7ea7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 28cb6dd0b0d997831412985280d6d052b353b29b22eef3fb48677c196ce42f21c06d70e5f384cc9e7ae7881d62023aaa313f9c71258e73b4f3954111f47c3908
|
7
|
+
data.tar.gz: 6b301d9dc82eb19a97d470418760213f7120a48ae997a7b7f7a0cd44fd1a4d2d2e0ce3a5eaf95338a9e0a6e33acc5b1848d2a61b010782d9e0c7ec66f80fd837
|
@@ -0,0 +1,39 @@
|
|
1
|
+
|
2
|
+
class Object
|
3
|
+
def where_are_you(ip, format = 'city', global = false)
|
4
|
+
|
5
|
+
require 'net/http'
|
6
|
+
require 'json' # already included in Rails
|
7
|
+
|
8
|
+
uri = URI.parse("http://ip-api.com/json/#{ip}")
|
9
|
+
response = Net::HTTP.get_response(uri)
|
10
|
+
result = JSON(response.body)
|
11
|
+
|
12
|
+
if result['status'] != 'success'
|
13
|
+
|
14
|
+
return nil
|
15
|
+
|
16
|
+
elsif format == 'city'
|
17
|
+
|
18
|
+
if global || result['country'] == 'United States'
|
19
|
+
return result['city'] + ', ' + result['region']
|
20
|
+
else
|
21
|
+
return nil
|
22
|
+
end
|
23
|
+
|
24
|
+
elsif format == 'state'
|
25
|
+
|
26
|
+
if global || result['country'] == 'United States'
|
27
|
+
return result['regionName']
|
28
|
+
else
|
29
|
+
return nil
|
30
|
+
end
|
31
|
+
|
32
|
+
elsif format == 'country'
|
33
|
+
|
34
|
+
return result['country']
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
metadata
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: where_are_you
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Stelios Constantinides
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-07-16 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Returns the city, state, or country for the current user using IP-API.com.
|
14
|
+
email: sconstantinides@gmail.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/where_are_you.rb
|
20
|
+
homepage: https://github.com/sconstantinides/where_are_you
|
21
|
+
licenses:
|
22
|
+
- MIT
|
23
|
+
metadata: {}
|
24
|
+
post_install_message:
|
25
|
+
rdoc_options: []
|
26
|
+
require_paths:
|
27
|
+
- lib
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - ">="
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
requirements: []
|
39
|
+
rubyforge_project:
|
40
|
+
rubygems_version: 2.2.2
|
41
|
+
signing_key:
|
42
|
+
specification_version: 4
|
43
|
+
summary: Returns the city, state, or country for the current user.
|
44
|
+
test_files: []
|