Created
April 18, 2012 17:02
-
-
Save rockpapergoat/2415042 to your computer and use it in GitHub Desktop.
purchase date extension attribute
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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