Class: OSXwarranty::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/osxwarranty/base.rb

Instance Method Summary collapse

Instance Method Details

#asdcheck(model) ⇒ Object



40
41
42
43
44
45
46
47
# File 'lib/osxwarranty/base.rb', line 40

def asdcheck(model)
    asd_hash = Hash.new
	HTTPClient.get("https://raw.github.com/tevren/warranty/master/asdcheck").body.each_line do |line|
		asd_array = line.split(":")
		asd_hash[asd_array[0]] = asd_array[1].gsub("\n","")
    end
    return asd_hash[model]
end

#get_model_info(serial) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/osxwarranty/base.rb', line 26

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



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/osxwarranty/base.rb', line 14

def get_warranty_info(serial)
	uri = "https://selfsolve.apple.com/wcResults.do"
	options = {:sn=>serial, :continue=>"Continue", :cn=>"", :locale=>"", :caller=>"", :num=>"0"}
	response = HTTPClient.post(uri,options)
	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



6
7
8
9
10
11
12
13
# File 'lib/osxwarranty/base.rb', line 6

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