imei-scrapper 0.0.0

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.
@@ -0,0 +1,44 @@
1
+
2
+ RSpec.describe ImeiScrapper::JSParser do
3
+
4
+ let(:parser) { ImeiScrapper::JSParser }
5
+
6
+ describe '#parse_hw_data' do
7
+ it 'extracts hardware warranty info' do
8
+ success_page_html = File.open(File.expand_path('../fixtures/hw_not_expired.html', __FILE__), 'rb').read
9
+ parse_result = parser.parse_hw_data(success_page_html)
10
+ expect(parse_result).to include(hw_warranty: true)
11
+ expect(parse_result).to include(expiration_date: Date.parse('August 10, 2016'))
12
+ end
13
+
14
+ it 'extracts expired warranty info' do
15
+ success_page_html = File.open(File.expand_path('../fixtures/hw_expired.html', __FILE__), 'rb').read
16
+ parse_result = parser.parse_hw_data(success_page_html)
17
+ expect(parse_result).to include(hw_warranty: false)
18
+ expect(parse_result).to include(expiration_date: nil)
19
+ end
20
+
21
+ it 'throws an error if nothing matched' do
22
+ invalid_imei_html = File.open(File.expand_path('../fixtures/invalid_imei.html', __FILE__), 'rb').read
23
+ expect { parser.parse_hw_data(invalid_imei_html) }.to raise_error(ImeiScrapper::ParseException)
24
+ end
25
+ end
26
+
27
+ describe '#extract_date' do
28
+ it 'parses expiration date' do
29
+ date = parser.extract_date('blah blah blah<br/>Estimated Expiration Date: August 10, 2016<br/><a href="http://blah"></a>')
30
+ expect(date).to eq(Date.parse('August 10, 2016'))
31
+ end
32
+
33
+ it 'returns nil if there is no match' do
34
+ date = parser.extract_date('blah blah blah<br/>Estimated Expiration Date, 2016<br/><a href="http://blah"></a>')
35
+ expect(date).to be_nil
36
+ end
37
+
38
+ it 'returns nil if date is incorrect' do
39
+ date = parser.extract_date('blah blah blah<br/>Estimated Expiration Date: Jabruaru 77, 2016<br/><a href="http://blah"></a>')
40
+ expect(date).to be_nil
41
+ end
42
+ end
43
+
44
+ end
@@ -0,0 +1,45 @@
1
+ RSpec.describe ImeiScrapper::Scrapper do
2
+
3
+ let(:expired_warranty_html) { File.open(File.expand_path('../fixtures/hw_expired.html', __FILE__), 'rb').read }
4
+ let(:not_expired_warranty_html) { File.open(File.expand_path('../fixtures/hw_not_expired.html', __FILE__), 'rb').read }
5
+ let(:invalid_imei_html) { File.open(File.expand_path('../fixtures/invalid_imei.html', __FILE__), 'rb').read }
6
+ let(:scrapper) { ImeiScrapper::Scrapper.new('test_imei') }
7
+
8
+ describe '#request' do
9
+ before(:each) do
10
+ stub_request(:post, ImeiScrapper::Scrapper::SCRAP_URL)
11
+ end
12
+
13
+ it 'sends a POST request with correct params' do
14
+ scrapper.request
15
+ expect(WebMock).to have_requested(:post, ImeiScrapper::Scrapper::SCRAP_URL)
16
+ .with(:body => {sn: 'test_imei', num: ImeiScrapper::Scrapper::NUMBER_PARAM})
17
+ end
18
+ end
19
+
20
+ describe '#get_info' do
21
+ it 'returns expired warranty info' do
22
+ stub_request(:post, ImeiScrapper::Scrapper::SCRAP_URL)
23
+ .to_return(:status => 200, :body => expired_warranty_html, :headers => {})
24
+ info = scrapper.get_info
25
+ expect(info).to include(hw_warranty: false)
26
+ expect(info).to include(expiration_date: nil)
27
+ end
28
+
29
+ it 'returns not expired warranty info' do
30
+ stub_request(:post, ImeiScrapper::Scrapper::SCRAP_URL)
31
+ .to_return(:status => 200, :body => not_expired_warranty_html, :headers => {})
32
+ info = scrapper.get_info
33
+ expect(info).to include(hw_warranty: true)
34
+ expect(info).to include(expiration_date: Date.parse('August 10, 2016'))
35
+ end
36
+
37
+ it 'returns nil if imei is invalid' do
38
+ stub_request(:post, ImeiScrapper::Scrapper::SCRAP_URL)
39
+ .to_return(:status => 200, :body => invalid_imei_html, :headers => {})
40
+ info = scrapper.get_info
41
+ expect(info).to eq(nil)
42
+ end
43
+ end
44
+
45
+ end
@@ -0,0 +1,5 @@
1
+ require 'webmock/rspec'
2
+ require 'imei-scrapper/scrapper'
3
+ require 'imei-scrapper/js_parser'
4
+ require 'imei-scrapper/parse_exception'
5
+ WebMock.disable_net_connect!
metadata ADDED
@@ -0,0 +1,123 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: imei-scrapper
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Andrey Chernyshev
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-06-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: webmock
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Apple IMEI scrapper
70
+ email: libdual@yandex.ru
71
+ executables:
72
+ - imei-scrapper
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - Gemfile
79
+ - README.md
80
+ - Rakefile
81
+ - bin/imei-scrapper
82
+ - imei-scrapper.gemspec
83
+ - lib/imei-scrapper/js_parser.rb
84
+ - lib/imei-scrapper/parse_exception.rb
85
+ - lib/imei-scrapper/scrapper.rb
86
+ - lib/imei_scrapper.rb
87
+ - spec/fixtures/hw_expired.html
88
+ - spec/fixtures/hw_not_expired.html
89
+ - spec/fixtures/invalid_imei.html
90
+ - spec/js_parser_spec.rb
91
+ - spec/scrapper_spec.rb
92
+ - spec/spec_helper.rb
93
+ homepage: http://rubygems.org/gems/imei-scrapper
94
+ licenses:
95
+ - MIT
96
+ metadata: {}
97
+ post_install_message:
98
+ rdoc_options: []
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ requirements: []
112
+ rubyforge_project:
113
+ rubygems_version: 2.2.1
114
+ signing_key:
115
+ specification_version: 4
116
+ summary: Apple IMEI scrapper
117
+ test_files:
118
+ - spec/fixtures/hw_expired.html
119
+ - spec/fixtures/hw_not_expired.html
120
+ - spec/fixtures/invalid_imei.html
121
+ - spec/js_parser_spec.rb
122
+ - spec/scrapper_spec.rb
123
+ - spec/spec_helper.rb