Class: OSXwarranty::Base
- Inherits:
-
Object
- Object
- OSXwarranty::Base
- Defined in:
- lib/osxwarranty/base.rb
Instance Method Summary collapse
-
#asdcheck(model) ⇒ Object
chilcote’s asdcheck (github.com/chilcote/warranty/blob/master/asdcheck).
- #get_model_info(serial) ⇒ Object
- #get_warranty_info(serial) ⇒ Object
-
#info(serial = nil) ⇒ Object
glarizza’s get_warranty method (github.com/glarizza/scripts/blob/master/ruby/warranty.rb).
Instance Method Details
#asdcheck(model) ⇒ Object
chilcote’s asdcheck (github.com/chilcote/warranty/blob/master/asdcheck)
41 42 43 44 45 |
# File 'lib/osxwarranty/base.rb', line 41 def asdcheck(model) asd_hash = YAML.load_file(File.join(File.dirname(__FILE__),"../config/asdcheck.yml")) search_q = model.gsub(" ", "_").gsub("(","").gsub(")","").gsub("-","_").gsub(",","_").gsub(".","_") return asd_hash[search_q] end |
#get_model_info(serial) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/osxwarranty/base.rb', line 27 def get_model_info(serial) serial_size = serial.size if serial_size == 12 search_q = serial[-4,4] elsif serial_size == 11 search_q = serial[-3,3] end uri = "http://support-sp.apple.com/sp/product?cc=#{search_q}&lang=en_US" response = HTTPClient.get(uri) nokogiri_data = Nokogiri::XML(response.body) model = nokogiri_data.search('configCode').text return model end |
#get_warranty_info(serial) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/osxwarranty/base.rb', line 15 def get_warranty_info(serial) uri = "https://selfsolve.apple.com/wcResults.do" = {:sn=>serial, :continue=>"Continue", :cn=>"", :locale=>"", :caller=>"", :num=>"0"} response = HTTPClient.post(uri,) response_body = response.content repair_covered = response_body.split('warrantyPage.warrantycheck.displayHWSupportInfo').last.split('Repairs and Service Coverage: ')[1] =~ /^Active/ ? true : false expiration_date = response_body.split('Estimated Expiration Date: ')[1].split('<')[0] if repair_covered == true expiration_date = "EXPIRED" if expiration_date.nil? warranty_info = {:repair_covered => repair_covered, :expiration_date => expiration_date} return warranty_info end |
#info(serial = nil) ⇒ Object
glarizza’s get_warranty method (github.com/glarizza/scripts/blob/master/ruby/warranty.rb)
7 8 9 10 11 12 13 14 |
# File 'lib/osxwarranty/base.rb', line 7 def info(serial = nil) @serial = serial warranty_info = get_warranty_info(@serial) model = get_model_info(serial) asdinfo = asdcheck(model) warranty_info = warranty_info.merge({:model => model, :asdinfo => asdinfo}) return warranty_info end |