wifi_location 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,8 @@
1
+ === 0.0.2 2012-08-03
2
+
3
+ * add whereami command
4
+
5
+
1
6
  === 0.0.1 2012-08-03
2
7
 
3
8
  * first release
@@ -2,7 +2,7 @@ History.txt
2
2
  Manifest.txt
3
3
  README.rdoc
4
4
  Rakefile
5
- bin/wifi_location
5
+ bin/whereami
6
6
  lib/wifi_location.rb
7
7
  samples/sample.rb
8
8
  script/console
@@ -6,6 +6,19 @@
6
6
 
7
7
  Get your location with WiFi Mac Address and GoogleMap.
8
8
 
9
+
10
+ == INSTALL:
11
+
12
+ % gem install wifi_location
13
+
14
+
15
+ == GET Location:
16
+
17
+ % which whereami
18
+ % whereami --help
19
+ % whereami --dump
20
+
21
+
9
22
  == SYNOPSIS:
10
23
 
11
24
  require 'rubygems'
@@ -17,11 +30,8 @@ Get your location with WiFi Mac Address and GoogleMap.
17
30
 
18
31
  == REQUIREMENTS:
19
32
 
20
- * WiFI, Mac OSX or Linux
21
-
22
- == INSTALL:
33
+ * WiFi, Mac OSX or Linux
23
34
 
24
- * gem install wifi_location
25
35
 
26
36
  == LICENSE:
27
37
 
data/Rakefile CHANGED
@@ -12,8 +12,10 @@ Hoe.plugin :newgem
12
12
  # Run 'rake -T' to see list of generated tasks (from gem root directory)
13
13
  $hoe = Hoe.spec 'wifi_location' do
14
14
  self.developer 'Sho Hashimoto', 'hashimoto@shokai.org'
15
+ self.post_install_message = "!! You can get your location with \"whereami\" command. For more information on wifi_location, see https://rubygems.org/gems/wifi_location"
15
16
  self.rubyforge_name = self.name # TODO this is default value
16
- # self.extra_deps = [['json','>= 1.5.3']]
17
+ self.extra_deps = [['json','>= 1.5.3'],
18
+ ['args_parser', '>= 0.0.2']]
17
19
 
18
20
  end
19
21
 
@@ -0,0 +1,54 @@
1
+ #!/usr/bin/env ruby
2
+ require File.expand_path '../lib/wifi_location', File.dirname(__FILE__)
3
+ require 'rubygems'
4
+ require 'args_parser'
5
+ require 'json'
6
+
7
+ parser = ArgsParser.parse ARGV do
8
+ arg :help, 'show help', :alias => :h
9
+ arg :towers, 'dump WiFi towers'
10
+ arg :dump, 'dump ALL'
11
+ arg :map, 'open Google Map'
12
+ arg :version, 'show version', :alias => :v
13
+ end
14
+
15
+ if parser.has_option? :help
16
+ puts parser.help
17
+ puts "--"
18
+ puts "wifi_location v#{WiFiLocation::VERSION} - https://github.com/shokai/wifi_location"
19
+ exit
20
+ end
21
+
22
+ if parser.has_option? :version
23
+ puts "wifi_location v#{WiFiLocation::VERSION} - https://github.com/shokai/wifi_location"
24
+ exit
25
+ end
26
+
27
+ if parser.has_option? :towers
28
+ puts WiFiLocation.wifi_towers.to_json
29
+ exit
30
+ end
31
+
32
+ if parser.has_option? :dump
33
+ towers = WiFiLocation.wifi_towers
34
+ location = WiFiLocation.location towers
35
+ h = {:towers => towers, :location => location}
36
+ puts h.to_json
37
+ exit
38
+ end
39
+
40
+ if parser.has_option? :map
41
+ location = WiFiLocation.location
42
+ puts url = "https://maps.google.com/?ll=#{location['latitude']},#{location['longitude']}"
43
+ ['xdg-open', 'open'].each do |cmd|
44
+ cmd = `which #{cmd}`.strip
45
+ unless cmd.empty?
46
+ system "#{cmd} #{url}"
47
+ break
48
+ end
49
+ end
50
+ exit
51
+ end
52
+
53
+ location = WiFiLocation.location
54
+ puts "lat=#{location['latitude']},lon=#{location['longitude']}"
@@ -4,7 +4,7 @@ require 'uri'
4
4
  require 'json'
5
5
 
6
6
  module WiFiLocation
7
- VERSION = '0.0.1'
7
+ VERSION = '0.0.2'
8
8
 
9
9
  def self.wifi_towers
10
10
  case RUBY_PLATFORM
@@ -13,14 +13,14 @@ module WiFiLocation
13
13
  lines.shift
14
14
  lines.map{|i|
15
15
  a = i.scan(/[^\s]+/)
16
- {:bssid => a[1], :signal => a[2].to_i}
16
+ {'bssid' => a[1], 'signal' => a[2].to_i}
17
17
  }
18
18
  when /linux/
19
19
  lines = `iwlist wlan0 scan`.split(/[\r\n]/)
20
20
  addrs = []
21
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=/
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
24
  end
25
25
  addrs
26
26
  end
@@ -28,15 +28,14 @@ module WiFiLocation
28
28
 
29
29
  def self.location(wifi_towers=self.wifi_towers)
30
30
  uri = URI.parse 'http://www.google.com/loc/json'
31
- wifi_towers = self.wifi_towers unless wifi_towers
32
31
  query = {
33
32
  :version => '1.1.0',
34
33
  :host => 'maps.google.com',
35
34
  :request_address => true,
36
35
  :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} }
36
+ :wifi_towers => wifi_towers.map{|tower| {:mac_address => tower['bssid'], :signal_strength => tower['signal'], :age => 0} }
38
37
  }.to_json
39
- headers = {'Content-Type' => 'application/x-www-form-urlencoded'}
38
+ headers = {'Content-Type' => 'application/json'}
40
39
  res = Net::HTTP.start(uri.host, uri.port).request(Net::HTTP::Post.new(uri.request_uri, headers), query)
41
40
  raise "Response Error (#{res.code})" unless res.code.to_i == 200
42
41
  JSON.parse(res.body)['location']
metadata CHANGED
@@ -1,80 +1,117 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: wifi_location
3
- version: !ruby/object:Gem::Version
4
- version: 0.0.1
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
5
  prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 2
10
+ version: 0.0.2
6
11
  platform: ruby
7
- authors:
12
+ authors:
8
13
  - Sho Hashimoto
9
14
  autorequire:
10
15
  bindir: bin
11
16
  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
+
18
+ date: 2012-08-03 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ prerelease: false
22
+ requirement: &id001 !ruby/object:Gem::Requirement
17
23
  none: false
18
- requirements:
19
- - - ~>
20
- - !ruby/object:Gem::Version
21
- version: '3.10'
22
- type: :development
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ hash: 5
28
+ segments:
29
+ - 1
30
+ - 5
31
+ - 3
32
+ version: 1.5.3
33
+ type: :runtime
34
+ name: json
35
+ version_requirements: *id001
36
+ - !ruby/object:Gem::Dependency
23
37
  prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
38
+ requirement: &id002 !ruby/object:Gem::Requirement
25
39
  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
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 27
44
+ segments:
45
+ - 0
46
+ - 0
47
+ - 2
48
+ version: 0.0.2
49
+ type: :runtime
50
+ name: args_parser
51
+ version_requirements: *id002
52
+ - !ruby/object:Gem::Dependency
53
+ prerelease: false
54
+ requirement: &id003 !ruby/object:Gem::Requirement
33
55
  none: false
34
- requirements:
35
- - - ! '>='
36
- - !ruby/object:Gem::Version
37
- version: 1.5.3
56
+ requirements:
57
+ - - ~>
58
+ - !ruby/object:Gem::Version
59
+ hash: 19
60
+ segments:
61
+ - 3
62
+ - 10
63
+ version: "3.10"
38
64
  type: :development
65
+ name: rdoc
66
+ version_requirements: *id003
67
+ - !ruby/object:Gem::Dependency
39
68
  prerelease: false
40
- version_requirements: !ruby/object:Gem::Requirement
69
+ requirement: &id004 !ruby/object:Gem::Requirement
41
70
  none: false
42
- requirements:
43
- - - ! '>='
44
- - !ruby/object:Gem::Version
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ hash: 5
75
+ segments:
76
+ - 1
77
+ - 5
78
+ - 3
45
79
  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
80
  type: :development
81
+ name: newgem
82
+ version_requirements: *id004
83
+ - !ruby/object:Gem::Dependency
55
84
  prerelease: false
56
- version_requirements: !ruby/object:Gem::Requirement
85
+ requirement: &id005 !ruby/object:Gem::Requirement
57
86
  none: false
58
- requirements:
87
+ requirements:
59
88
  - - ~>
60
- - !ruby/object:Gem::Version
61
- version: '3.0'
89
+ - !ruby/object:Gem::Version
90
+ hash: 7
91
+ segments:
92
+ - 3
93
+ - 0
94
+ version: "3.0"
95
+ type: :development
96
+ name: hoe
97
+ version_requirements: *id005
62
98
  description: Get your location with WiFi Mac Address and GoogleMap.
63
- email:
99
+ email:
64
100
  - hashimoto@shokai.org
65
- executables:
66
- - wifi_location
101
+ executables:
102
+ - whereami
67
103
  extensions: []
68
- extra_rdoc_files:
104
+
105
+ extra_rdoc_files:
69
106
  - History.txt
70
107
  - Manifest.txt
71
108
  - README.rdoc
72
- files:
109
+ files:
73
110
  - History.txt
74
111
  - Manifest.txt
75
112
  - README.rdoc
76
113
  - Rakefile
77
- - bin/wifi_location
114
+ - bin/whereami
78
115
  - lib/wifi_location.rb
79
116
  - samples/sample.rb
80
117
  - script/console
@@ -85,30 +122,38 @@ files:
85
122
  - .gemtest
86
123
  homepage: http://github.com/shokai/wifi_location
87
124
  licenses: []
88
- post_install_message:
89
- rdoc_options:
125
+
126
+ post_install_message: "!! You can get your location with \"whereami\" command. For more information on wifi_location, see https://rubygems.org/gems/wifi_location"
127
+ rdoc_options:
90
128
  - --main
91
129
  - README.rdoc
92
- require_paths:
130
+ require_paths:
93
131
  - lib
94
- required_ruby_version: !ruby/object:Gem::Requirement
132
+ required_ruby_version: !ruby/object:Gem::Requirement
95
133
  none: false
96
- requirements:
97
- - - ! '>='
98
- - !ruby/object:Gem::Version
99
- version: '0'
100
- required_rubygems_version: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ hash: 3
138
+ segments:
139
+ - 0
140
+ version: "0"
141
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
142
  none: false
102
- requirements:
103
- - - ! '>='
104
- - !ruby/object:Gem::Version
105
- version: '0'
143
+ requirements:
144
+ - - ">="
145
+ - !ruby/object:Gem::Version
146
+ hash: 3
147
+ segments:
148
+ - 0
149
+ version: "0"
106
150
  requirements: []
151
+
107
152
  rubyforge_project: wifi_location
108
153
  rubygems_version: 1.8.24
109
154
  signing_key:
110
155
  specification_version: 3
111
156
  summary: Get your location with WiFi Mac Address and GoogleMap.
112
- test_files:
157
+ test_files:
113
158
  - test/test_helper.rb
114
159
  - test/test_wifi_location.rb
@@ -1,10 +0,0 @@
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"