correios_sro_scraper 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0af8c87089c21c2ca292a657e7ff15f433501db9
4
+ data.tar.gz: 01585bfb5c737fa0d9d3cf17a15f34912ac5139b
5
+ SHA512:
6
+ metadata.gz: ec366457a43f530c1aed4c19379ddfcbd5338ccb45c48544c871aec261ddfc023c73a2627171051385e688bf6271a95b9dcd500764346d2db3eff313effb4f1c
7
+ data.tar.gz: 33f53d48cadcae7a5b2b2b4c43d6cea1b21f28e8d6716dfc5e735a6440c2724c4c75e48ab2fcb8be07a768ea74916edbf1ac7630ede1dc9cc64eb049f8fdd1ab
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1 @@
1
+ correios_srco_scraper
@@ -0,0 +1 @@
1
+ ruby-2.3.1
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.13.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in correios_sro_scraper.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Pedro Pazello
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,41 @@
1
+ # CorreiosSroScraper
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/correios_sro_scraper`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'correios_sro_scraper'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install correios_sro_scraper
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/correios_sro_scraper.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
+
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "correios_sro_scraper"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'correios_sro_scraper/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "correios_sro_scraper"
8
+ spec.version = CorreiosSroScraper::VERSION
9
+ spec.authors = ["Pedro Pazello"]
10
+ spec.email = ["pedropazello.rj@gmail.com"]
11
+
12
+ spec.summary = %q{Write a short summary, because Rubygems requires one.}
13
+ spec.homepage = "https://github.com/pedropazello/correios_sro_scraper"
14
+ spec.license = "MIT"
15
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
16
+ f.match(%r{^(test|spec|features)/})
17
+ end
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.13"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "rspec", "~> 3.0"
25
+ spec.add_development_dependency "vcr"
26
+ spec.add_development_dependency "webmock"
27
+ spec.add_development_dependency "pry"
28
+ spec.add_dependency "nokogiri"
29
+ end
@@ -0,0 +1,64 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://websro.correios.com.br/sro_bin/txect01$.QueryList?P_COD_UNI=test&P_LINGUA=001&P_TIPO=001
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept-Encoding:
11
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
12
+ Accept:
13
+ - "*/*"
14
+ User-Agent:
15
+ - Ruby
16
+ response:
17
+ status:
18
+ code: 200
19
+ message: OK
20
+ headers:
21
+ Date:
22
+ - Sat, 26 Nov 2016 10:48:11 GMT
23
+ Server:
24
+ - Oracle-Application-Server-10g/10.1.2.0.2 Oracle-HTTP-Server
25
+ Content-Length:
26
+ - '1235'
27
+ Content-Type:
28
+ - text/html; charset=ISO-8859-1
29
+ X-Cache:
30
+ - MISS from 127.0.0.1
31
+ body:
32
+ encoding: ASCII-8BIT
33
+ string: !binary |-
34
+ PGh0bWw+CjxoZWFkPgo8dGl0bGU+U1JPIC0gSW50ZXJuZXQ8L3RpdGxlPgo8
35
+ L2hlYWQ+CjxTQ1JJUFQ+CjwhLS0gSGlkZSBmcm9tIG9sZCBicm93c2Vycwp2
36
+ YXIgRm9ybVR5cGUgPSAiVXBkYXRlIjsKdmFyIE5leHRGaWVsZCA9ICJQX0NP
37
+ RF9GSU4iOwpmdW5jdGlvbiBKU0xOb3ROdWxsKHBjdGwsIHBtc2cpewogICBp
38
+ ZiAocGN0bC52YWx1ZSA9PSAiIikgeyBhbGVydChwbXNnKTsgcGN0bC5mb2N1
39
+ cygpOyByZXR1cm4gZmFsc2U7IH0KICAgcmV0dXJuIHRydWU7Cn0KZnVuY3Rp
40
+ b24gSlNMTWFrZVVwcGVyKHBjdGwpIHsKICAgcGN0bC52YWx1ZSA9IHBjdGwu
41
+ dmFsdWUudG9VcHBlckNhc2UoKTsKfQpmdW5jdGlvbiBCVF9WT0xUQVJfT25D
42
+ bGljayhjdGwpIHsKaGlzdG9yeS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RlbiBuYW1lPSJaX0FD
59
+ VElPTiI+CjxpbnB1dCB0eXBlPWJ1dHRvbiBuYW1lPSJkb25lIiB2YWx1ZT0i
60
+ QmFjayIgb25DbGljaz0iQlRfVk9MVEFSX09uQ2xpY2sodGhpcykiPgo8L2Zv
61
+ cm0+CjwvYm9keT4KPC9odG1sPgo=
62
+ http_version:
63
+ recorded_at: Sat, 26 Nov 2016 10:48:11 GMT
64
+ recorded_with: VCR 3.0.3
@@ -0,0 +1,143 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://websro.correios.com.br/sro_bin/txect01$.QueryList?P_COD_UNI=DU841641734BR&P_LINGUA=001&P_TIPO=001
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept-Encoding:
11
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
12
+ Accept:
13
+ - "*/*"
14
+ User-Agent:
15
+ - Ruby
16
+ response:
17
+ status:
18
+ code: 200
19
+ message: OK
20
+ headers:
21
+ Date:
22
+ - Sat, 26 Nov 2016 10:25:54 GMT
23
+ Server:
24
+ - Oracle-Application-Server-10g/10.1.2.0.2 Oracle-HTTP-Server
25
+ Content-Length:
26
+ - '4787'
27
+ Content-Type:
28
+ - text/html; charset=ISO-8859-1
29
+ X-Cache:
30
+ - MISS from 127.0.0.1
31
+ body:
32
+ encoding: ASCII-8BIT
33
+ string: !binary |-
34
+ PGh0bWw+CjxoZWFkPgo8dGl0bGU+U1JPIC0gSW50ZXJuZXQ8L3RpdGxlPgo8
35
+ L2hlYWQ+CjxTQ1JJUFQ+CjwhLS0gSGlkZSBmcm9tIG9sZCBicm93c2Vycwp2
36
+ YXIgRm9ybVR5cGUgPSAiVXBkYXRlIjsKdmFyIE5leHRGaWVsZCA9ICJQX0NP
37
+ RF9GSU4iOwpmdW5jdGlvbiBKU0xOb3ROdWxsKHBjdGwsIHBtc2cpewogICBp
38
+ ZiAocGN0bC52YWx1ZSA9PSAiIikge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hzPTE1MHgxNTAmY2h0PXFy
135
+ JmNobD1EVTg0MTY0MTczNEJSIiBib3JkZXI9IjAiPgo8aW5wdXQgdHlwZT1o
136
+ aWRkZW4gbmFtZT0iWl9BQ1RJT04iPgo8aW5wdXQgdHlwZT1idXR0b24gbmFt
137
+ ZT0iZG9uZSIgdmFsdWU9Ik5vdmEgQ29uc3VsdGEiIG9uQ2xpY2s9IkJUX05F
138
+ V1BfT25DbGljayh0aGlzKSI+CjxpbnB1dCB0eXBlPWJ1dHRvbiBuYW1lPSJQ
139
+ cmludCIgdmFsdWU9IlByaW50IiBvbkNsaWNrPSJJTVBSSU1JUih0aGlzKSI+
140
+ CjwvYm9keT4KPC9odG1sPgo=
141
+ http_version:
142
+ recorded_at: Sat, 26 Nov 2016 10:25:54 GMT
143
+ recorded_with: VCR 3.0.3
@@ -0,0 +1,71 @@
1
+ require "correios_sro_scraper/version"
2
+ require "nokogiri"
3
+ require "open-uri"
4
+
5
+ module CorreiosSroScraper
6
+ class Scraper
7
+ BASE_URL = "http://websro.correios.com.br/sro_bin/txect01$.QueryList?P_LINGUA=001&P_TIPO=001&"
8
+ def initialize(package_code)
9
+ @package_code = package_code
10
+ end
11
+
12
+ def parsed_package_log
13
+ raise PackageCodeNotFoundException if package_code_not_found?
14
+ package_log_lines.map.with_index do |line, index|
15
+ next if only_status_line?(line)
16
+ {
17
+ date: find_date(line),
18
+ origin: find_origin(line),
19
+ status: find_status(line),
20
+ description: find_description(index)
21
+ }
22
+ end.compact
23
+ end
24
+
25
+ private
26
+
27
+ def doc
28
+ @doc ||= Nokogiri::HTML(sro_html)
29
+ end
30
+
31
+ def sro_html
32
+ open("#{BASE_URL}P_COD_UNI=#{@package_code}").read
33
+ end
34
+
35
+ def package_code_not_found?
36
+ not_found_message = doc.xpath('//p').children[0].text
37
+ not_found_message.include?('Informe o identificador do objeto.')
38
+ end
39
+
40
+ def package_log_lines
41
+ doc.xpath('//table//tr').drop(1)
42
+ end
43
+
44
+ def only_status_line?(line)
45
+ line.children[1].nil?
46
+ end
47
+
48
+ def find_date(line)
49
+ line.children[0].text
50
+ end
51
+
52
+ def find_origin(line)
53
+ line.children[1].text
54
+ end
55
+
56
+ def find_status(line)
57
+ line.children[2].text
58
+ end
59
+
60
+ def find_description(current_index)
61
+ find_current_line_description(current_index)&.children&.text
62
+ end
63
+
64
+ def find_current_line_description(current_index)
65
+ package_log_lines[current_index + 1]
66
+ end
67
+ end
68
+
69
+ class PackageCodeNotFoundException < StandardError
70
+ end
71
+ end
@@ -0,0 +1,3 @@
1
+ module CorreiosSroScraper
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,158 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: correios_sro_scraper
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Pedro Pazello
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-11-27 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: '1.13'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.13'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.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: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: vcr
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
+ - !ruby/object:Gem::Dependency
70
+ name: webmock
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: nokogiri
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description:
112
+ email:
113
+ - pedropazello.rj@gmail.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".gitignore"
119
+ - ".rspec"
120
+ - ".ruby-gemset"
121
+ - ".ruby-version"
122
+ - ".travis.yml"
123
+ - Gemfile
124
+ - LICENSE.txt
125
+ - README.md
126
+ - Rakefile
127
+ - bin/console
128
+ - bin/setup
129
+ - correios_sro_scraper.gemspec
130
+ - fixtures/vcr_cassettes/invalid_package_log.yml
131
+ - fixtures/vcr_cassettes/package_log.yml
132
+ - lib/correios_sro_scraper.rb
133
+ - lib/correios_sro_scraper/version.rb
134
+ homepage: https://github.com/pedropazello/correios_sro_scraper
135
+ licenses:
136
+ - MIT
137
+ metadata: {}
138
+ post_install_message:
139
+ rdoc_options: []
140
+ require_paths:
141
+ - lib
142
+ required_ruby_version: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - ">="
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ required_rubygems_version: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - ">="
150
+ - !ruby/object:Gem::Version
151
+ version: '0'
152
+ requirements: []
153
+ rubyforge_project:
154
+ rubygems_version: 2.6.3
155
+ signing_key:
156
+ specification_version: 4
157
+ summary: Write a short summary, because Rubygems requires one.
158
+ test_files: []