Class: AppleWarrantyCheck::Process
- Inherits:
-
Object
- Object
- AppleWarrantyCheck::Process
- Defined in:
- lib/apple_warranty_check/process.rb
Constant Summary collapse
- CHECK_URL =
'https://selfsolve.apple.com/wcResults.do'.freeze
- STR_ARG =
"'(.*)'".freeze
- BOOL_ARG =
"(true|false)".freeze
- PRODUCT_INFO_REGEXP =
/warrantyPage.warrantycheck.displayProductInfo\((.*)\)/.freeze
- PH_SUPPORT_INFO_REGEXP =
/warrantyPage.warrantycheck.displayPHSupportInfo\(\s*#{BOOL_ARG},\s*#{STR_ARG},\s*#{STR_ARG},\s*#{STR_ARG}/.freeze
- HW_SUPPORT_INFO_REGEXP =
/warrantyPage.warrantycheck.displayHWSupportInfo\(\s*#{BOOL_ARG},\s*#{STR_ARG},\s*#{STR_ARG},\s*#{STR_ARG},\s*#{STR_ARG}/.freeze
- PH_SUPPORT_STATUS =
/Telephone Technical Support: (Active|Expired)/.freeze
- HW_SUPPORT_STATUS =
/Repairs and Service Coverage: (Active|Expired)/.freeze
- EXP_DATE =
/Estimated Expiration Date: (.*\s\d{2},\s\d{4})/.freeze
- ERR_RESP_REGEXP =
/var errorMsg = '(.*)';/.freeze
- NOT_REGISTERED_REGEXP =
/window.location.href =(.*);/.freeze
- PRODUCT_INFO_KEYS =
%i(prodImgUrl prodDesc isIMEINum APIMEINum isProdId prodId sn).freeze
- PH_SUPPORT_INFO_KEYS =
%i(hasPhoneSuppCov phoneSuppSubHeader phoneSuppCovTxt phoneSuppLink).freeze
- HW_SUPPORT_INFO_KEYS =
%i(hasHWSuppCov HWRepairSubHead HWSuppCovTxt HWSuppLnk hasCLMessageCode).freeze
Instance Attribute Summary collapse
-
#imei ⇒ Object
Returns the value of attribute imei.
-
#response ⇒ Object
Returns the value of attribute response.
Instance Method Summary collapse
- #get_hw_support_info(html) ⇒ Object
- #get_phone_support_info(html) ⇒ Object
- #get_product_info(html) ⇒ Object
-
#initialize(imei = nil) ⇒ Process
constructor
A new instance of Process.
- #parse_body(html) ⇒ Object
- #run ⇒ Object
Constructor Details
#initialize(imei = nil) ⇒ Process
Returns a new instance of Process.
28 29 30 |
# File 'lib/apple_warranty_check/process.rb', line 28 def initialize(imei=nil) @imei = imei end |
Instance Attribute Details
#imei ⇒ Object
Returns the value of attribute imei.
26 27 28 |
# File 'lib/apple_warranty_check/process.rb', line 26 def imei @imei end |
#response ⇒ Object
Returns the value of attribute response.
26 27 28 |
# File 'lib/apple_warranty_check/process.rb', line 26 def response @response end |
Instance Method Details
#get_hw_support_info(html) ⇒ Object
59 60 61 |
# File 'lib/apple_warranty_check/process.rb', line 59 def get_hw_support_info(html) get_support_info HW_SUPPORT_INFO_REGEXP, HW_SUPPORT_INFO_KEYS, HW_SUPPORT_STATUS, html end |
#get_phone_support_info(html) ⇒ Object
55 56 57 |
# File 'lib/apple_warranty_check/process.rb', line 55 def get_phone_support_info(html) get_support_info PH_SUPPORT_INFO_REGEXP, PH_SUPPORT_INFO_KEYS, PH_SUPPORT_STATUS, html end |
#get_product_info(html) ⇒ Object
63 64 65 66 67 68 69 70 |
# File 'lib/apple_warranty_check/process.rb', line 63 def get_product_info(html) process_with_exception 'could not find product info' do [ PRODUCT_INFO_KEYS, PRODUCT_INFO_REGEXP.match(html)[1].split(',').map{ |el| el.strip.gsub('\'', '') } ].transpose.to_h end end |
#parse_body(html) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/apple_warranty_check/process.rb', line 43 def parse_body(html) return error_response(html) unless ERR_RESP_REGEXP.match(html).nil? return not_registered unless NOT_REGISTERED_REGEXP.match(html).nil? { product_info: get_product_info(html), phone_support: get_phone_support_info(html), hw_support: get_hw_support_info(html) } end |
#run ⇒ Object
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/apple_warranty_check/process.rb', line 32 def run @response = get_response case response when Net::HTTPSuccess parse_body response.body else error_msg [response.code, response.].join(': ') end end |