apple_warranty_check 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 71194e5d218383d9d37d5f4f0ba7ef5b43c7482e
4
- data.tar.gz: fb7f3c1ffdbda38240d09cf129f6e170da1b4b9b
3
+ metadata.gz: 28cf9938788f73aecbcd2157555a7b233068e150
4
+ data.tar.gz: 21886b40f483d2966c2c14a224db1734a0368eb2
5
5
  SHA512:
6
- metadata.gz: ee198ee1535bbaeab46e6170a2d1fdc4526e84b3b1bcd6aea838335f515fcdedb5ab1f0d983439a039e64a167a15b373dec3011af9fe76dde286b1bb8c18faf2
7
- data.tar.gz: 174ff31b8622a8e56ff06f24a625a89771b3f5815e4ee2c7d92a3387b739b9fbbe0df333bfa245d3aae1d67e9cdf7785c6ba0a1252dfb10681cdd2e65a93c190
6
+ metadata.gz: 628e17aea374f37e996fcee3568ac240d8af740e28de703cbb7018a8b0a6e79224fc1bdee02e7ee5fd42c36ccdd2942e06a6bb83b21aa69245cc896fa6afc4b0
7
+ data.tar.gz: c912ec837824e5ce3828b8dfbafe25dc97dae411275f7de62f98c1876dea9c4d2bea36a9f645eca0ca10044297c686f028c151267ca6dda6e00b17d9308fb38c
@@ -17,6 +17,8 @@ module AppleWarrantyCheck
17
17
 
18
18
  ERR_RESP_REGEXP = /var errorMsg = '(.*)';/
19
19
 
20
+ NOT_REGISTERED_REGEXP = /window.location.href =(.*);/.freeze
21
+
20
22
  PRODUCT_INFO_KEYS = %i(prodImgUrl prodDesc isIMEINum APIMEINum isProdId prodId sn).freeze
21
23
  PH_SUPPORT_INFO_KEYS = %i(hasPhoneSuppCov phoneSuppSubHeader phoneSuppCovTxt phoneSuppLink).freeze
22
24
  HW_SUPPORT_INFO_KEYS = %i(hasHWSuppCov HWRepairSubHead HWSuppCovTxt HWSuppLnk hasCLMessageCode).freeze
@@ -32,15 +34,15 @@ module AppleWarrantyCheck
32
34
  end
33
35
 
34
36
  def parse_body(html)
35
- if ERR_RESP_REGEXP.match(html).nil?
36
- {
37
- product_info: get_product_info(html),
38
- phone_support: get_phone_support_info(html),
39
- hw_support: get_hw_support_info(html)
40
- }
41
- else
42
- { error: ERR_RESP_REGEXP.match(html)[1] }
43
- end
37
+ return error_response(html) unless ERR_RESP_REGEXP.match(html).nil?
38
+
39
+ return not_registered unless NOT_REGISTERED_REGEXP.match(html).nil?
40
+
41
+ {
42
+ product_info: get_product_info(html),
43
+ phone_support: get_phone_support_info(html),
44
+ hw_support: get_hw_support_info(html)
45
+ }
44
46
  end
45
47
 
46
48
  def get_phone_support_info(html)
@@ -78,5 +80,14 @@ module AppleWarrantyCheck
78
80
  expiration_date: (EXP_DATE.match(match_data[3])[1] rescue nil)
79
81
  )
80
82
  end
83
+
84
+ def error_response(html)
85
+ { error: ERR_RESP_REGEXP.match(html)[1] }
86
+ end
87
+
88
+ # TODO follow redirect to get live apple message
89
+ def not_registered
90
+ { error: "Please validate your product's purchase date. Apple is unable to provide information about your service coverage." }
91
+ end
81
92
  end
82
93
  end
@@ -1,3 +1,3 @@
1
1
  module AppleWarrantyCheck
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  describe AppleWarrantyCheck do
4
4
  it 'has a version number' do
5
- expect(AppleWarrantyCheck::VERSION).to eq '0.0.1'
5
+ expect(AppleWarrantyCheck::VERSION).to eq '0.0.2'
6
6
  end
7
7
 
8
8
  let(:valid_warranty_html) { File.open('spec/files/valid_warranty_resp.html').read }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apple_warranty_check
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Chernyshev