-
Notifications
You must be signed in to change notification settings - Fork 4
/
warranty.rb
executable file
·64 lines (56 loc) · 1.91 KB
/
warranty.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
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env ruby
#
# File: Warranty.rb
#
# Decription: Contact's Apple's selfserve servers to capture warranty
# information about your product. Accepts arguments of
# machine serial numbers.
#
# Author: Gary Larizza
# Last Modified: 8/13/2012
# Why: Apple hates APIs
require 'uri'
require 'net/http'
require 'net/https'
require 'date'
def get_warranty(serial)
# Setup HTTP connection
uri = URI.parse('https://selfsolve.apple.com/wcResults.do')
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
request = Net::HTTP::Post.new(uri.request_uri)
# Prepare POST data
request.set_form_data(
{
'sn' => serial,
'Continue' => 'Continue',
'cn' => '',
'locale' => '',
'caller' => '',
'num' => '0'
}
)
# POST data and get the response
response = http.request(request)
response_data = response.body
# I apologize for this line
warranty_status = response_data.split('warrantyPage.warrantycheck.displayHWSupportInfo').last.split('Repairs and Service Coverage: ')[1] =~ /^Active/ ? true : false
# And this one too
expiration_date = response_data.split('Estimated Expiration Date: ')[1].split('<')[0] if warranty_status
puts "\nSerial Number:\t\t#{serial}"
puts "Warranty Status:\t" + (warranty_status ? "Active and it expires on #{expiration_date}" : 'Expired')
#TODO:
# Grab product description and calculate Purchase Data
# Catch invalid Serial Numbers
# Make this more than just a proof of concept...
end
if ARGV.size > 0 then
serial = ARGV.each do |serial|
get_warranty(serial.upcase)
end
else
puts "Without your input, we'll use this machine's serial number."
serial = %x(system_profiler SPHardwareDataType | awk '/Serial/ {print $4}').upcase.chomp
get_warranty(serial)
end