Skip to content

Instantly share code, notes, and snippets.

@rickychilcott
Created March 28, 2011 01:58
Show Gist options
  • Save rickychilcott/889875 to your computer and use it in GitHub Desktop.
Save rickychilcott/889875 to your computer and use it in GitHub Desktop.
Contact's Apple's selfserve servers to capture warranty information about your product. Accepts arguments of machine serial numbers.
#!/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.
# Contributed by Gary Larizza
require 'open-uri'
require 'openssl'
# This is a complete hack to disregard SSL Cert validity for the Apple
# Selfserve site. We had SSL errors as we're behind a proxy. I'm
# open suggestions for doing it 'Less-Hacky.' You can delete this
# code if your network does not have SSL issues with open-uri.
# module OpenSSL
# module SSL
# remove_const:VERIFY_PEER
# end
# end
# OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
def get_warranty(serial)
serial = serial.upcase
hash = {}
open('https://selfsolve.apple.com/warrantyChecker.do?sn=' + serial.upcase + '&country=USA') {|item|
item.each_line {|item|}
warranty_array = item.strip.split('"')
warranty_array.each {|array_item|
hash[array_item] = warranty_array[warranty_array.index(array_item) + 2] if array_item =~ /[A-Z][A-Z\d]+/
}
}
{:serial_number => hash['SERIAL_ID'],
:product_description => hash['PROD_DESCR'],
:purchase_date => hash['PURCHASE_DATE'].gsub("-","."),
:coverage_end_date => !hash['COV_END_DATE'].empty? ? hash['COV_END_DATE'].gsub("-",".") : "EXPIRED",
:days_remaining_in_coverage => hash['DAYS_REM_IN_COV']
}
end
serials = []
if ARGV.size == 0 then
puts "Without your input, we'll use this machine's serial number."
serials << %x(system_profiler SPHardwareDataType | awk '/Serial/ {print $4}').upcase.chomp
else
serials << ARGV
end
serials.each do |serial|
warranty = get_warranty(serial)
puts "\nSerial Number:\t\t#{warranty[:serial_number]}\n"
puts "Product Decription:\t#{warranty[:product_description]}\n"
puts "Purchase date:\t\t#{warranty[:purchase_date]}"
puts "Coverage end:\t\t#{warranty[:coverage_end_date]}\n"
puts "Days Remaining in Cov:\t#{warranty[:days_remaining_in_coverage]}\n"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment