correios-sro 0.9.7

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright (c) 2011 Caio Tarifa
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 ADDED
@@ -0,0 +1,2 @@
1
+ == Welcome to Correios SRO
2
+ Tracking object system from Correios (Brazil)
@@ -0,0 +1,36 @@
1
+ require "rubygems"
2
+ require "nokogiri"
3
+ require "open-uri"
4
+ require "track"
5
+ require "status"
6
+
7
+ class CorreiosSRO
8
+
9
+ def self.track(number)
10
+ @xml = open("http://correios-api.appspot.com/yql?numero=#{number}")
11
+ track = Track.new(number)
12
+
13
+ status = nil
14
+ status = self.parse(track)
15
+ track << status if not status.nil?
16
+
17
+ return track
18
+ end
19
+
20
+ private
21
+ def self.parse(track)
22
+ xml = Nokogiri::XML(@xml)
23
+ status = nil
24
+
25
+ xml.xpath('/results/status').each do |value|
26
+ status = Status.new
27
+ status.date = value.search('data').inner_text
28
+ status.place = value.search('local').inner_text
29
+ status.track = value.search('situacao').inner_text
30
+ status.details = value.search('detalhes').inner_text
31
+ end
32
+
33
+ return status
34
+ end
35
+
36
+ end
data/lib/status.rb ADDED
@@ -0,0 +1,3 @@
1
+ class Status
2
+ attr_accessor :date, :place, :track, :details
3
+ end
data/lib/test.rb ADDED
File without changes
data/lib/track.rb ADDED
@@ -0,0 +1,23 @@
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
metadata ADDED
@@ -0,0 +1,69 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: correios-sro
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.9.7
6
+ platform: ruby
7
+ authors:
8
+ - Caio Tarifa
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-04-17 00:00:00 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: nokogiri
17
+ prerelease: false
18
+ requirement: &id001 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ~>
22
+ - !ruby/object:Gem::Version
23
+ version: 1.4.4
24
+ type: :runtime
25
+ version_requirements: *id001
26
+ description: Tracking object system from Correios (Brazil).
27
+ email: contato@caiotarifa.com
28
+ executables: []
29
+
30
+ extensions: []
31
+
32
+ extra_rdoc_files: []
33
+
34
+ files:
35
+ - README.rdoc
36
+ - LICENSE
37
+ - lib/correios-sro.rb
38
+ - lib/status.rb
39
+ - lib/test.rb
40
+ - lib/track.rb
41
+ homepage: http://github.com/caiotarifa/correios-sro
42
+ licenses: []
43
+
44
+ post_install_message:
45
+ rdoc_options: []
46
+
47
+ require_paths:
48
+ - - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: "0"
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: "0"
61
+ requirements: []
62
+
63
+ rubyforge_project:
64
+ rubygems_version: 1.7.2
65
+ signing_key:
66
+ specification_version: 3
67
+ summary: Tracking object system from Correios (Brazil).
68
+ test_files: []
69
+