ship 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/correios.rb +22 -17
- metadata +58 -44
data/lib/correios.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
+
require "cgi"
|
1
2
|
require "net/http"
|
2
3
|
require "uri"
|
3
|
-
require "
|
4
|
+
require "nokogiri"
|
5
|
+
require "open-uri"
|
4
6
|
require "provider.rb"
|
5
7
|
|
6
8
|
module Ship
|
@@ -44,28 +46,31 @@ module Ship
|
|
44
46
|
params["nCdServico"] = shipping.service ? shipping.service.code : ""
|
45
47
|
end
|
46
48
|
|
47
|
-
|
48
|
-
|
49
|
+
params_str = params.map {|key,val| "#{CGI.escape(key.to_s)}=#{CGI.escape(val.to_s)}"}.join("&")
|
50
|
+
url = URI.parse("http://ws.correios.com.br/calculador/CalcPrecoPrazo.asmx/CalcPrecoPrazo?#{params_str}")
|
51
|
+
data = open(url.to_s)
|
52
|
+
raise Exception.new("Could not get an answer from URL: #{full_path}") if data.status[0]!="200"
|
49
53
|
|
54
|
+
data = data.read
|
50
55
|
error_msg = data.scan(/(<Erro>)([0-9-]{1,5})(<\/Erro>)(<MsgErro>)([a-z0-9 ]+)(<\/MsgErro>)(.*)/i)
|
51
56
|
raise Exception.new(error_msg[0][4]) if error_msg.size>0 && error_msg[0][1]!="0"
|
52
57
|
|
53
|
-
xml =
|
58
|
+
xml = Nokogiri::XML(data)
|
54
59
|
rtn = {}
|
55
60
|
|
56
|
-
xml.
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
61
|
+
xml.search("Servicos/cServico").each do |cServico|
|
62
|
+
values = {
|
63
|
+
"Codigo"=>0,
|
64
|
+
"Valor"=>0,
|
65
|
+
"PrazoEntrega"=>0,
|
66
|
+
"ValorMaoPropria"=>0,
|
67
|
+
"ValorAvisoRecebimento"=>0,
|
68
|
+
"ValorValorDeclarado"=>0,
|
69
|
+
"EntregaDomiciliar"=>0,
|
70
|
+
"EntregaSabado"=>0
|
71
|
+
}
|
72
|
+
values.each {|k,v| values[k] = cServico.search("#{k}").first.text}
|
73
|
+
rtn[values["Codigo"]] = values
|
69
74
|
end
|
70
75
|
return rtn
|
71
76
|
end
|
metadata
CHANGED
@@ -1,71 +1,85 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: ship
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
6
|
-
- 0
|
7
|
-
- 0
|
8
|
-
- 3
|
9
|
-
version: 0.0.3
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.4
|
5
|
+
prerelease:
|
10
6
|
platform: ruby
|
11
|
-
authors:
|
7
|
+
authors:
|
12
8
|
- Eustaquio Rangel
|
13
9
|
autorequire:
|
14
10
|
bindir: bin
|
15
11
|
cert_chain: []
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
12
|
+
date: 2013-07-26 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: nokogiri
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: open-uri
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
21
46
|
description: A class to get values and tracking info from shipping providers
|
22
47
|
email: eustaquiorangel@gmail.com
|
23
48
|
executables: []
|
24
|
-
|
25
49
|
extensions: []
|
26
|
-
|
27
|
-
extra_rdoc_files:
|
50
|
+
extra_rdoc_files:
|
28
51
|
- LICENSE
|
29
|
-
files:
|
52
|
+
files:
|
53
|
+
- lib/provider.rb
|
30
54
|
- lib/country.rb
|
31
|
-
- lib/
|
32
|
-
- lib/correios.rb
|
55
|
+
- lib/format.rb
|
33
56
|
- lib/shipping.rb
|
57
|
+
- lib/correios.rb
|
34
58
|
- lib/ship.rb
|
35
|
-
- lib/
|
36
|
-
- lib/format.rb
|
59
|
+
- lib/service.rb
|
37
60
|
- LICENSE
|
38
|
-
has_rdoc: true
|
39
61
|
homepage: http://github.com/taq/ship
|
40
62
|
licenses: []
|
41
|
-
|
42
63
|
post_install_message:
|
43
64
|
rdoc_options: []
|
44
|
-
|
45
|
-
require_paths:
|
65
|
+
require_paths:
|
46
66
|
- lib
|
47
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
requirements:
|
56
|
-
- -
|
57
|
-
- !ruby/object:Gem::Version
|
58
|
-
segments:
|
59
|
-
- 1
|
60
|
-
- 3
|
61
|
-
- 6
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
+
none: false
|
69
|
+
requirements:
|
70
|
+
- - ! '>='
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ! '>='
|
77
|
+
- !ruby/object:Gem::Version
|
62
78
|
version: 1.3.6
|
63
79
|
requirements: []
|
64
|
-
|
65
80
|
rubyforge_project:
|
66
|
-
rubygems_version: 1.
|
81
|
+
rubygems_version: 1.8.25
|
67
82
|
signing_key:
|
68
83
|
specification_version: 3
|
69
84
|
summary: A class to get values and tracking info from shipping providers
|
70
85
|
test_files: []
|
71
|
-
|