paypal-frete-facil 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +9 -0
- data/Gemfile.lock +28 -0
- data/README.rdoc +84 -0
- data/Rakefile +52 -0
- data/lib/paypal/fretefacil/frete.rb +40 -0
- data/lib/paypal/fretefacil/parser.rb +12 -0
- data/lib/paypal/fretefacil/version.rb +11 -0
- data/lib/paypal/fretefacil/web_service.rb +47 -0
- data/lib/paypal-frete-facil.rb +5 -0
- data/paypal-frete-facil.gemspec +62 -0
- data/spec/paypal-frete-facil_spec.rb +7 -0
- data/spec/spec_helper.rb +12 -0
- metadata +112 -0
data/.document
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
diff-lcs (1.1.2)
|
5
|
+
git (1.2.5)
|
6
|
+
jeweler (1.6.2)
|
7
|
+
bundler (~> 1.0)
|
8
|
+
git (>= 1.2.5)
|
9
|
+
rake
|
10
|
+
nokogiri (1.4.6)
|
11
|
+
rake (0.9.2)
|
12
|
+
rspec (2.6.0)
|
13
|
+
rspec-core (~> 2.6.0)
|
14
|
+
rspec-expectations (~> 2.6.0)
|
15
|
+
rspec-mocks (~> 2.6.0)
|
16
|
+
rspec-core (2.6.4)
|
17
|
+
rspec-expectations (2.6.0)
|
18
|
+
diff-lcs (~> 1.1.2)
|
19
|
+
rspec-mocks (2.6.0)
|
20
|
+
|
21
|
+
PLATFORMS
|
22
|
+
ruby
|
23
|
+
|
24
|
+
DEPENDENCIES
|
25
|
+
bundler (~> 1.0.0)
|
26
|
+
jeweler
|
27
|
+
nokogiri
|
28
|
+
rspec
|
data/README.rdoc
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
= paypal-frete-facil
|
2
|
+
|
3
|
+
Cálculo de frete através do Frete Fácil do PayPal.
|
4
|
+
|
5
|
+
== Instalando
|
6
|
+
|
7
|
+
=== Gemfile
|
8
|
+
gem 'paypal-frete-facil'
|
9
|
+
|
10
|
+
=== Instalação direta
|
11
|
+
$ gem install paypal-frete-facil
|
12
|
+
|
13
|
+
|
14
|
+
== Usando
|
15
|
+
|
16
|
+
require 'paypal-frete-facil'
|
17
|
+
|
18
|
+
frete = PayPal::FreteFacil::Frete.new :cep_origem => "04094-050",
|
19
|
+
:cep_destino => "90619-900",
|
20
|
+
:largura => 15,
|
21
|
+
:altura => 2,
|
22
|
+
:profundidade => 30,
|
23
|
+
:peso => 0.3
|
24
|
+
|
25
|
+
frete.calcular # => 13.873999999999999
|
26
|
+
frete.calculate # => 13.873999999999999
|
27
|
+
|
28
|
+
=== Maneiras de configurar atributos no construtor de Correios::Frete::Calculador
|
29
|
+
|
30
|
+
==== Com um hash
|
31
|
+
frete = PayPal::FreteFacil::Frete.new :cep_origem => "04094-050",
|
32
|
+
:cep_destino => "90619-900",
|
33
|
+
:largura => 15,
|
34
|
+
:altura => 2,
|
35
|
+
:profundidade => 30,
|
36
|
+
:peso => 0.3
|
37
|
+
|
38
|
+
==== Com um bloco
|
39
|
+
frete = PayPal::FreteFacil::Frete.new do |f|
|
40
|
+
f.cep_origem = "04094-050"
|
41
|
+
f.cep_destino = "90619-900"
|
42
|
+
f.largura = 15
|
43
|
+
f.altura = 2
|
44
|
+
f.profundidade = 30
|
45
|
+
f.peso = 0.3
|
46
|
+
end
|
47
|
+
|
48
|
+
|
49
|
+
=== Atributos de PayPal::FreteFacil::Frete
|
50
|
+
|
51
|
+
==== String
|
52
|
+
cep_origem, cep_destino
|
53
|
+
==== Fixnum
|
54
|
+
largura, altura, profundidade
|
55
|
+
==== Float
|
56
|
+
peso
|
57
|
+
|
58
|
+
== Copyright
|
59
|
+
|
60
|
+
(The MIT License)
|
61
|
+
|
62
|
+
{Prodis a.k.a. Fernando Hamasaki}[http://prodis.blog.br]
|
63
|
+
|
64
|
+
Copyright (c) 2011 Prodis
|
65
|
+
|
66
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
67
|
+
a copy of this software and associated documentation files (the
|
68
|
+
"Software"), to deal in the Software without restriction, including
|
69
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
70
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
71
|
+
permit persons to whom the Software is furnished to do so, subject to
|
72
|
+
the following conditions:
|
73
|
+
|
74
|
+
The above copyright notice and this permission notice shall be
|
75
|
+
included in all copies or substantial portions of the Software.
|
76
|
+
|
77
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
78
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
79
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
80
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
81
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
82
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
83
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
84
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'rubygems'
|
3
|
+
require 'rake'
|
4
|
+
require './lib/paypal/fretefacil/version'
|
5
|
+
|
6
|
+
require 'bundler'
|
7
|
+
begin
|
8
|
+
Bundler.setup(:default, :development)
|
9
|
+
rescue Bundler::BundlerError => e
|
10
|
+
$stderr.puts e.message
|
11
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
12
|
+
exit e.status_code
|
13
|
+
end
|
14
|
+
|
15
|
+
require 'jeweler'
|
16
|
+
Jeweler::Tasks.new do |gem|
|
17
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
18
|
+
gem.name = "paypal-frete-facil"
|
19
|
+
gem.homepage = "http://github.com/prodis/paypal-frete-facil"
|
20
|
+
gem.license = "MIT"
|
21
|
+
gem.summary = %Q{Cálculo de frete do Frete Fácil do PayPal.}
|
22
|
+
gem.description = %Q{Cálculo de frete utilizando o Web Service do Frete Fácil do PayPal.}
|
23
|
+
gem.email = "prodis@gmail.com"
|
24
|
+
gem.authors = ["Prodis a.k.a. Fernando Hamasaki"]
|
25
|
+
gem.version = PayPal::FreteFacil::Version::VERSION
|
26
|
+
gem.required_ruby_version = ">= 1.9"
|
27
|
+
# dependencies defined in Gemfile
|
28
|
+
end
|
29
|
+
Jeweler::RubygemsDotOrgTasks.new
|
30
|
+
|
31
|
+
require 'rspec/core'
|
32
|
+
require 'rspec/core/rake_task'
|
33
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
34
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
35
|
+
end
|
36
|
+
|
37
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
38
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
39
|
+
spec.rcov = true
|
40
|
+
end
|
41
|
+
|
42
|
+
task :default => :spec
|
43
|
+
|
44
|
+
require 'rake/rdoctask'
|
45
|
+
Rake::RDocTask.new do |rdoc|
|
46
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
47
|
+
|
48
|
+
rdoc.rdoc_dir = 'rdoc'
|
49
|
+
rdoc.title = "paypal-frete-facil #{version}"
|
50
|
+
rdoc.rdoc_files.include('README*')
|
51
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
52
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
module PayPal
|
3
|
+
module FreteFacil
|
4
|
+
class Frete
|
5
|
+
attr_accessor :cep_origem, :cep_destino
|
6
|
+
attr_accessor :largura, :altura, :profundidade
|
7
|
+
attr_accessor :peso
|
8
|
+
|
9
|
+
DEFAULT_OPTIONS = {
|
10
|
+
:largura => 0,
|
11
|
+
:altura => 0,
|
12
|
+
:profundidade => 0,
|
13
|
+
:peso => 0.0
|
14
|
+
}
|
15
|
+
|
16
|
+
def initialize(options = {})
|
17
|
+
DEFAULT_OPTIONS.merge(options).each do |attr, value|
|
18
|
+
self.send("#{attr}=", value)
|
19
|
+
end
|
20
|
+
|
21
|
+
yield self if block_given?
|
22
|
+
end
|
23
|
+
|
24
|
+
def web_service
|
25
|
+
@web_service ||= PayPal::FreteFacil::WebService.new
|
26
|
+
end
|
27
|
+
|
28
|
+
def parser
|
29
|
+
@parser ||= PayPal::FreteFacil::Parser.new
|
30
|
+
end
|
31
|
+
|
32
|
+
def calcular
|
33
|
+
response = web_service.request(self)
|
34
|
+
parser.parse(response)
|
35
|
+
end
|
36
|
+
|
37
|
+
alias calculate calcular
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'net/http'
|
3
|
+
require 'uri'
|
4
|
+
|
5
|
+
module PayPal
|
6
|
+
module FreteFacil
|
7
|
+
class WebService
|
8
|
+
URL = "https://ff.paypal-brasil.com.br/FretesPayPalWS/WSFretesPayPal"
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
@uri = URI.parse(URL)
|
12
|
+
end
|
13
|
+
|
14
|
+
def request(frete)
|
15
|
+
http = Net::HTTP.new(@uri.host, @uri.port)
|
16
|
+
http.use_ssl = true
|
17
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
18
|
+
|
19
|
+
request = Net::HTTP::Post.new(@uri.path)
|
20
|
+
request["Content-Type"] = "text/xml"
|
21
|
+
request["SoapAction"] = "#{URL}/getPreco"
|
22
|
+
request.body = request_body_for(frete)
|
23
|
+
|
24
|
+
response = http.request(request)
|
25
|
+
response.body
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def request_body_for(frete)
|
31
|
+
"<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:frete=\"https://ff.paypal-brasil.com.br/FretesPayPalWS\">" +
|
32
|
+
"<soapenv:Header />" +
|
33
|
+
"<soapenv:Body>" +
|
34
|
+
"<frete:getPreco>" +
|
35
|
+
"<cepOrigem>#{frete.cep_origem}</cepOrigem>" +
|
36
|
+
"<cepDestino>#{frete.cep_destino}</cepDestino>" +
|
37
|
+
"<largura>#{frete.largura}</largura>" +
|
38
|
+
"<altura>#{frete.altura}</altura>" +
|
39
|
+
"<profundidade>#{frete.profundidade}</profundidade>" +
|
40
|
+
"<peso>#{frete.peso}</peso>" +
|
41
|
+
"</frete:getPreco>" +
|
42
|
+
"</soapenv:Body>" +
|
43
|
+
"</soapenv:Envelope>"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{paypal-frete-facil}
|
8
|
+
s.version = "0.0.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Prodis a.k.a. Fernando Hamasaki"]
|
12
|
+
s.date = %q{2011-08-22}
|
13
|
+
s.description = %q{Cálculo de frete utilizando o Web Service do Frete Fácil do PayPal.}
|
14
|
+
s.email = %q{prodis@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"README.rdoc"
|
17
|
+
]
|
18
|
+
s.files = [
|
19
|
+
".document",
|
20
|
+
".rspec",
|
21
|
+
"Gemfile",
|
22
|
+
"Gemfile.lock",
|
23
|
+
"README.rdoc",
|
24
|
+
"Rakefile",
|
25
|
+
"lib/paypal-frete-facil.rb",
|
26
|
+
"lib/paypal/fretefacil/frete.rb",
|
27
|
+
"lib/paypal/fretefacil/parser.rb",
|
28
|
+
"lib/paypal/fretefacil/version.rb",
|
29
|
+
"lib/paypal/fretefacil/web_service.rb",
|
30
|
+
"paypal-frete-facil.gemspec",
|
31
|
+
"spec/paypal-frete-facil_spec.rb",
|
32
|
+
"spec/spec_helper.rb"
|
33
|
+
]
|
34
|
+
s.homepage = %q{http://github.com/prodis/paypal-frete-facil}
|
35
|
+
s.licenses = ["MIT"]
|
36
|
+
s.require_paths = ["lib"]
|
37
|
+
s.required_ruby_version = Gem::Requirement.new(">= 1.9")
|
38
|
+
s.rubygems_version = %q{1.6.1}
|
39
|
+
s.summary = %q{Cálculo de frete do Frete Fácil do PayPal.}
|
40
|
+
|
41
|
+
if s.respond_to? :specification_version then
|
42
|
+
s.specification_version = 3
|
43
|
+
|
44
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
45
|
+
s.add_runtime_dependency(%q<nokogiri>, [">= 0"])
|
46
|
+
s.add_development_dependency(%q<rspec>, [">= 0"])
|
47
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
48
|
+
s.add_development_dependency(%q<jeweler>, [">= 0"])
|
49
|
+
else
|
50
|
+
s.add_dependency(%q<nokogiri>, [">= 0"])
|
51
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
52
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
53
|
+
s.add_dependency(%q<jeweler>, [">= 0"])
|
54
|
+
end
|
55
|
+
else
|
56
|
+
s.add_dependency(%q<nokogiri>, [">= 0"])
|
57
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
58
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
59
|
+
s.add_dependency(%q<jeweler>, [">= 0"])
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rspec'
|
4
|
+
require 'paypal-frete-facil'
|
5
|
+
|
6
|
+
# Requires supporting files with custom matchers and macros, etc,
|
7
|
+
# in ./support/ and its subdirectories.
|
8
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
|
12
|
+
end
|
metadata
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: paypal-frete-facil
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.1
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Prodis a.k.a. Fernando Hamasaki
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-08-22 00:00:00 -03:00
|
14
|
+
default_executable:
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: nokogiri
|
18
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
type: :runtime
|
25
|
+
prerelease: false
|
26
|
+
version_requirements: *id001
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
30
|
+
none: false
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: "0"
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: *id002
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
|
+
name: bundler
|
40
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 1.0.0
|
46
|
+
type: :development
|
47
|
+
prerelease: false
|
48
|
+
version_requirements: *id003
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: jeweler
|
51
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: "0"
|
57
|
+
type: :development
|
58
|
+
prerelease: false
|
59
|
+
version_requirements: *id004
|
60
|
+
description: "C\xC3\xA1lculo de frete utilizando o Web Service do Frete F\xC3\xA1cil do PayPal."
|
61
|
+
email: prodis@gmail.com
|
62
|
+
executables: []
|
63
|
+
|
64
|
+
extensions: []
|
65
|
+
|
66
|
+
extra_rdoc_files:
|
67
|
+
- README.rdoc
|
68
|
+
files:
|
69
|
+
- .document
|
70
|
+
- .rspec
|
71
|
+
- Gemfile
|
72
|
+
- Gemfile.lock
|
73
|
+
- README.rdoc
|
74
|
+
- Rakefile
|
75
|
+
- lib/paypal-frete-facil.rb
|
76
|
+
- lib/paypal/fretefacil/frete.rb
|
77
|
+
- lib/paypal/fretefacil/parser.rb
|
78
|
+
- lib/paypal/fretefacil/version.rb
|
79
|
+
- lib/paypal/fretefacil/web_service.rb
|
80
|
+
- paypal-frete-facil.gemspec
|
81
|
+
- spec/paypal-frete-facil_spec.rb
|
82
|
+
- spec/spec_helper.rb
|
83
|
+
has_rdoc: true
|
84
|
+
homepage: http://github.com/prodis/paypal-frete-facil
|
85
|
+
licenses:
|
86
|
+
- MIT
|
87
|
+
post_install_message:
|
88
|
+
rdoc_options: []
|
89
|
+
|
90
|
+
require_paths:
|
91
|
+
- lib
|
92
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
93
|
+
none: false
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: "1.9"
|
98
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
|
+
none: false
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: "0"
|
104
|
+
requirements: []
|
105
|
+
|
106
|
+
rubyforge_project:
|
107
|
+
rubygems_version: 1.6.1
|
108
|
+
signing_key:
|
109
|
+
specification_version: 3
|
110
|
+
summary: "C\xC3\xA1lculo de frete do Frete F\xC3\xA1cil do PayPal."
|
111
|
+
test_files: []
|
112
|
+
|