pear_warranty 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d02cfd647347b554ae3f5cadbaa2112026de3565
4
- data.tar.gz: 0301c37701a36369fcb8f6fc85626f98c9297995
3
+ metadata.gz: 178340311308b99dcbcbb034367ad6f0a04b2a2a
4
+ data.tar.gz: 1044186ab6a3c52c516f49733ac78e54a65339d9
5
5
  SHA512:
6
- metadata.gz: 74f6407b991dae65ebeceb6523cb78598927189163516242f88f857c8b920bc04d51320afb35475700c44cb0757232132dbaeb9a0915e9259a7e8c5c50c6d27d
7
- data.tar.gz: a50b83b0c678485c22548f5fae3864518cdfbdc6e7a706a93f28169c59743516b5a49033ca64b35b337451d070152714c5ccf6a9376bc72eeea1233a1a04c0a6
6
+ metadata.gz: fb592fb527fe268121d98c9a884273ff2128ccef256950167885073a368c4231b1ccc5224e5bafd37a2b35836da31eb20075a6981365f036254990f933ed7c68
7
+ data.tar.gz: 34a5b2234776489d73fce21ef662686411cd4613bc6c73d49f48a705a48b262199c92d61c0de45defbf49be2274aff5e4f283ae2853172d9b787538ed4d25d2e
data/README.md CHANGED
@@ -41,6 +41,37 @@ PearWarranty.check('your IMEI here', 0)
41
41
  ```
42
42
  Proxy index must be in range of 0 and `PearWarranty::PROXIES.size`. If it goes out randomly chosen will be used.
43
43
 
44
+ ### Available proxies:
45
+
46
+ * 0 - Canada East
47
+ * 1 - Germany
48
+ * 2 - France (Strasbourg)
49
+ * 3 - Netherlands
50
+ * 4 - France (Roubaix)
51
+ * 5 - France (Gravelines)
52
+ * 6 - United States Central (TX)
53
+ * 7 - United States East (NJ)
54
+ * 8 - United States Central (IL)
55
+ * 9 - United States East (GA)
56
+
57
+ To improve speed your should to test which of proxies works for you most frequently. For my location (Ukraine) speed test show that result (each one is for 50 requests):
58
+
59
+ Proxy index | Location | Speed
60
+ :----------:|:--------:|:----:
61
+ 0 | Canada | 94.452161
62
+ 1 | Germany | 138.392749
63
+ 2 | Strasbourg | 79.161559
64
+ 3 | Netherlands | 133.401920
65
+ 4 | Roubaix | 70.684222
66
+ 5 | Gravelines | 71.803946
67
+ 6 | TX | 83.853322
68
+ 7 | NJ | 75.568946
69
+ 8 | IL | 103.772447
70
+ 9 | GA | 75.414354
71
+ - | random | 114.406067
72
+
73
+ That`s why I prefer to use France (Roubaix) - 4th proxy.
74
+
44
75
  ## Dependencies
45
76
 
46
77
  - mechanize
@@ -9,33 +9,42 @@ module PearWarranty
9
9
 
10
10
  def self.check(serial, proxy_index = nil)
11
11
  agent = Mechanize.new
12
- proxy_index ||= rand(PROXIES.size)
12
+ proxies = [0,1,2,3,4,5,6,7,8,9]
13
+ unless proxy_index
14
+ proxy_index = rand(PROXIES.size)
15
+ else
16
+ proxies -= [proxy_index]
17
+ end
13
18
  page = nil
14
19
  error = true
15
20
  apple_url = "https://selfsolve.apple.com/wcResults.do?sn=#{serial}&Continue=Continue&num=0"
21
+ correct_reg = /warrantyPage\.warrantycheck\.displayHWSupportInfo/
22
+ invalid_reg = [/but this serial number is not valid/, /but the serial number you have provided cannot be found in our records/]
16
23
  TRIES.times do
17
24
  form = get_form(proxy_index, apple_url, agent)
18
25
  set_cookie(agent)
19
26
  begin
20
27
  page = agent.submit(form)
21
28
  rescue Net::HTTP::Persistent::Error
22
- proxy_index = rand(PROXIES.size)
29
+ proxy_index = proxies[rand(proxies.size)]
30
+ proxies -= [proxy_index]
23
31
  next
24
32
  end
25
33
  page = page.body
26
- unless page =~ /pferror/
34
+ if page =~ correct_reg or page =~ invalid_reg[1] or page =~ invalid_reg[0]
27
35
  error = false
28
36
  break
29
37
  end
30
- proxy_index = rand(PROXIES.size)
38
+ proxy_index = proxies[rand(proxies.size)]
39
+ proxies -= [proxy_index]
31
40
  end
32
41
  if error
33
42
  {error: 'Problem with proxy'}
34
43
  else
35
- if page =~ /(but this serial number is not valid)|(but the serial number you have provided cannot be found in our records)/
44
+ unless page =~ correct_reg
36
45
  { error: 'There is no such imei or service is not available at this moment' }
37
46
  else
38
- text = page.split('warrantyPage.warrantycheck.displayPHSupportInfo')[1].scan(/\(.*\)/)[0].delete('()')
47
+ text = page.split(correct_reg)[1].scan(/\(.*\)/)[0].delete('()')
39
48
  params = text.split(', ')
40
49
  warranty = to_boolean(params.first.delete ' ')
41
50
  {
@@ -1,3 +1,3 @@
1
1
  module PearWarranty
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ["moranibaca@gmail.com"]
11
11
  spec.summary = %q{Get IPhone warranty information}
12
12
  spec.description = %q{Get IPhone warranty information form https://selfsolve.apple.com by device imei}
13
- spec.homepage = ""
13
+ spec.homepage = "https://github.com/imdrasil/pear_warranty"
14
14
  spec.license = "MIT"
15
15
 
16
16
  spec.files = `git ls-files -z`.split("\x0")
@@ -82,7 +82,7 @@ RSpec.describe PearWarranty do
82
82
  end
83
83
 
84
84
  context :check, type: :request do
85
- let(:date) { Date.new(2015, 9, 9)}
85
+ let(:date) { Date.new(2016, 6, 10)}
86
86
  before :all do
87
87
  @without_imei = '013896000639712'
88
88
  @with_imei = '013977000323877'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pear_warranty
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roman Kalnytsky
@@ -116,7 +116,7 @@ files:
116
116
  - spec/support/uncorrect_warranty.html
117
117
  - spec/support/with_warranty.html
118
118
  - spec/support/without_warranty.html
119
- homepage: ''
119
+ homepage: https://github.com/imdrasil/pear_warranty
120
120
  licenses:
121
121
  - MIT
122
122
  metadata: {}