ios_devices_manager 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.
- checksums.yaml +15 -0
- data/lib/ios_devices_manager.rb +104 -0
- data/lib/ios_devices_manager/device.rb +18 -0
- metadata +46 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
ZjAzMWFkMzhmN2E5YTQ4ZmYzYjRkZTgwMTlhOTQ2YmU1NGJmOTZmNw==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
NDkzYThhOGRhYmQ0YjY4NDdmYTgyOGQyMDY5YjA1NGUyMGRlNmQ0Mg==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
MTRjNzBkNjdhOGVlZWY4Yzg5NTQzNzFlNDY5MDY5ZjUyNmJmZDlkMzA4MWUz
|
10
|
+
ODc1MTE2MDBjNjAyNThhZjU2ODE4YTEyZjJhNDRhYTZjNzhmZDUwNWE3NWEw
|
11
|
+
MzIyMzcxZWExY2MwOWNlMWRkZGY1NDY4YTA4ZDhlMTZjYzhhNzQ=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
YWRjMzAyOWQ2NDBkM2FmY2IwYmM3NzI0NTZmNGZmNmU5Y2RmNjg0NzBjZjU2
|
14
|
+
NmExYTc4MjAzZmQxYzZjYzgwNmUwNTE4ODc2MmY5ZDQ0MDQ3NTM4ZWY4ZGMz
|
15
|
+
ZTk4MTViYzIyNzk0MjYzYTYyNGU0MzBjNWY4NTNlNjdjYTY5ZTY=
|
@@ -0,0 +1,104 @@
|
|
1
|
+
require 'base64'
|
2
|
+
require 'json'
|
3
|
+
require 'net/http'
|
4
|
+
require 'net/https'
|
5
|
+
require 'typhoeus'
|
6
|
+
require 'uri'
|
7
|
+
require 'ios_devices_manager/device'
|
8
|
+
|
9
|
+
class IOSDevicesManager < OpenStruct
|
10
|
+
|
11
|
+
INIT_CLIENT = 'initClient'
|
12
|
+
REFRESH_CLIENT = 'refreshClient'
|
13
|
+
SEND_MESSAGE = 'sendMessage'
|
14
|
+
PLAY_SOUND = 'playSound'
|
15
|
+
|
16
|
+
def initialize username, password
|
17
|
+
super({username: username, devices: []})
|
18
|
+
@username = username
|
19
|
+
@password = password
|
20
|
+
@partition = nil
|
21
|
+
@baseURI = "/fmipservice/device/#{@username}/"
|
22
|
+
|
23
|
+
get_partition
|
24
|
+
get_devices
|
25
|
+
end
|
26
|
+
|
27
|
+
def send(device, title = '', msg = '', sound = false)
|
28
|
+
options = {
|
29
|
+
'device' => device.id,
|
30
|
+
'subject' => title,
|
31
|
+
'text' => msg,
|
32
|
+
'sound' => sound,
|
33
|
+
'userText' => true
|
34
|
+
}
|
35
|
+
post(SEND_MESSAGE, options)
|
36
|
+
end
|
37
|
+
|
38
|
+
def play_sound(device, subject = '')
|
39
|
+
options = {
|
40
|
+
'device' => device.id,
|
41
|
+
'subject' => subject
|
42
|
+
}
|
43
|
+
post(PLAY_SOUND, options)
|
44
|
+
end
|
45
|
+
|
46
|
+
def get_devices
|
47
|
+
response = post(INIT_CLIENT)
|
48
|
+
self.devices = parse_devices(response)
|
49
|
+
end
|
50
|
+
|
51
|
+
def update_devices
|
52
|
+
response = post(REFRESH_CLIENT)
|
53
|
+
self.devices = parse_devices(response)
|
54
|
+
end
|
55
|
+
|
56
|
+
def parse_devices(data)
|
57
|
+
JSON.parse(data.body)['content'].collect { |device| Device.new(device) }
|
58
|
+
end
|
59
|
+
|
60
|
+
private
|
61
|
+
|
62
|
+
def get_partition
|
63
|
+
response = post(@initClient)
|
64
|
+
@partition = response.headers['X-Apple-MMe-Host']
|
65
|
+
end
|
66
|
+
|
67
|
+
def post_headers
|
68
|
+
{
|
69
|
+
'Content-Type' => 'application/json; charset=utf-8',
|
70
|
+
'X-Apple-Find-Api-Ver' => '2.0',
|
71
|
+
'X-Apple-Authscheme' => 'UserIdGuest',
|
72
|
+
'X-Apple-Realm-Support' => '1.0',
|
73
|
+
'Accept-Language' => 'en-us',
|
74
|
+
'userAgent' => 'iOS Devices Manager',
|
75
|
+
'Connection' => 'keep-alive'
|
76
|
+
}
|
77
|
+
end
|
78
|
+
|
79
|
+
def post url, options = nil
|
80
|
+
uri = @partition ? "https://#{@partition}#{@baseURI}#{url}" : "https://fmipmobile.icloud.com#{@baseURI}#{url}"
|
81
|
+
|
82
|
+
unless options.nil?
|
83
|
+
clientContext = {
|
84
|
+
'clientContext' => {
|
85
|
+
'appName' => 'FindMyiPhone',
|
86
|
+
'appVersion' => '2.0.2',
|
87
|
+
'shouldLocate' => false
|
88
|
+
}
|
89
|
+
}
|
90
|
+
body = JSON.generate(clientContext.merge(options))
|
91
|
+
post_with(uri, body)
|
92
|
+
else
|
93
|
+
post_with(uri)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def post_with(uri, body = nil)
|
98
|
+
if body
|
99
|
+
Typhoeus::Request.post(uri, userpwd: "#{@username}:#{@password}", headers: post_headers, followlocation: true, verbose: true, maxredirs: 10, body: body)
|
100
|
+
else
|
101
|
+
Typhoeus::Request.post(uri, userpwd: "#{@username}:#{@password}", headers: post_headers, followlocation: true, verbose: true, maxredirs: 10)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'ostruct'
|
2
|
+
|
3
|
+
class Device < OpenStruct
|
4
|
+
|
5
|
+
def initialize(params)
|
6
|
+
location = params['location']
|
7
|
+
super({
|
8
|
+
id: params['id'],
|
9
|
+
name: params['name'],
|
10
|
+
class: params['deviceClass'],
|
11
|
+
display_name: params['deviceDisplayName'],
|
12
|
+
model: params['deviceModel'],
|
13
|
+
latitude: location ? location['latitude'] : nil,
|
14
|
+
longitude: location ? location['longitude'] : nil,
|
15
|
+
time: location ? location['timeStamp'] : nil
|
16
|
+
})
|
17
|
+
end
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ios_devices_manager
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Stephane Thomas
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2010-07-19 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: A simple gem to get location data of a given device, send notifications
|
14
|
+
to it
|
15
|
+
email: thomas.stephn@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- lib/ios_devices_manager.rb
|
21
|
+
- lib/ios_devices_manager/device.rb
|
22
|
+
homepage: http://rubygems.org/gems/ios_devices_manager
|
23
|
+
licenses:
|
24
|
+
- MIT
|
25
|
+
metadata: {}
|
26
|
+
post_install_message:
|
27
|
+
rdoc_options: []
|
28
|
+
require_paths:
|
29
|
+
- lib
|
30
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ! '>='
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ! '>='
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
requirements: []
|
41
|
+
rubyforge_project:
|
42
|
+
rubygems_version: 2.2.2
|
43
|
+
signing_key:
|
44
|
+
specification_version: 4
|
45
|
+
summary: Localize your iDevice from your ruby app
|
46
|
+
test_files: []
|