apple_warranty_check 0.0.2 → 0.0.3

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: 28cf9938788f73aecbcd2157555a7b233068e150
4
- data.tar.gz: 21886b40f483d2966c2c14a224db1734a0368eb2
3
+ metadata.gz: 60bcec6d62ab2bc0417c81e48217baa8135f3e91
4
+ data.tar.gz: d34d92ced8b939bd51e2f4e95dbd58e35858535e
5
5
  SHA512:
6
- metadata.gz: 628e17aea374f37e996fcee3568ac240d8af740e28de703cbb7018a8b0a6e79224fc1bdee02e7ee5fd42c36ccdd2942e06a6bb83b21aa69245cc896fa6afc4b0
7
- data.tar.gz: c912ec837824e5ce3828b8dfbafe25dc97dae411275f7de62f98c1876dea9c4d2bea36a9f645eca0ca10044297c686f028c151267ca6dda6e00b17d9308fb38c
6
+ metadata.gz: a6732a3072693525ff52b36fa6b40befa186e20c99fc707c79e4bc4cc14f1862fe27b04012508942845a9f313f33cfb48babd4ad3c162ddcbeeb70e9f79c3d8e
7
+ data.tar.gz: 735b771c3a5a1569a50efe5d1f20610a869e477a08572d1b140874b4c81065b17cede030aed8555ac65c203081b1288ee3922a5f83360d44b6bf97264c122a82
data/.gitignore CHANGED
@@ -1,5 +1,7 @@
1
1
  /.bundle/
2
2
  /.yardoc
3
+ .ruby-version
4
+ .ruby-gemset
3
5
  /Gemfile.lock
4
6
  /_yardoc/
5
7
  /coverage/
data/README.md CHANGED
@@ -1,7 +1,9 @@
1
1
  # AppleWarrantyCheck
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/apple_warranty_check.svg)](http://badge.fury.io/rb/apple_warranty_check)
3
4
  [![Build Status](https://travis-ci.org/flowerett/apple_warranty_check.svg?branch=master)](https://travis-ci.org/flowerett/apple_warranty_check)
4
5
  [![Code Climate](https://codeclimate.com/github/flowerett/apple_warranty_check/badges/gpa.svg)](https://codeclimate.com/github/flowerett/apple_warranty_check)
6
+ [![Dependency Status](https://gemnasium.com/flowerett/apple_warranty_check.svg)](https://gemnasium.com/flowerett/apple_warranty_check)
5
7
 
6
8
  Simple tool to get warranty info for Apple devices by it's IMEI.
7
9
 
@@ -8,14 +8,14 @@ module AppleWarrantyCheck
8
8
  BOOL_ARG = "(true|false)".freeze
9
9
 
10
10
  PRODUCT_INFO_REGEXP = /warrantyPage.warrantycheck.displayProductInfo\((.*)\)/.freeze
11
- PH_SUPPORT_INFO_REGEXP = /warrantyPage.warrantycheck.displayPHSupportInfo\(\s*#{BOOL_ARG},\s*#{STR_ARG},\s*#{STR_ARG},\s*#{STR_ARG}/
11
+ PH_SUPPORT_INFO_REGEXP = /warrantyPage.warrantycheck.displayPHSupportInfo\(\s*#{BOOL_ARG},\s*#{STR_ARG},\s*#{STR_ARG},\s*#{STR_ARG}/.freeze
12
12
  HW_SUPPORT_INFO_REGEXP = /warrantyPage.warrantycheck.displayHWSupportInfo\(\s*#{BOOL_ARG},\s*#{STR_ARG},\s*#{STR_ARG},\s*#{STR_ARG},\s*#{STR_ARG}/.freeze
13
13
 
14
14
  PH_SUPPORT_STATUS = /Telephone Technical Support: (Active|Expired)/.freeze
15
15
  HW_SUPPORT_STATUS = /Repairs and Service Coverage: (Active|Expired)/.freeze
16
16
  EXP_DATE = /Estimated Expiration Date: (.*\s\d{2},\s\d{4})/.freeze
17
17
 
18
- ERR_RESP_REGEXP = /var errorMsg = '(.*)';/
18
+ ERR_RESP_REGEXP = /var errorMsg = '(.*)';/.freeze
19
19
 
20
20
  NOT_REGISTERED_REGEXP = /window.location.href =(.*);/.freeze
21
21
 
@@ -23,14 +23,20 @@ module AppleWarrantyCheck
23
23
  PH_SUPPORT_INFO_KEYS = %i(hasPhoneSuppCov phoneSuppSubHeader phoneSuppCovTxt phoneSuppLink).freeze
24
24
  HW_SUPPORT_INFO_KEYS = %i(hasHWSuppCov HWRepairSubHead HWSuppCovTxt HWSuppLnk hasCLMessageCode).freeze
25
25
 
26
- attr_accessor :imei
26
+ attr_accessor :imei, :response
27
27
 
28
28
  def initialize(imei=nil)
29
29
  @imei = imei
30
+ @response = get_response
30
31
  end
31
32
 
32
33
  def run
33
- parse_body get_response.body
34
+ case response
35
+ when Net::HTTPSuccess
36
+ parse_body response.body
37
+ else
38
+ error_msg [response.code, response.message].join(': ')
39
+ end
34
40
  end
35
41
 
36
42
  def parse_body(html)
@@ -54,10 +60,12 @@ module AppleWarrantyCheck
54
60
  end
55
61
 
56
62
  def get_product_info(html)
57
- [
58
- PRODUCT_INFO_KEYS,
59
- PRODUCT_INFO_REGEXP.match(html)[1].split(',').map{ |el| el.strip.gsub('\'', '') }
60
- ].transpose.to_h
63
+ process_with_exception 'could not find product info' do
64
+ [
65
+ PRODUCT_INFO_KEYS,
66
+ PRODUCT_INFO_REGEXP.match(html)[1].split(',').map{ |el| el.strip.gsub('\'', '') }
67
+ ].transpose.to_h
68
+ end
61
69
  end
62
70
 
63
71
  private
@@ -68,26 +76,40 @@ module AppleWarrantyCheck
68
76
 
69
77
  uri.query = URI.encode_www_form(params)
70
78
 
71
- Net::HTTP.get_response(uri)
79
+ res = Net::HTTP.get_response(uri)
72
80
  end
73
81
 
74
82
  def get_support_info(regexp, keys, status_regexp, html)
75
- match_data = regexp.match(html)
83
+ process_with_exception 'could not find support info' do
84
+ match_data = regexp.match(html)
85
+
86
+ keys.map.
87
+ with_index{ |el, i| [el, match_data[i+1]] }.
88
+ to_h.
89
+ merge!(
90
+ support_status: status_regexp.match(match_data[2])[1],
91
+ expiration_date: (EXP_DATE.match(match_data[3])[1] rescue nil)
92
+ )
93
+ end
94
+ end
76
95
 
77
- keys.map.with_index{ |el, i| [el, match_data[i+1]] }.to_h.
78
- merge!(
79
- support_status: status_regexp.match(match_data[2])[1],
80
- expiration_date: (EXP_DATE.match(match_data[3])[1] rescue nil)
81
- )
96
+ def process_with_exception(message)
97
+ yield
98
+ rescue NoMethodError
99
+ message
82
100
  end
83
101
 
84
102
  def error_response(html)
85
- { error: ERR_RESP_REGEXP.match(html)[1] }
103
+ error_msg ERR_RESP_REGEXP.match(html)[1]
86
104
  end
87
105
 
88
106
  # TODO follow redirect to get live apple message
89
107
  def not_registered
90
- { error: "Please validate your product's purchase date. Apple is unable to provide information about your service coverage." }
108
+ error_msg "Please validate your product's purchase date. Apple is unable to provide information about your service coverage."
109
+ end
110
+
111
+ def error_msg(message)
112
+ { error: message }
91
113
  end
92
114
  end
93
115
  end
@@ -1,3 +1,3 @@
1
1
  module AppleWarrantyCheck
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
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.2'
5
+ expect(AppleWarrantyCheck::VERSION).to eq '0.0.3'
6
6
  end
7
7
 
8
8
  let(:valid_warranty_html) { File.open('spec/files/valid_warranty_resp.html').read }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apple_warranty_check
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Chernyshev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-08 00:00:00.000000000 Z
11
+ date: 2015-06-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler