geo_stalker 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a337515f5877c81dc3d08aa872b56b01818b6707
4
+ data.tar.gz: 38c28bb4259ea7b483b24384af6ec7dd170a8317
5
+ SHA512:
6
+ metadata.gz: 0bb56c82fcdf2d125347a64970009c35ce8aca40858db39a06226347af801ed9c5c0ebca1c77be911845ae86a34c414de8e2f4cb9e357ce24e2c8899ac55ad8a
7
+ data.tar.gz: 59625c616dfb4dc14b3d733866a7b1efbdb675115cc686d562842b141ba090f901fe1ce79b4367e0c3a2778b862bae32e685aa221a52728d7aa50b511be3a2ad
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.3
4
+ before_install: gem install bundler -v 1.10.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in geo_stalker.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Yoshiori SHOJI
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,45 @@
1
+ # GeoStalker
2
+
3
+ Get your location using your around wifi access point.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem "geo_stalker"
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install geo_stalker
20
+
21
+ ## Usage
22
+
23
+ ### Get api key
24
+
25
+ https://developers.google.com/maps/documentation/geolocation/get-api-key
26
+
27
+ ### location
28
+
29
+ ```ruby
30
+ require "geo_stalker"
31
+
32
+ stalker = GeoStalker::Locator.new(ENV["GOOGLE_API_KEY"])
33
+ p stalker.location # {"location"=>{"lat"=>29.4222384, "lng"=>-98.4830782}, "accuracy"=>48.0}
34
+ ```
35
+
36
+ ## Development
37
+
38
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake false` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment. Run `bundle exec geo_stalker` to use the gem in this directory, ignoring other installed copies of this gem.
39
+
40
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
41
+
42
+
43
+ ## License
44
+
45
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "geo_stalker"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
data/exe/geo_stalker ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require "geo_stalker"
3
+
4
+ puts GeoStalker::Locator.new(ENV["GOOGLE_API_KEY"]).location.to_json
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'geo_stalker/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "geo_stalker"
8
+ spec.version = GeoStalker::VERSION
9
+ spec.authors = ["Yoshiori SHOJI"]
10
+ spec.email = ["yoshiori@gmail.com"]
11
+
12
+ spec.summary = %q{Get your location using your around wifi access point.}
13
+ spec.description = %q{Get your location using your around wifi access point.}
14
+ spec.homepage = "https://github.com/yoshiori/geo_stalker"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_dependency "plist", "~> 3.1"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.10"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ end
@@ -0,0 +1,2 @@
1
+ require "geo_stalker/version"
2
+ require "geo_stalker/locator"
@@ -0,0 +1,26 @@
1
+ require "geo_stalker/locator/base"
2
+ require "geo_stalker/locator/darwin"
3
+
4
+ module GeoStalker
5
+ class Locator
6
+ extend Forwardable
7
+ def_delegators :locator, :location
8
+
9
+ def initialize(api_key)
10
+ @api_key = api_key
11
+ end
12
+
13
+ private
14
+
15
+ def locator
16
+ @locator ||= begin
17
+ case RUBY_PLATFORM
18
+ when /darwin/
19
+ GeoStalker::Locator::Darwin.new(@api_key)
20
+ when /linux/
21
+ GeoStalker::Locator::Linux.new(@api_key)
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,48 @@
1
+ require "net/https"
2
+ require "uri"
3
+ require "json"
4
+
5
+ module GeoStalker
6
+ class Locator
7
+ class Base
8
+ ENDPOINT = "https://www.googleapis.com/geolocation/v1/geolocate?key="
9
+
10
+ def initialize(api_key)
11
+ @api_key = api_key
12
+ end
13
+
14
+ def location
15
+ https.start do
16
+ request = Net::HTTP::Post.new(uri.request_uri)
17
+ request.body = params.to_json
18
+ request["Content-Type"] = "application/json"
19
+ response = https.request(request)
20
+ JSON.parse(response.body)
21
+ end
22
+ end
23
+
24
+ private
25
+
26
+ def wifi_access_points
27
+ fail NotImplementedError, "You must implement #{self.class}##{__method__}"
28
+ end
29
+
30
+ def params
31
+ { wifiAccessPoints: wifi_access_points }
32
+ end
33
+
34
+ def uri
35
+ @uri ||= URI.parse(ENDPOINT + @api_key)
36
+ end
37
+
38
+ def https
39
+ @https ||= begin
40
+ https = Net::HTTP.new(uri.host, uri.port)
41
+ https.use_ssl = true
42
+ https.verify_mode = OpenSSL::SSL::VERIFY_NONE
43
+ https
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,20 @@
1
+ require "plist"
2
+
3
+ module GeoStalker
4
+ class Locator
5
+ class Darwin < Base
6
+ COMMAND = "/System/Library/PrivateFrameworks/Apple80211.framework/Versions/A/Resources/airport -s -x"
7
+
8
+ def wifi_access_points
9
+ xml = `#{COMMAND}`
10
+ Plist.parse_xml(xml).map do |data|
11
+ {
12
+ macAddress: data["BSSID"],
13
+ signalStrength: data["RSSI"],
14
+ channel: data["CHANNEL"],
15
+ }
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,17 @@
1
+ module GeoStalker
2
+ class Locator
3
+ class Linux < Base
4
+ COMMAND = "iwlist wlan0 scan"
5
+
6
+ def wifi_access_points
7
+ lines = `#{COMMAND}`.split(/[\r\n]/)
8
+ lines.map do |line|
9
+ {
10
+ macAddress: line.split(/\s+/).last,
11
+ signalStrength: line.scan(/Signal level[:=](\-?\d+)/)[0][0].to_i,
12
+ }
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,3 @@
1
+ module GeoStalker
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: geo_stalker
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Yoshiori SHOJI
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-11-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: plist
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.10'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.10'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ description: Get your location using your around wifi access point.
56
+ email:
57
+ - yoshiori@gmail.com
58
+ executables:
59
+ - geo_stalker
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - ".travis.yml"
65
+ - Gemfile
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - bin/console
70
+ - bin/setup
71
+ - exe/geo_stalker
72
+ - geo_stalker.gemspec
73
+ - lib/geo_stalker.rb
74
+ - lib/geo_stalker/locator.rb
75
+ - lib/geo_stalker/locator/base.rb
76
+ - lib/geo_stalker/locator/darwin.rb
77
+ - lib/geo_stalker/locator/linux.rb
78
+ - lib/geo_stalker/version.rb
79
+ homepage: https://github.com/yoshiori/geo_stalker
80
+ licenses:
81
+ - MIT
82
+ metadata: {}
83
+ post_install_message:
84
+ rdoc_options: []
85
+ require_paths:
86
+ - lib
87
+ required_ruby_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ requirements: []
98
+ rubyforge_project:
99
+ rubygems_version: 2.4.5.1
100
+ signing_key:
101
+ specification_version: 4
102
+ summary: Get your location using your around wifi access point.
103
+ test_files: []