royal_mail_scraper 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.travis.yml +8 -0
- data/Gemfile +12 -0
- data/LICENSE.txt +22 -0
- data/README.md +42 -0
- data/Rakefile +6 -0
- data/lib/royal_mail_scraper/tracker/detail.rb +12 -0
- data/lib/royal_mail_scraper/tracker/request.rb +23 -0
- data/lib/royal_mail_scraper/tracker/response.rb +36 -0
- data/lib/royal_mail_scraper/tracker/status_map.rb +27 -0
- data/lib/royal_mail_scraper/tracker.rb +35 -0
- data/lib/royal_mail_scraper/version.rb +3 -0
- data/lib/royal_mail_scraper.rb +16 -0
- data/royal_mail_scraper.gemspec +24 -0
- data/spec/assets/collected.html +633 -0
- data/spec/assets/delivered.html +638 -0
- data/spec/assets/not_found.html +624 -0
- data/spec/assets/on_delivery.html +633 -0
- data/spec/royal_mail_scraper_spec.rb +20 -0
- data/spec/spec_helper.rb +9 -0
- data/spec/tracker_spec.rb +80 -0
- metadata +114 -0
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe RoyalMailScraper do
|
4
|
+
describe '.tracking_number?' do
|
5
|
+
let(:examples) do
|
6
|
+
{
|
7
|
+
'RU401513974GB' => true,
|
8
|
+
'ru401513974gb' => true,
|
9
|
+
'RU401513974CZ' => false,
|
10
|
+
'RU4015139GB' => false,
|
11
|
+
}
|
12
|
+
end
|
13
|
+
|
14
|
+
specify do
|
15
|
+
examples.each do |tracking_number, expected_result|
|
16
|
+
expect(RoyalMailScraper.tracking_number?(tracking_number)).to be(expected_result)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe RoyalMailScraper::Tracker do
|
4
|
+
describe '.fetch' do
|
5
|
+
subject(:tracker) { described_class.fetch(tracking_number) }
|
6
|
+
|
7
|
+
shared_examples 'tracker with details' do
|
8
|
+
it 'contains correct detail statuses' do
|
9
|
+
expect(tracker).to be_instance_of(described_class)
|
10
|
+
expect(tracker.tracking_number).to eq tracking_number
|
11
|
+
expect(tracker.details.map(&:status)).to eq expected_statuses
|
12
|
+
expect(tracker.status).to eq expected_statuses.last
|
13
|
+
expect(tracker.datetime).to eq tracker.details.last.datetime if tracker.details.any?
|
14
|
+
expect(tracker.message).to eq tracker.details.last.message if tracker.details.any?
|
15
|
+
expect(tracker.location).to eq tracker.details.last.location if tracker.details.any?
|
16
|
+
expect(tracker.recognised_details).not_to be_empty if tracker.details.any?
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context 'with real response' do
|
21
|
+
let(:tracking_number) { 'RU401513974GB' }
|
22
|
+
let(:expected_statuses) do
|
23
|
+
["in_transit", "in_transit", "in_transit", "delivered"]
|
24
|
+
end
|
25
|
+
|
26
|
+
it_behaves_like 'tracker with details'
|
27
|
+
end
|
28
|
+
|
29
|
+
context 'with mocked response' do
|
30
|
+
let(:tracking_number) { 'KF000000000GB' }
|
31
|
+
let(:html) { File.binread(File.dirname(__FILE__) + '/assets/' + file) }
|
32
|
+
let(:http_response) { double(body: html) }
|
33
|
+
|
34
|
+
before { expect_any_instance_of(Net::HTTP).to receive(:request).and_return(http_response) }
|
35
|
+
|
36
|
+
context 'collected' do
|
37
|
+
let(:file) { 'collected.html' }
|
38
|
+
|
39
|
+
let(:expected_statuses) do
|
40
|
+
["in_transit", "undelivered", "held_at_enquiry_office", "in_transit"]
|
41
|
+
end
|
42
|
+
|
43
|
+
it_behaves_like 'tracker with details'
|
44
|
+
|
45
|
+
its('datetime.to_s') { should eq '2014-07-02T13:28:00+00:00' }
|
46
|
+
end
|
47
|
+
|
48
|
+
context 'delivered' do
|
49
|
+
let(:file) { 'delivered.html' }
|
50
|
+
|
51
|
+
let(:expected_statuses) do
|
52
|
+
["in_transit", "in_transit", "in_transit", "in_transit", "in_transit", "in_transit",
|
53
|
+
"on_delivery", "delivered", "delivered"]
|
54
|
+
end
|
55
|
+
|
56
|
+
it_behaves_like 'tracker with details'
|
57
|
+
end
|
58
|
+
|
59
|
+
context 'on delivery' do
|
60
|
+
let(:file) { 'on_delivery.html' }
|
61
|
+
|
62
|
+
let(:expected_statuses) do
|
63
|
+
["in_transit", "undelivered", "held_at_enquiry_office", "on_delivery"]
|
64
|
+
end
|
65
|
+
|
66
|
+
it_behaves_like 'tracker with details'
|
67
|
+
end
|
68
|
+
|
69
|
+
context 'not found' do
|
70
|
+
let(:file) { 'not_found.html' }
|
71
|
+
|
72
|
+
let(:expected_statuses) do
|
73
|
+
[]
|
74
|
+
end
|
75
|
+
|
76
|
+
it_behaves_like 'tracker with details'
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
metadata
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: royal_mail_scraper
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Laurynas Butkus
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-07-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: nokogiri
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.5'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.3'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
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
|
+
description: A simple page scraper for Royal Mail Track and Trace
|
56
|
+
email:
|
57
|
+
- laurynas.butkus@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- .gitignore
|
63
|
+
- .travis.yml
|
64
|
+
- Gemfile
|
65
|
+
- LICENSE.txt
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- lib/royal_mail_scraper.rb
|
69
|
+
- lib/royal_mail_scraper/tracker.rb
|
70
|
+
- lib/royal_mail_scraper/tracker/detail.rb
|
71
|
+
- lib/royal_mail_scraper/tracker/request.rb
|
72
|
+
- lib/royal_mail_scraper/tracker/response.rb
|
73
|
+
- lib/royal_mail_scraper/tracker/status_map.rb
|
74
|
+
- lib/royal_mail_scraper/version.rb
|
75
|
+
- royal_mail_scraper.gemspec
|
76
|
+
- spec/assets/collected.html
|
77
|
+
- spec/assets/delivered.html
|
78
|
+
- spec/assets/not_found.html
|
79
|
+
- spec/assets/on_delivery.html
|
80
|
+
- spec/royal_mail_scraper_spec.rb
|
81
|
+
- spec/spec_helper.rb
|
82
|
+
- spec/tracker_spec.rb
|
83
|
+
homepage: https://github.com/laurynas/royal_mail_scraper
|
84
|
+
licenses:
|
85
|
+
- MIT
|
86
|
+
metadata: {}
|
87
|
+
post_install_message:
|
88
|
+
rdoc_options: []
|
89
|
+
require_paths:
|
90
|
+
- lib
|
91
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - '>='
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- - '>='
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
requirements: []
|
102
|
+
rubyforge_project:
|
103
|
+
rubygems_version: 2.2.2
|
104
|
+
signing_key:
|
105
|
+
specification_version: 4
|
106
|
+
summary: Fetches tracking information from Royal Mail page
|
107
|
+
test_files:
|
108
|
+
- spec/assets/collected.html
|
109
|
+
- spec/assets/delivered.html
|
110
|
+
- spec/assets/not_found.html
|
111
|
+
- spec/assets/on_delivery.html
|
112
|
+
- spec/royal_mail_scraper_spec.rb
|
113
|
+
- spec/spec_helper.rb
|
114
|
+
- spec/tracker_spec.rb
|