findi 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Contributing.markdown +7 -0
- data/Gemfile +5 -0
- data/LICENSE +22 -0
- data/Rakefile +1 -0
- data/Readme.markdown +30 -0
- data/findi.gemspec +23 -0
- data/lib/findi.rb +6 -0
- data/lib/findi/client.rb +100 -0
- data/lib/findi/device.rb +33 -0
- data/lib/findi/version.rb +3 -0
- metadata +76 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Sam Soffes
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
data/Readme.markdown
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# Findi
|
2
|
+
|
3
|
+
Find your iPhone through Apple's Find my iPhone API's.
|
4
|
+
|
5
|
+
A Ruby port of [findi](https://github.com/pearkes/findi) by [pearkes](https://github.com/pearkes).
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'findi'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install findi
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
``` ruby
|
24
|
+
> client = Findi::Client.new('steve@mac.com', 'password')
|
25
|
+
> client.devices
|
26
|
+
```
|
27
|
+
|
28
|
+
## Contributing
|
29
|
+
|
30
|
+
See the [contributing guide](Contributing.markdown).
|
data/findi.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'findi/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = 'findi'
|
8
|
+
gem.version = Findi::VERSION
|
9
|
+
gem.authors = ['Sam Soffes']
|
10
|
+
gem.email = ['sam@soff.es']
|
11
|
+
gem.description = "Find your iPhone through Apple's Find my iPhone API's."
|
12
|
+
gem.summary = gem.description
|
13
|
+
gem.homepage = 'https://github.com/soffes/findi'
|
14
|
+
gem.license = 'MIT'
|
15
|
+
|
16
|
+
gem.files = `git ls-files`.split($/)
|
17
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
18
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
19
|
+
gem.require_paths = ['lib']
|
20
|
+
|
21
|
+
gem.required_ruby_version = '>= 1.9.2'
|
22
|
+
gem.add_dependency 'multi_json'
|
23
|
+
end
|
data/lib/findi.rb
ADDED
data/lib/findi/client.rb
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
require 'net/https'
|
2
|
+
require 'uri'
|
3
|
+
require 'base64'
|
4
|
+
require 'multi_json'
|
5
|
+
|
6
|
+
module Findi
|
7
|
+
class Client
|
8
|
+
attr_reader :username
|
9
|
+
attr_reader :devices
|
10
|
+
|
11
|
+
def initialize(username, password)
|
12
|
+
@username = username
|
13
|
+
@password = password
|
14
|
+
@devices = []
|
15
|
+
|
16
|
+
get_partition
|
17
|
+
update_devices
|
18
|
+
end
|
19
|
+
|
20
|
+
def update_devices
|
21
|
+
body = {
|
22
|
+
clientContext: {
|
23
|
+
appName: 'FindMyiPhone',
|
24
|
+
appVersion: '1.4',
|
25
|
+
buildVersion: '145',
|
26
|
+
deviceUDID: '0000000000000000000000000000000000000000',
|
27
|
+
inactiveTime: 2147483647,
|
28
|
+
osVersion: '4.2.1',
|
29
|
+
personID: 0,
|
30
|
+
productType: 'iPad1,1'
|
31
|
+
}
|
32
|
+
}
|
33
|
+
response = post("fmipservice/device/#{@username}/initClient", body)
|
34
|
+
|
35
|
+
json = MultiJson.load(response.body)
|
36
|
+
# TODO: Catch parse error
|
37
|
+
raise "Web service error: #{json['error']}" if json['error']
|
38
|
+
|
39
|
+
@devices = []
|
40
|
+
json['content'].each do |device|
|
41
|
+
@devices << Device.new(device)
|
42
|
+
end
|
43
|
+
|
44
|
+
@devices
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def post(path, params = nil)
|
50
|
+
# Build URL
|
51
|
+
url = @partition ? "https://#{@partition}/#{path}" : "https://fmipmobile.icloud.com/#{path}"
|
52
|
+
|
53
|
+
# Setup connection
|
54
|
+
uri = URI.parse(url)
|
55
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
56
|
+
http.use_ssl = true
|
57
|
+
|
58
|
+
# Build request
|
59
|
+
request = Net::HTTP::Post.new(uri.request_uri)
|
60
|
+
|
61
|
+
# Add headers
|
62
|
+
request['Content-type'] = 'application/json; charset=utf-8'
|
63
|
+
request['X-Apple-Find-Api-Ver'] = '2.0'
|
64
|
+
request['X-Apple-Authscheme'] = 'UserIdGuest'
|
65
|
+
request['X-Apple-Realm-Support'] = '1.0'
|
66
|
+
request['User-agent'] = 'Find iPhone/1.2 MeKit (iPad: iPhone OS/4.2.1)'
|
67
|
+
request['X-Client-Name'] = 'iPad'
|
68
|
+
request['X-Client-UUID'] = '0cf3dc501ff812adb0b202baed4f37274b210853'
|
69
|
+
request['Accept-Language'] = 'en-us'
|
70
|
+
request['Connection'] = 'keep-alive'
|
71
|
+
|
72
|
+
# Auth
|
73
|
+
auth = Base64.urlsafe_encode64("#{@username}:#{@password}").chomp
|
74
|
+
request['Authorization'] = "Basic #{auth}"
|
75
|
+
|
76
|
+
# Add params as JSON if they exist
|
77
|
+
request.body = MultiJson.dump(params) if params
|
78
|
+
|
79
|
+
# Request
|
80
|
+
http.request(request)
|
81
|
+
end
|
82
|
+
|
83
|
+
def get_partition
|
84
|
+
body = {
|
85
|
+
clientContext: {
|
86
|
+
appName: 'FindMyiPhone',
|
87
|
+
appVersion: '1.4',
|
88
|
+
buildVersion: '145',
|
89
|
+
deviceUDID: '0000000000000000000000000000000000000000',
|
90
|
+
inactiveTime: 2147483647,
|
91
|
+
osVersion: '4.2.1',
|
92
|
+
personID: 0,
|
93
|
+
productType: 'iPad1,1'
|
94
|
+
}
|
95
|
+
}
|
96
|
+
response = post("fmipservice/device/#{@username}/initClient", body)
|
97
|
+
@partition = response['X-Apple-MMe-Host']
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
data/lib/findi/device.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
module Findi
|
2
|
+
class Device
|
3
|
+
attr_reader :model, :status, :id, :name, :kind, :battery_status, :battery_level, :location_type, :horizontal_accuracy, :longitude, :latitude, :location_timestamp
|
4
|
+
|
5
|
+
def initialize(json)
|
6
|
+
if location = json['location'] and location.is_a?(Hash)
|
7
|
+
@location_timestamp = Time.at(location['timeStamp'] / 1000)
|
8
|
+
@location_type = location['positionType']
|
9
|
+
@horizontal_accuracy = location['horizontalAccuracy']
|
10
|
+
@location_finished = location['locationFinished']
|
11
|
+
@longitude = location['longitude']
|
12
|
+
@latitude = location['latitude']
|
13
|
+
end
|
14
|
+
|
15
|
+
@is_locating = json['isLocating']
|
16
|
+
@model = json['deviceModel']
|
17
|
+
@status = json['deviceStatus']
|
18
|
+
@id = json['id']
|
19
|
+
@name = json['name']
|
20
|
+
@kind = json['deviceClass']
|
21
|
+
@battery_status = json['batteryStatus']
|
22
|
+
@battery_level = json['batteryLevel']
|
23
|
+
end
|
24
|
+
|
25
|
+
def is_locating?
|
26
|
+
@is_locating
|
27
|
+
end
|
28
|
+
|
29
|
+
def location_finished?
|
30
|
+
@location_finished
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
metadata
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: findi
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Sam Soffes
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-02-02 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: multi_json
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
description: Find your iPhone through Apple's Find my iPhone API's.
|
31
|
+
email:
|
32
|
+
- sam@soff.es
|
33
|
+
executables: []
|
34
|
+
extensions: []
|
35
|
+
extra_rdoc_files: []
|
36
|
+
files:
|
37
|
+
- .gitignore
|
38
|
+
- Contributing.markdown
|
39
|
+
- Gemfile
|
40
|
+
- LICENSE
|
41
|
+
- Rakefile
|
42
|
+
- Readme.markdown
|
43
|
+
- findi.gemspec
|
44
|
+
- lib/findi.rb
|
45
|
+
- lib/findi/client.rb
|
46
|
+
- lib/findi/device.rb
|
47
|
+
- lib/findi/version.rb
|
48
|
+
homepage: https://github.com/soffes/findi
|
49
|
+
licenses:
|
50
|
+
- MIT
|
51
|
+
post_install_message:
|
52
|
+
rdoc_options: []
|
53
|
+
require_paths:
|
54
|
+
- lib
|
55
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
56
|
+
none: false
|
57
|
+
requirements:
|
58
|
+
- - ! '>='
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 1.9.2
|
61
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ! '>='
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
segments:
|
68
|
+
- 0
|
69
|
+
hash: 704362302268065703
|
70
|
+
requirements: []
|
71
|
+
rubyforge_project:
|
72
|
+
rubygems_version: 1.8.23
|
73
|
+
signing_key:
|
74
|
+
specification_version: 3
|
75
|
+
summary: Find your iPhone through Apple's Find my iPhone API's.
|
76
|
+
test_files: []
|