findmyiphone 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,9 @@
1
+ *.gem
2
+ examples/fireeagle_keys.yml
3
+ examples/iphone_credentials.yml
4
+ .*.swp
5
+ *.sw?
6
+ .DS_Store
7
+ coverage
8
+ rdoc
9
+ pkg
data/LICENSE ADDED
@@ -0,0 +1,10 @@
1
+ Copyright (c) 2009, Matt Biddulph, Hackdiary Ltd
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
5
+
6
+ * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
7
+ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
8
+ * Neither the name of Hackdiary Ltd nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
9
+
10
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README ADDED
@@ -0,0 +1,4 @@
1
+ Ported from http://github.com/spullara/findmyiphone/tree/master and http://github.com/tylerhall/sosumi/tree/master
2
+ They worked it all out.
3
+
4
+ In the examples directory is a Fire Eagle updater. Rename the *.yml.example files to *.yml and fill in your MobileMe account details and a valid set of Fire Eagle OAuth tokens, and it'll update your location using the MobileMe data.
@@ -0,0 +1,59 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "findmyiphone"
8
+ gem.summary = "MobileMe utilities"
9
+ gem.description = "A toolkit for sending messages and getting location from MobileMe."
10
+ gem.email = "matt@hackdiary.com"
11
+ gem.homepage = "http://github.com/mattb/findmyiphone"
12
+ gem.authors = ["Matt Biddulph"]
13
+ gem.add_dependency("mechanize", [">= 0.9.3"])
14
+ gem.add_dependency("json", [">= 1.1.3"])
15
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
+ end
17
+
18
+ rescue LoadError
19
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
20
+ end
21
+
22
+ require 'rake/testtask'
23
+ Rake::TestTask.new(:test) do |test|
24
+ test.libs << 'lib' << 'test'
25
+ test.pattern = 'test/**/*_test.rb'
26
+ test.verbose = true
27
+ end
28
+
29
+ begin
30
+ require 'rcov/rcovtask'
31
+ Rcov::RcovTask.new do |test|
32
+ test.libs << 'test'
33
+ test.pattern = 'test/**/*_test.rb'
34
+ test.verbose = true
35
+ end
36
+ rescue LoadError
37
+ task :rcov do
38
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
39
+ end
40
+ end
41
+
42
+
43
+ task :default => :test
44
+
45
+ require 'rake/rdoctask'
46
+ Rake::RDocTask.new do |rdoc|
47
+ if File.exist?('VERSION.yml')
48
+ config = YAML.load(File.read('VERSION.yml'))
49
+ version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
50
+ else
51
+ version = ""
52
+ end
53
+
54
+ rdoc.rdoc_dir = 'rdoc'
55
+ rdoc.title = "findmyiphone #{version}"
56
+ rdoc.rdoc_files.include('README*')
57
+ rdoc.rdoc_files.include('lib/**/*.rb')
58
+ end
59
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.2.0
@@ -0,0 +1,5 @@
1
+ ---
2
+ :consumer_key:
3
+ :consumer_secret:
4
+ :access_token:
5
+ :access_token_secret:
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/ruby
2
+ require 'rubygems'
3
+ require 'findmyiphone'
4
+ require 'oauth'
5
+ require 'fireeagle'
6
+ require 'pp'
7
+
8
+ c = FireEagle::Client.new(YAML.load_file("fireeagle_keys.yml"))
9
+ i = YAML.load_file("iphone_credentials.yml")
10
+ f = FindMyIphone.new(i[:username], i[:password])
11
+ puts "Looking for your iphone..."
12
+ f.devices
13
+ puts "Requesting location from MobileMe..."
14
+ loc = f.locateMe
15
+ puts "Updating Fire Eagle..."
16
+ result = c.update(:lat => loc['latitude'], :lon => loc['longitude'])
17
+ puts "Fire Eagle said #{result.status}."
@@ -0,0 +1,3 @@
1
+ ---
2
+ :username:
3
+ :password:
@@ -0,0 +1,53 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{findmyiphone}
5
+ s.version = "0.2.0"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Matt Biddulph"]
9
+ s.date = %q{2009-07-23}
10
+ s.description = %q{A toolkit for sending messages and getting location from MobileMe.}
11
+ s.email = %q{matt@hackdiary.com}
12
+ s.extra_rdoc_files = [
13
+ "LICENSE",
14
+ "README"
15
+ ]
16
+ s.files = [
17
+ ".gitignore",
18
+ "LICENSE",
19
+ "README",
20
+ "Rakefile",
21
+ "VERSION",
22
+ "examples/fireeagle_keys.yml.example",
23
+ "examples/iphone_2_fireeagle.rb",
24
+ "examples/iphone_credentials.yml.example",
25
+ "findmyiphone.gemspec",
26
+ "lib/findmyiphone.rb"
27
+ ]
28
+ s.has_rdoc = true
29
+ s.homepage = %q{http://github.com/mattb/findmyiphone}
30
+ s.rdoc_options = ["--charset=UTF-8"]
31
+ s.require_paths = ["lib"]
32
+ s.rubygems_version = %q{1.3.1}
33
+ s.summary = %q{MobileMe utilities}
34
+ s.test_files = [
35
+ "examples/iphone_2_fireeagle.rb"
36
+ ]
37
+
38
+ if s.respond_to? :specification_version then
39
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
40
+ s.specification_version = 2
41
+
42
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
43
+ s.add_runtime_dependency(%q<mechanize>, [">= 0.9.3"])
44
+ s.add_runtime_dependency(%q<json>, [">= 1.1.3"])
45
+ else
46
+ s.add_dependency(%q<mechanize>, [">= 0.9.3"])
47
+ s.add_dependency(%q<json>, [">= 1.1.3"])
48
+ end
49
+ else
50
+ s.add_dependency(%q<mechanize>, [">= 0.9.3"])
51
+ s.add_dependency(%q<json>, [">= 1.1.3"])
52
+ end
53
+ end
@@ -0,0 +1,73 @@
1
+ require 'rubygems'
2
+ require 'mechanize'
3
+ require 'json'
4
+
5
+ class FindMyIphone
6
+ def initialize(username, password)
7
+ @username = username
8
+ @password = password
9
+ @agent = WWW::Mechanize.new
10
+ @agent.user_agent_alias = 'Mac Safari'
11
+ end
12
+
13
+ def devices
14
+ if !@thedevices
15
+ authurl="https://auth.apple.com/authenticate?service=DockStatus&realm=primary-me&formID=loginForm&username=#{@username}&password=#{@password}&returnURL=aHR0cHM6Ly9zZWN1cmUubWUuY29tL3dvL1dlYk9iamVjdHMvRG9ja1N0YXR1cy53b2Evd2EvdHJhbXBvbGluZT9kZXN0aW5hdGlvblVybD0vYWNjb3VudA%3D%3D"
16
+ page = @agent.get(authurl)
17
+ @isc = @agent.cookie_jar.cookies(URI.parse("https://secure.me.com")).select { |c| c.name == 'isc-secure.me.com' }[0].value
18
+
19
+ devicesurl = "https://secure.me.com/wo/WebObjects/DeviceMgmt.woa/?lang=en"
20
+ @agent.pre_connect_hooks << lambda { |params|
21
+ params[:request]['X-Mobileme-Version'] = '1.0'
22
+ params[:request]['X-Mobileme-Isc'] = @isc
23
+ params[:request]['X-Requested-With'] = 'XMLHttpRequest'
24
+ params[:request]['Accept'] = 'text/javascript, text/html, application/xml, text/xml, */*'
25
+ }
26
+
27
+ page = @agent.post(devicesurl)
28
+ @thedevices = page.content.scan(/tDeviceMgmt.deviceIdMap\['[0-9+]'\] = '([^']+)'/).flatten
29
+ end
30
+ return @thedevices
31
+ end
32
+
33
+ def sendMessage(msg, alarm=false, device=nil)
34
+ device ||= self.devices[0]
35
+
36
+ messageurl = "https://secure.me.com/wo/WebObjects/DeviceMgmt.woa/wa/SendMessageAction/sendMessage"
37
+ data = {"deviceId" => device,
38
+ "deviceOsVersion" => "7A341",
39
+ "message" => msg,
40
+ "playAlarm" => alarm ? 'Y' : 'N',
41
+ }
42
+ self.send(messageurl,data)
43
+ end
44
+
45
+ def locateMe(device = nil)
46
+ device ||= self.devices[0]
47
+ deviceurl = "https://secure.me.com/wo/WebObjects/DeviceMgmt.woa/wa/LocateAction/locateStatus"
48
+ result = {}
49
+ data = {"deviceId" => device, "deviceOsVersion" => "7A341" }
50
+ return self.send(deviceurl,data)
51
+ end
52
+
53
+ def send(url,data)
54
+ uri = URI.parse(url)
55
+ json = JSON.generate(data)
56
+
57
+ http = Net::HTTP.new(uri.host, uri.port)
58
+ http.use_ssl = true
59
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
60
+ req = Net::HTTP::Post.new(uri.path)
61
+ req.body = "postBody=#{json}"
62
+ req['Cookie'] = @agent.cookie_jar.cookies(URI.parse("https://secure.me.com")).map { |c| c.to_s }.join("; ")
63
+ req['X-Mobileme-Version'] = '1.0'
64
+ req['X-Mobileme-Isc'] = @isc
65
+ req['X-Requested-With'] = 'XMLHttpRequest'
66
+ req['Accept'] = 'text/javascript, text/html, application/xml, text/xml, */*'
67
+ req['Content-type'] = 'application/json'
68
+ res = http.start { |web|
69
+ web.request(req)
70
+ }
71
+ return JSON.parse(res.body)
72
+ end
73
+ end
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: findmyiphone
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Matt Biddulph
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-07-23 00:00:00 +01:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: mechanize
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 0.9.3
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: json
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 1.1.3
34
+ version:
35
+ description: A toolkit for sending messages and getting location from MobileMe.
36
+ email: matt@hackdiary.com
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files:
42
+ - LICENSE
43
+ - README
44
+ files:
45
+ - .gitignore
46
+ - LICENSE
47
+ - README
48
+ - Rakefile
49
+ - VERSION
50
+ - examples/fireeagle_keys.yml.example
51
+ - examples/iphone_2_fireeagle.rb
52
+ - examples/iphone_credentials.yml.example
53
+ - findmyiphone.gemspec
54
+ - lib/findmyiphone.rb
55
+ has_rdoc: true
56
+ homepage: http://github.com/mattb/findmyiphone
57
+ licenses: []
58
+
59
+ post_install_message:
60
+ rdoc_options:
61
+ - --charset=UTF-8
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: "0"
69
+ version:
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: "0"
75
+ version:
76
+ requirements: []
77
+
78
+ rubyforge_project:
79
+ rubygems_version: 1.3.5
80
+ signing_key:
81
+ specification_version: 2
82
+ summary: MobileMe utilities
83
+ test_files:
84
+ - examples/iphone_2_fireeagle.rb