pagseguro_catcher 0.0.4 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.4
1
+ 0.1.0
@@ -48,4 +48,10 @@ module PagseguroCatcher
48
48
  501 => "Oi Paggo"
49
49
  }
50
50
 
51
+ SHIPPING_TYPES = {
52
+ 1 => "Encomenda normal (PAC)",
53
+ 2 => "SEDEX",
54
+ 3 => "Tipo de frete não especificado"
55
+ }
56
+
51
57
  end
@@ -19,6 +19,11 @@ module PagseguroCatcher
19
19
  @sender
20
20
  end
21
21
 
22
+ def shipping
23
+ @shipping ||= PagseguroCatcher::Transaction::Shipping.new(self.body)
24
+ @shipping
25
+ end
26
+
22
27
  def items
23
28
  @items = []
24
29
 
@@ -32,7 +37,7 @@ module PagseguroCatcher
32
37
  def each_item
33
38
  self.items.each { |item| yield item }
34
39
  end
35
-
40
+
36
41
  def date
37
42
  self[:date].to_datetime.change(:offset => "-0300")
38
43
  end
@@ -56,9 +61,7 @@ module PagseguroCatcher
56
61
  def payment_method_code
57
62
  PAYMENT_CODES[self[:paymentMethod][:code].to_i]
58
63
  end
59
-
60
- #TODO - items, shipping
61
-
64
+
62
65
  end
63
66
 
64
67
  end
@@ -7,6 +7,10 @@ module PagseguroCatcher
7
7
  self.body = body
8
8
  end
9
9
 
10
+ def id
11
+ self[:id].to_i
12
+ end
13
+
10
14
  def amount
11
15
  self[:amount].to_f
12
16
  end
@@ -0,0 +1,30 @@
1
+ module PagseguroCatcher
2
+ module Transaction
3
+
4
+ class Shipping < Transaction::Body
5
+
6
+ def initialize(body)
7
+ self.body = body[:shipping]
8
+ end
9
+
10
+ def zip
11
+ self[:address][:postalCode]
12
+ end
13
+
14
+ def human_type
15
+ SHIPPING_TYPES[self[:type].to_i]
16
+ end
17
+
18
+ def cost
19
+ self[:cost].to_f
20
+ end
21
+
22
+ def method_missing(name, *args)
23
+ return self[:address][name] if self.body[:address].has_key?(name.to_sym)
24
+ super
25
+ end
26
+
27
+ end
28
+
29
+ end
30
+ end
@@ -19,5 +19,6 @@ module PagseguroCatcher
19
19
  autoload :Amount, 'pagseguro_catcher/transaction/amount'
20
20
  autoload :Sender, 'pagseguro_catcher/transaction/sender'
21
21
  autoload :Item, 'pagseguro_catcher/transaction/item'
22
+ autoload :Shipping, 'pagseguro_catcher/transaction/shipping'
22
23
  end
23
24
  end
@@ -21,6 +21,4 @@ module PagseguroCatcher
21
21
  end
22
22
  end
23
23
 
24
-
25
-
26
24
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{pagseguro_catcher}
8
- s.version = "0.0.4"
8
+ s.version = "0.1.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Matias H. Leidemer"]
12
- s.date = %q{2011-10-15}
12
+ s.date = %q{2011-10-23}
13
13
  s.description = %q{This gem provides a simple way to check and parse the PagSeguro transaction notification.}
14
14
  s.email = %q{matiasleidemer@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -36,6 +36,7 @@ Gem::Specification.new do |s|
36
36
  "lib/pagseguro_catcher/transaction/base.rb",
37
37
  "lib/pagseguro_catcher/transaction/item.rb",
38
38
  "lib/pagseguro_catcher/transaction/sender.rb",
39
+ "lib/pagseguro_catcher/transaction/shipping.rb",
39
40
  "pagseguro_catcher.gemspec",
40
41
  "spec/checker_spec.rb",
41
42
  "spec/pagseguro_catcher_spec.rb",
@@ -44,7 +45,8 @@ Gem::Specification.new do |s|
44
45
  "spec/transaction/amount_spec.rb",
45
46
  "spec/transaction/base_spec.rb",
46
47
  "spec/transaction/item_spec.rb",
47
- "spec/transaction/sender_spec.rb"
48
+ "spec/transaction/sender_spec.rb",
49
+ "spec/transaction/shipping_spec.rb"
48
50
  ]
49
51
  s.homepage = %q{http://github.com/matiasleidemer/pagseguro_catcher}
50
52
  s.licenses = ["MIT"]
@@ -41,7 +41,7 @@
41
41
  </sender>
42
42
  <shipping>
43
43
  <address>
44
- <street>Av. Brig. Faria Lima</street>
44
+ <street>Av. Brig. Faria Lima</street>
45
45
  <number>1384</number>
46
46
  <complement>5o andar</complement>
47
47
  <district>Jardim Paulistano</district>
@@ -46,6 +46,12 @@ describe "Transaction" do
46
46
  end
47
47
  end
48
48
 
49
+ describe "#shipping" do
50
+ it "returns a Shipping object" do
51
+ transaction.shipping.should be_a(PagseguroCatcher::Transaction::Shipping)
52
+ end
53
+ end
54
+
49
55
  describe "#date" do
50
56
  it "returns the date response as a DateTime object" do
51
57
  transaction.body[:date] = "2011-02-10T16:13:41.000-03:00"
@@ -18,4 +18,9 @@ describe "Item" do
18
18
  end
19
19
  end
20
20
 
21
+ describe "#id" do
22
+ it "returns the item id as integer" do
23
+ item.id.should == 1
24
+ end
25
+ end
21
26
  end
@@ -0,0 +1,75 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe "Shipping" do
4
+
5
+ let(:xml) { File.open(File.expand_path(File.dirname(__FILE__) + '/../support/return.xml')).read }
6
+ let(:transaction) { PagseguroCatcher::Transaction::Base.new(xml) }
7
+ let(:shipping) { PagseguroCatcher::Transaction::Shipping.new(transaction.body) }
8
+
9
+ describe ".initialize" do
10
+ it "assigns the body" do
11
+ shipping.body.should be_a(Hash)
12
+ end
13
+ end
14
+
15
+ describe "#zip" do
16
+ it "return the zip code" do
17
+ shipping.zip.should == "01452002"
18
+ end
19
+ end
20
+
21
+ describe "#street" do
22
+ it "returns the street name" do
23
+ shipping.street.should == "Av. Brig. Faria Lima"
24
+ end
25
+ end
26
+
27
+ describe "#number" do
28
+ it "returns the street number" do
29
+ shipping.number.should == "1384"
30
+ end
31
+ end
32
+
33
+ describe "#complement" do
34
+ it "returns the address complement" do
35
+ shipping.complement.should == "5o andar"
36
+ end
37
+ end
38
+
39
+ describe "#district" do
40
+ it "returns the district" do
41
+ shipping.district.should == "Jardim Paulistano"
42
+ end
43
+ end
44
+
45
+ describe "#city" do
46
+ it "returns the city" do
47
+ shipping.city.should == "Sao Paulo"
48
+ end
49
+ end
50
+
51
+ describe "#state" do
52
+ it "returns the state" do
53
+ shipping.state.should == "SP"
54
+ end
55
+ end
56
+
57
+ describe "#country" do
58
+ it "returns the country code" do
59
+ shipping.country.should == "BRA"
60
+ end
61
+ end
62
+
63
+ describe "#human_type" do
64
+ it "returns the human value for type" do
65
+ shipping.human_type.should == "Encomenda normal (PAC)"
66
+ end
67
+ end
68
+
69
+ describe "#cost" do
70
+ it "returns the cost as float" do
71
+ shipping.cost.should == 21.50
72
+ end
73
+ end
74
+
75
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pagseguro_catcher
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 27
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
+ - 1
8
9
  - 0
9
- - 4
10
- version: 0.0.4
10
+ version: 0.1.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Matias H. Leidemer
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-10-15 00:00:00 -03:00
18
+ date: 2011-10-23 00:00:00 -02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -165,6 +165,7 @@ files:
165
165
  - lib/pagseguro_catcher/transaction/base.rb
166
166
  - lib/pagseguro_catcher/transaction/item.rb
167
167
  - lib/pagseguro_catcher/transaction/sender.rb
168
+ - lib/pagseguro_catcher/transaction/shipping.rb
168
169
  - pagseguro_catcher.gemspec
169
170
  - spec/checker_spec.rb
170
171
  - spec/pagseguro_catcher_spec.rb
@@ -174,6 +175,7 @@ files:
174
175
  - spec/transaction/base_spec.rb
175
176
  - spec/transaction/item_spec.rb
176
177
  - spec/transaction/sender_spec.rb
178
+ - spec/transaction/shipping_spec.rb
177
179
  has_rdoc: true
178
180
  homepage: http://github.com/matiasleidemer/pagseguro_catcher
179
181
  licenses: