Skip to content

Instantly share code, notes, and snippets.

@rockpapergoat
Created February 8, 2011 18:50
Show Gist options
  • Save rockpapergoat/816967 to your computer and use it in GitHub Desktop.
Save rockpapergoat/816967 to your computer and use it in GitHub Desktop.
get mac applecare coverage details
#!/usr/bin/env ruby
# get a machine's applecare warranty expiration
# 100605, nate, initial version
# 100605, updated with collaboration from glarizza
# cf. http://pastie.org/993496
# cf. http://pastie.org/994884, with facter attribute additions
# 101222, require rubygems, facter; used facter to get serial (not as portable)
# 101222, reverted to system_profiler, as it requires fewer dependencies
# 110208, new url worked out by gary
# 110208, openssl workaround, cf. http://snippets.aktagon.com/snippets/370-Hack-for-using-OpenURI-with-SSL
=begin
to do: add option parsing using optparse
to do: accept file of serials or input other than stdin
=end
#require 'rubygems'
#require 'facter'
require 'open-uri'
require 'openssl'
#require 'optparse'
def get_warranty_end(serial)
open('https://selfsolve.apple.com/warrantyChecker.do?sn=' + serial.upcase + '&country=USA') {|item|
item.each_line {|item|}
warranty_array = item.strip.split('"')
coverage = warranty_array.index('COV_END_DATE')
purchase = warranty_array.index('PURCHASE_DATE')
puts "\nMachine serial:\t#{serial}"
puts "Purchase date:\t#{warranty_array[purchase+2]}"
puts "Coverage end:\t#{warranty_array[coverage+2]}\n"
}
end
OpenSSL::SSL::VERIFY_NONE
if ARGV.size > 0 then
serial = ARGV.each do |serial|
get_warranty_end(serial.upcase)
end
else
puts "Without your input, we'll use this machine's serial number."
#facts = Facter.to_hash
#serial = "#{facts["sp_serial_number"]}" if facts.include?("sp_serial_number")
#gets.chomp.upcase
serial = %x(system_profiler SPHardwareDataType | awk '/Serial/ {print $4}').upcase.chomp
get_warranty_end(serial)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment