correios-sro 2.0.4 → 3.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 +26 -0
- data/Gemfile +4 -0
- data/License.txt +22 -0
- data/Rakefile +1 -0
- data/Readme.md +54 -0
- data/correios-sro.gemspec +25 -0
- data/lib/correios_sro.rb +12 -0
- data/lib/correios_sro/parser.rb +36 -0
- data/lib/correios_sro/status.rb +5 -0
- data/lib/correios_sro/track.rb +25 -0
- data/lib/correios_sro/version.rb +3 -0
- metadata +63 -28
- data/LICENSE +0 -7
- data/README.rdoc +0 -45
- data/lib/correios-sro.rb +0 -39
- data/lib/status.rb +0 -3
- data/lib/track.rb +0 -23
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e5e6d06b9d1522cfff200d4914f9830996c54586
|
4
|
+
data.tar.gz: 140d19f5e86354e0ce37df153ec42f7c910644bc
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d1569da9dffc4e51e74eefb16861a09b63e81ded197988d4c806c4cf3f851aa2753b394831e1eb2b7c57136f375c3078dc359ed6113ea30e06cab620ef18d1cb
|
7
|
+
data.tar.gz: d24f80aa0943b978e63248f0a00c53516085ba11f29b8a0ff3c9a06162ec3cda31d837170f3549d95ea2213209bb338384ce47fd5ba9cb23beac6f1e2c5ca219
|
data/.gitignore
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# Default
|
2
|
+
*.gem
|
3
|
+
*.rbc
|
4
|
+
.bundle
|
5
|
+
.config
|
6
|
+
.yardoc
|
7
|
+
Gemfile.lock
|
8
|
+
InstalledFiles
|
9
|
+
_yardoc
|
10
|
+
coverage
|
11
|
+
doc/
|
12
|
+
lib/bundler/man
|
13
|
+
pkg
|
14
|
+
rdoc
|
15
|
+
spec/reports
|
16
|
+
test/tmp
|
17
|
+
test/version_tmp
|
18
|
+
tmp
|
19
|
+
*.bundle
|
20
|
+
*.so
|
21
|
+
*.o
|
22
|
+
*.a
|
23
|
+
mkmf.log
|
24
|
+
|
25
|
+
# Others
|
26
|
+
.DS_Store
|
data/Gemfile
ADDED
data/License.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Caio Tarifa
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/Readme.md
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
# Correios SRO
|
2
|
+
|
3
|
+
Tracking object system from Correios (Brazil).
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'correios-sro'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install correios-sro
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
### Basic
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
package = CorreiosSRO.track('SS987654321BR')
|
25
|
+
|
26
|
+
if package
|
27
|
+
puts package.number
|
28
|
+
package.status.each do |status|
|
29
|
+
puts status.date
|
30
|
+
puts status.place
|
31
|
+
puts status.track
|
32
|
+
puts status.details
|
33
|
+
end
|
34
|
+
end
|
35
|
+
```
|
36
|
+
|
37
|
+
### First or Last
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
package = CorreiosSRO.track('SS987654321XX')
|
41
|
+
|
42
|
+
if package
|
43
|
+
puts package.first.date
|
44
|
+
puts package.last.date
|
45
|
+
end
|
46
|
+
```
|
47
|
+
|
48
|
+
## Contributing
|
49
|
+
|
50
|
+
1. Fork it ( https://github.com/formaweb/correios-sro/fork )
|
51
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
52
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
53
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
54
|
+
5. Create a new Pull Request
|
@@ -0,0 +1,25 @@
|
|
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/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "correios-sro"
|
8
|
+
spec.version = CorreiosSRO::VERSION
|
9
|
+
spec.authors = ["Caio Tarifa"]
|
10
|
+
spec.email = ["caio@formaweb.com.br"]
|
11
|
+
spec.summary = %q{Tracking object system from Correios (Brazil).}
|
12
|
+
spec.description = %q{Tracking object system from Correios (Brazil).}
|
13
|
+
spec.homepage = "https://github.com/formaweb/correios-sro"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "nokogiri"
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
24
|
+
spec.add_development_dependency "rake"
|
25
|
+
end
|
data/lib/correios_sro.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
module CorreiosSRO
|
2
|
+
class << self
|
3
|
+
WEBSRO = "http://websro.correios.com.br/sro_bin/txect01$.QueryList?P_LINGUA=001&P_TIPO=001&P_COD_UNI"
|
4
|
+
|
5
|
+
def track(number)
|
6
|
+
@html = Nokogiri::HTML open("#{WEBSRO}=#{number}")
|
7
|
+
|
8
|
+
if @html.xpath("//tr").count > 0
|
9
|
+
track = Track.new number
|
10
|
+
parse track
|
11
|
+
|
12
|
+
return track
|
13
|
+
end
|
14
|
+
|
15
|
+
return false
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
def parse(track)
|
20
|
+
@html.xpath("//tr[position() > 1]").each do |row|
|
21
|
+
if row.search("td").count > 1
|
22
|
+
track << Status.new.tap { |status|
|
23
|
+
status.date = DateTime.strptime row.search("td[@rowspan][1]").text.strip, "%d/%m/%Y %H:%M"
|
24
|
+
status.place = row.search("td[2]").text.strip
|
25
|
+
status.track = row.search("td[3]").text.strip
|
26
|
+
|
27
|
+
if row.search("td[@rowspan='2'][1]").count > 0
|
28
|
+
status.details = row.search(".//following-sibling::tr[1]").text.strip
|
29
|
+
end
|
30
|
+
}
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module CorreiosSRO
|
2
|
+
class Track
|
3
|
+
attr_reader :number, :status
|
4
|
+
|
5
|
+
def initialize(number)
|
6
|
+
@number = number
|
7
|
+
@status = Array.new
|
8
|
+
end
|
9
|
+
|
10
|
+
def <<(status)
|
11
|
+
@status << status
|
12
|
+
@status.sort! do |a, b|
|
13
|
+
a.date <=> b.date
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def first
|
18
|
+
@status.first
|
19
|
+
end
|
20
|
+
|
21
|
+
def last
|
22
|
+
@status.last
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
metadata
CHANGED
@@ -1,62 +1,97 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: correios-sro
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
5
|
-
prerelease:
|
4
|
+
version: 3.0.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
|
-
-
|
7
|
+
- Caio Tarifa
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2015-08-31 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: nokogiri
|
16
|
-
requirement:
|
17
|
-
none: false
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - ">="
|
20
18
|
- !ruby/object:Gem::Version
|
21
|
-
version:
|
19
|
+
version: '0'
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
|
-
version_requirements:
|
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: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.6'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.6'
|
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'
|
25
55
|
description: Tracking object system from Correios (Brazil).
|
26
|
-
email:
|
56
|
+
email:
|
57
|
+
- caio@formaweb.com.br
|
27
58
|
executables: []
|
28
59
|
extensions: []
|
29
|
-
extra_rdoc_files:
|
30
|
-
- README.rdoc
|
60
|
+
extra_rdoc_files: []
|
31
61
|
files:
|
32
|
-
-
|
33
|
-
-
|
34
|
-
-
|
35
|
-
-
|
36
|
-
-
|
37
|
-
|
38
|
-
|
62
|
+
- ".gitignore"
|
63
|
+
- Gemfile
|
64
|
+
- License.txt
|
65
|
+
- Rakefile
|
66
|
+
- Readme.md
|
67
|
+
- correios-sro.gemspec
|
68
|
+
- lib/correios_sro.rb
|
69
|
+
- lib/correios_sro/parser.rb
|
70
|
+
- lib/correios_sro/status.rb
|
71
|
+
- lib/correios_sro/track.rb
|
72
|
+
- lib/correios_sro/version.rb
|
73
|
+
homepage: https://github.com/formaweb/correios-sro
|
74
|
+
licenses:
|
75
|
+
- MIT
|
76
|
+
metadata: {}
|
39
77
|
post_install_message:
|
40
|
-
rdoc_options:
|
41
|
-
- --charset=UTF-8
|
78
|
+
rdoc_options: []
|
42
79
|
require_paths:
|
43
|
-
-
|
80
|
+
- lib
|
44
81
|
required_ruby_version: !ruby/object:Gem::Requirement
|
45
|
-
none: false
|
46
82
|
requirements:
|
47
|
-
- -
|
83
|
+
- - ">="
|
48
84
|
- !ruby/object:Gem::Version
|
49
85
|
version: '0'
|
50
86
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
51
|
-
none: false
|
52
87
|
requirements:
|
53
|
-
- -
|
88
|
+
- - ">="
|
54
89
|
- !ruby/object:Gem::Version
|
55
90
|
version: '0'
|
56
91
|
requirements: []
|
57
92
|
rubyforge_project:
|
58
|
-
rubygems_version:
|
93
|
+
rubygems_version: 2.4.5
|
59
94
|
signing_key:
|
60
|
-
specification_version:
|
95
|
+
specification_version: 4
|
61
96
|
summary: Tracking object system from Correios (Brazil).
|
62
97
|
test_files: []
|
data/LICENSE
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
Copyright (c) 2011 Formaweb
|
2
|
-
|
3
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
4
|
-
|
5
|
-
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
6
|
-
|
7
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
DELETED
@@ -1,45 +0,0 @@
|
|
1
|
-
= Correios SRO
|
2
|
-
|
3
|
-
Tracking object system from Correios (Brazil).
|
4
|
-
|
5
|
-
== Install
|
6
|
-
|
7
|
-
gem install correios-sro
|
8
|
-
|
9
|
-
|
10
|
-
== Use
|
11
|
-
|
12
|
-
=== Synopsis
|
13
|
-
|
14
|
-
require 'rubygems'
|
15
|
-
require 'correios-sro'
|
16
|
-
|
17
|
-
package = CorreiosSRO.track('SS987654321BR')
|
18
|
-
if package
|
19
|
-
puts package.number
|
20
|
-
package.status.each do |status|
|
21
|
-
puts status.date
|
22
|
-
puts status.place
|
23
|
-
puts status.track
|
24
|
-
puts status.details
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
|
29
|
-
=== First or Last
|
30
|
-
|
31
|
-
package = CorreiosSRO.track('SS987654321BR')
|
32
|
-
if package
|
33
|
-
puts package.first.date
|
34
|
-
puts package.last.date
|
35
|
-
end
|
36
|
-
|
37
|
-
|
38
|
-
== Contributing
|
39
|
-
|
40
|
-
* {QaDeS}[https://github.com/QaDeS]
|
41
|
-
|
42
|
-
|
43
|
-
== Notes
|
44
|
-
|
45
|
-
As always, pull requests are always welcome. If you have any issues or feature requests, please {open an issue}[https://github.com/caiotarifa/correios-sro/issues].
|
data/lib/correios-sro.rb
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
require "rubygems"
|
2
|
-
require "date"
|
3
|
-
require "open-uri"
|
4
|
-
require "nokogiri"
|
5
|
-
require "track"
|
6
|
-
require "status"
|
7
|
-
|
8
|
-
class CorreiosSRO
|
9
|
-
|
10
|
-
def self.track(number)
|
11
|
-
@html = Nokogiri::HTML(open("http://websro.correios.com.br/sro_bin/txect01$.QueryList?P_LINGUA=001&P_TIPO=001&P_COD_UNI=#{number}"))
|
12
|
-
|
13
|
-
if @html.xpath("//tr").count > 0
|
14
|
-
track = Track.new(number)
|
15
|
-
self.parse(track)
|
16
|
-
|
17
|
-
return track
|
18
|
-
else
|
19
|
-
return false
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
private
|
24
|
-
def self.parse(track)
|
25
|
-
|
26
|
-
@html.xpath("//tr[position() > 1]").each do |row|
|
27
|
-
if row.search("td").count > 1
|
28
|
-
track << Status.new.tap { |s|
|
29
|
-
s.date = DateTime.strptime(row.search("td[@rowspan][1]").text.strip, "%d/%m/%Y %H:%M")
|
30
|
-
s.place = row.search("td[2]").text.strip
|
31
|
-
s.track = row.search("td[3]").text.strip
|
32
|
-
s.details = row.search(".//following-sibling::tr[1]").text.strip if row.search("td[@rowspan='2'][1]").count > 0
|
33
|
-
}
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
end
|
38
|
-
|
39
|
-
end
|
data/lib/status.rb
DELETED
data/lib/track.rb
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
class Track
|
2
|
-
attr_reader :number, :status
|
3
|
-
|
4
|
-
def initialize(number)
|
5
|
-
@number = number
|
6
|
-
@status = Array.new
|
7
|
-
end
|
8
|
-
|
9
|
-
def <<(status)
|
10
|
-
@status << status
|
11
|
-
@status.sort! do |a, b|
|
12
|
-
a.date <=> b.date
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
def first
|
17
|
-
@status.first
|
18
|
-
end
|
19
|
-
|
20
|
-
def last
|
21
|
-
@status.last
|
22
|
-
end
|
23
|
-
end
|