class Pingo::Client
Constants
- INIT_CLIENT
- PLAY_SOUND
Public Class Methods
new(model_name)
click to toggle source
# File lib/pingo.rb, line 19 def initialize(model_name) @model_name = model_name @username = ENV['APPLE_ID'] @password = ENV['APPLE_PASSWORD'] end
run(model_name)
click to toggle source
# File lib/pingo.rb, line 14 def run(model_name) new(model_name).sound! end
Public Instance Methods
device_ids()
click to toggle source
# File lib/pingo.rb, line 29 def device_ids response = post(INIT_CLIENT) raise "#{response.response_code}:#{response.status_message }" unless response.success? parse_device_ids(response.body) end
sound!()
click to toggle source
# File lib/pingo.rb, line 25 def sound! device_ids.each { |device_id| post(PLAY_SOUND, generate_body(device_id)) } end
Private Instance Methods
contents(body)
click to toggle source
# File lib/pingo.rb, line 46 def contents(body) JSON.parse(body)['content'] end
generate_body(device_id)
click to toggle source
# File lib/pingo.rb, line 54 def generate_body(device_id) JSON.generate(sound_body(device_id)) end
match_device?(params)
click to toggle source
# File lib/pingo.rb, line 50 def match_device?(params) params['deviceDisplayName'] =~ /#{@model_name}$/i end
parse_device_ids(body)
click to toggle source
# File lib/pingo.rb, line 37 def parse_device_ids(body) target_contents(body).map { |content| content["id"] } end
post(type, body=nil)
click to toggle source
# File lib/pingo.rb, line 70 def post(type, body=nil) Typhoeus::Request.post(uri(type), userpwd: "#{@username}:#{@password}", headers: post_headers, followlocation: true, verbose: true, maxredirs: 1, body: body) end
post_headers()
click to toggle source
# File lib/pingo.rb, line 80 def post_headers { 'Content-Type' => 'application/json; charset=utf-8', 'X-Apple-Find-Api-Ver' => '2.0', 'X-Apple-Authscheme' => 'UserIdGuest', 'X-Apple-Realm-Support' => '1.0', 'Accept-Language' => 'en-us', 'userAgent' => 'Pingo', 'Connection' => 'keep-alive' } end
sound_body(device_id)
click to toggle source
# File lib/pingo.rb, line 58 def sound_body(device_id) { clientContext: { appName: 'FindMyiPhone', appVersion: '2.0.2', shouldLocate: false, }, device: device_id, subject: "Pingo" } end
target_contents(body)
click to toggle source
# File lib/pingo.rb, line 41 def target_contents(body) target = contents(body).find_all { |content| match_device?(content) } target.empty? ? raise("Not found your device(iPhone#{@model_name})") : target end
uri(type)
click to toggle source
# File lib/pingo.rb, line 92 def uri(type) "https://fmipmobile.icloud.com/fmipservice/device/#{@username}/#{type}" end