This repository was archived by the owner on Nov 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathtest.rb
54 lines (42 loc) · 1.37 KB
/
test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env ruby
require 'optparse'
require 'pp'
require "./rosumi.rb"
$options = { }
$options[:device] = 0
$options[:verbose] = false
@parser = OptionParser.new do |opts|
opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
$options[:verbose] = true
end
opts.on('-u', "--username USERNAME", "iCloud Username") do |v|
$options[:username] = v
end
opts.on('-p', "--password PASSWORD", "iCloud Password") do |v|
$options[:password] = v
end
opts.on('-d', "--device DEVICE_NR", "Device number") do |v|
$options[:device] = v.to_i
end
end
begin
@options = @parser.parse!(ARGV)
mandatory = [:username, :password]
missing = mandatory.select { |param| $options[param].nil? }
if not missing.empty?
descr = missing.map { |o| "--#{o}" }
puts "Missing options: #{descr.join(', ')}"
puts @parser
exit 1
end
rescue OptionParser::InvalidOption, OptionParser::MissingArgument
puts $!.to_s
puts @parser
exit
end
r = Rosumi.new($options[:username], $options[:password], $options[:verbose])
#=> #<Rosumi:0x0000010083b048 @user="username", @pass="password", @devices=[], @http=#<Net::HTTP fmipmobile.me.com:443 open=false>
puts r.locate($options[:device])
#=> {:name=>"Steve’s iPhone", :latitude=>23.5423458632445456, :longitude=>23.923433562234181818, :accuracy=>80.0, :timestamp=>1279839672446, :position_type=>"Wifi"}
#####
# EOF