wifi_location 0.0.1

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,3 @@
1
+ === 0.0.1 2012-08-03
2
+
3
+ * first release
@@ -0,0 +1,12 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.rdoc
4
+ Rakefile
5
+ bin/wifi_location
6
+ lib/wifi_location.rb
7
+ samples/sample.rb
8
+ script/console
9
+ script/destroy
10
+ script/generate
11
+ test/test_helper.rb
12
+ test/test_wifi_location.rb
@@ -0,0 +1,49 @@
1
+ = wifi_location
2
+
3
+ * http://github.com/shokai/wifi_location
4
+
5
+ == DESCRIPTION:
6
+
7
+ Get your location with WiFi Mac Address and GoogleMap.
8
+
9
+ == SYNOPSIS:
10
+
11
+ require 'rubygems'
12
+ require 'wifi_location'
13
+ loc = WiFiLocation.location
14
+ puts "#{loc['latitude']}, #{loc['longitude']}"
15
+ p loc['address']
16
+
17
+
18
+ == REQUIREMENTS:
19
+
20
+ * WiFI, Mac OSX or Linux
21
+
22
+ == INSTALL:
23
+
24
+ * gem install wifi_location
25
+
26
+ == LICENSE:
27
+
28
+ (The MIT License)
29
+
30
+ Copyright (c) 2012 Sho Hashimoto
31
+
32
+ Permission is hereby granted, free of charge, to any person obtaining
33
+ a copy of this software and associated documentation files (the
34
+ 'Software'), to deal in the Software without restriction, including
35
+ without limitation the rights to use, copy, modify, merge, publish,
36
+ distribute, sublicense, and/or sell copies of the Software, and to
37
+ permit persons to whom the Software is furnished to do so, subject to
38
+ the following conditions:
39
+
40
+ The above copyright notice and this permission notice shall be
41
+ included in all copies or substantial portions of the Software.
42
+
43
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
44
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
45
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
46
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
47
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
48
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
49
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,25 @@
1
+ require 'rubygems'
2
+ gem 'hoe', '>= 2.1.0'
3
+ require 'hoe'
4
+ require 'fileutils'
5
+ require './lib/wifi_location'
6
+
7
+ Hoe.plugin :newgem
8
+ # Hoe.plugin :website
9
+ # Hoe.plugin :cucumberfeatures
10
+
11
+ # Generate all the Rake tasks
12
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
13
+ $hoe = Hoe.spec 'wifi_location' do
14
+ self.developer 'Sho Hashimoto', 'hashimoto@shokai.org'
15
+ self.rubyforge_name = self.name # TODO this is default value
16
+ # self.extra_deps = [['json','>= 1.5.3']]
17
+
18
+ end
19
+
20
+ require 'newgem/tasks'
21
+ Dir['tasks/**/*.rake'].each { |t| load t }
22
+
23
+ # TODO - want other tests/tasks run by default? Add them to the list
24
+ # remove_task :default
25
+ # task :default => [:spec, :features]
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ require File.expand_path '../lib/wifi_location', File.dirname(__FILE__)
3
+
4
+ towers = WiFiLocation.wifi_towers
5
+ puts "towers - #{towers.inspect}"
6
+
7
+ location = WiFiLocation.location towers
8
+ puts "location - #{location.inspect}"
9
+
10
+ puts "map - https://maps.google.com/?ll=#{location['latitude']},#{location['longitude']}&z=16"
@@ -0,0 +1,45 @@
1
+ require 'rubygems'
2
+ require 'net/http'
3
+ require 'uri'
4
+ require 'json'
5
+
6
+ module WiFiLocation
7
+ VERSION = '0.0.1'
8
+
9
+ def self.wifi_towers
10
+ case RUBY_PLATFORM
11
+ when /darwin/
12
+ lines = `/System/Library/PrivateFrameworks/Apple80211.framework/Versions/A/Resources/airport -s`.split(/[\r\n]/)
13
+ lines.shift
14
+ lines.map{|i|
15
+ a = i.scan(/[^\s]+/)
16
+ {:bssid => a[1], :signal => a[2].to_i}
17
+ }
18
+ when /linux/
19
+ lines = `iwlist wlan0 scan`.split(/[\r\n]/)
20
+ addrs = []
21
+ lines.each do |line|
22
+ addrs.push({:bssid => line.split(/\s+/).last, :signal => 8}) if line =~ /Address: /
23
+ addrs.last[:signal] = line.scan(/Signal level=(\-?\d+)/)[0][0].to_i rescue next if line =~ /Signal level=/
24
+ end
25
+ addrs
26
+ end
27
+ end
28
+
29
+ def self.location(wifi_towers=self.wifi_towers)
30
+ uri = URI.parse 'http://www.google.com/loc/json'
31
+ wifi_towers = self.wifi_towers unless wifi_towers
32
+ query = {
33
+ :version => '1.1.0',
34
+ :host => 'maps.google.com',
35
+ :request_address => true,
36
+ :address_language => ENV['LANG'] ? ENV['LANG'].scan(/([^\.]+)/)[0][0] : 'en_US',
37
+ :wifi_towers => wifi_towers.map{|addr| {:mac_address => addr[:bssid], :signal_strength => addr[:signal], :age => 0} }
38
+ }.to_json
39
+ headers = {'Content-Type' => 'application/x-www-form-urlencoded'}
40
+ res = Net::HTTP.start(uri.host, uri.port).request(Net::HTTP::Post.new(uri.request_uri, headers), query)
41
+ raise "Response Error (#{res.code})" unless res.code.to_i == 200
42
+ JSON.parse(res.body)['location']
43
+ end
44
+
45
+ end
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rubygems'
3
+ require 'wifi_location'
4
+ loc = WiFiLocation.location
5
+ puts "#{loc['latitude']}, #{loc['longitude']}"
6
+ p loc
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ # File: script/console
3
+ irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
4
+
5
+ libs = " -r irb/completion"
6
+ # Perhaps use a console_lib to store any extra methods I may want available in the cosole
7
+ # libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
8
+ libs << " -r #{File.dirname(__FILE__) + '/../lib/wifi_location.rb'}"
9
+ puts "Loading wifi_location gem"
10
+ exec "#{irb} #{libs} --simple-prompt"
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/destroy'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Destroy.new.run(ARGV)
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/generate'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Generate.new.run(ARGV)
@@ -0,0 +1,3 @@
1
+ require 'stringio'
2
+ require 'test/unit'
3
+ require File.dirname(__FILE__) + '/../lib/wifi_location'
@@ -0,0 +1,27 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class TestWiFiLocation < Test::Unit::TestCase
4
+ def setup
5
+ @location = WiFiLocation.location
6
+ end
7
+
8
+ def test_location
9
+ assert @location.class == Hash
10
+ end
11
+
12
+ def test_latitude
13
+ assert @location['latitude'].class == Float
14
+ end
15
+
16
+ def test_longitude
17
+ assert @location['longitude'].class == Float
18
+ end
19
+
20
+ def test_address
21
+ assert @location['address'].class == Hash
22
+ end
23
+
24
+ def test_accuracy
25
+ assert @location['accuracy'].class == Float
26
+ end
27
+ end
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wifi_location
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Sho Hashimoto
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-08-03 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rdoc
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '3.10'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '3.10'
30
+ - !ruby/object:Gem::Dependency
31
+ name: newgem
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: 1.5.3
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: 1.5.3
46
+ - !ruby/object:Gem::Dependency
47
+ name: hoe
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '3.0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ description: Get your location with WiFi Mac Address and GoogleMap.
63
+ email:
64
+ - hashimoto@shokai.org
65
+ executables:
66
+ - wifi_location
67
+ extensions: []
68
+ extra_rdoc_files:
69
+ - History.txt
70
+ - Manifest.txt
71
+ - README.rdoc
72
+ files:
73
+ - History.txt
74
+ - Manifest.txt
75
+ - README.rdoc
76
+ - Rakefile
77
+ - bin/wifi_location
78
+ - lib/wifi_location.rb
79
+ - samples/sample.rb
80
+ - script/console
81
+ - script/destroy
82
+ - script/generate
83
+ - test/test_helper.rb
84
+ - test/test_wifi_location.rb
85
+ - .gemtest
86
+ homepage: http://github.com/shokai/wifi_location
87
+ licenses: []
88
+ post_install_message:
89
+ rdoc_options:
90
+ - --main
91
+ - README.rdoc
92
+ require_paths:
93
+ - lib
94
+ required_ruby_version: !ruby/object:Gem::Requirement
95
+ none: false
96
+ requirements:
97
+ - - ! '>='
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ none: false
102
+ requirements:
103
+ - - ! '>='
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ requirements: []
107
+ rubyforge_project: wifi_location
108
+ rubygems_version: 1.8.24
109
+ signing_key:
110
+ specification_version: 3
111
+ summary: Get your location with WiFi Mac Address and GoogleMap.
112
+ test_files:
113
+ - test/test_helper.rb
114
+ - test/test_wifi_location.rb