Skip to content

Instantly share code, notes, and snippets.

@rockpapergoat
Created April 18, 2012 17:02
Show Gist options
  • Save rockpapergoat/2415042 to your computer and use it in GitHub Desktop.
Save rockpapergoat/2415042 to your computer and use it in GitHub Desktop.
purchase date extension attribute
#!/usr/bin/env ruby
require 'open-uri'
def get_warranty_end(serial)
open('https://selfsolve.apple.com/warrantyChecker.do?sn=' + serial.upcase + '&country=USA', :proxy => "http://proxy.company.com:8080") {|item|
item.each_line {|item|}
warranty_array = item.strip.split('"')
purchase = warranty_array.index('PURCHASE_DATE')+2
File.open("/etc/purchase_date", "w") {|f| f.puts warranty_array[purchase]}
puts "<result>#{warranty_array[purchase]}</result>"
}
end
@serial = %x(system_profiler SPHardwareDataType | awk '/Serial/ {print $4}').upcase.chomp
def check_cached(file)
if File.exists?(file)
f = File.open(file, "r")
purchase_date = f.read.chomp
puts "<result>#{purchase_date}</result>"
else
get_warranty_end(@serial)
end
end
check_cached("/etc/purchase_date")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment