Created
August 14, 2012 03:27
-
-
Save glarizza/3346062 to your computer and use it in GitHub Desktop.
Apple's new Warranty Status changes
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
| # I apologize to The Baby Jesus for the atrocities I'm about to commit | |
| require 'net/http' | |
| require 'net/https' | |
| require 'uri' | |
| # Contact Apple | |
| 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) | |
| #request.add_field('Content-Type', 'application/json') <-- A guy can dream, can't he? | |
| request.set_form_data({ 'sn' => 'C02FT03UDMC9', 'Continue' => 'Continue', 'cn' => '', 'locale' => '', 'caller' => '', 'num' => '0' }) | |
| response = http.request(request) | |
| the_data = response.body | |
| # Check if the warranty is active | |
| warranty_status = the_data.split('warrantyPage.warrantycheck.displayHWSupportInfo').last.split('Repairs and Service Coverage: ')[1] =~ /^Active/ ? true : false | |
| expiration_date = the_data.split('Estimated Expiration Date: ')[1].split('<')[0] if warranty_status | |
| puts "Your warranty is: " + (warranty_status ? "Active and it expires on #{expiration_date}" : 'Expired') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment