xero_gateway-float 2.0.16 → 2.0.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7,34 +7,63 @@ module XeroGateway
7
7
  attr_reader :errors
8
8
 
9
9
  # All accessible fields
10
- attr_accessor :date, :amount
11
-
10
+ attr_accessor :invoice_id, :invoice_number, :account_id, :code, :payment_id, :date, :amount, :reference, :currency_rate
11
+
12
12
  def initialize(params = {})
13
13
  @errors ||= []
14
-
14
+
15
15
  params.each do |k,v|
16
16
  self.send("#{k}=", v)
17
17
  end
18
18
  end
19
-
19
+
20
20
  def self.from_xml(payment_element)
21
21
  payment = Payment.new
22
22
  payment_element.children.each do | element |
23
23
  case element.name
24
- when 'Date' then payment.date = parse_date_time(element.text)
25
- when 'Amount' then payment.amount = BigDecimal.new(element.text)
26
- end
24
+ when 'PaymentID' then payment.payment_id = element.text
25
+ when 'Date' then payment.date = parse_date_time(element.text)
26
+ when 'Amount' then payment.amount = BigDecimal.new(element.text)
27
+ when 'Reference' then payment.reference = element.text
28
+ when 'CurrencyRate' then payment.currency_rate = BigDecimal.new(element.text)
29
+ when 'Invoice' then payment.send("#{element.children.first.name.underscore}=", element.children.first.text)
30
+ when 'Account' then payment.send("#{element.children.first.name.underscore}=", element.children.first.text)
31
+ end
27
32
  end
28
33
  payment
29
- end
30
-
34
+ end
35
+
31
36
  def ==(other)
32
- [:date, :amount].each do |field|
37
+ [:payment_id, :date, :amount].each do |field|
33
38
  return false if send(field) != other.send(field)
34
39
  end
35
40
  return true
36
41
  end
37
-
42
+
43
+ def to_xml(b = Builder::XmlMarkup.new)
44
+ b.Payment do
45
+
46
+ if self.invoice_id || self.invoice_number
47
+ b.Invoice do |i|
48
+ i.InvoiceID self.invoice_id if self.invoice_id
49
+ i.InvoiceNumber self.invoice_number if self.invoice_number
50
+ end
51
+ end
52
+
53
+ if self.account_id || self.code
54
+ b.Account do |a|
55
+ a.AccountID self.account_id if self.account_id
56
+ a.Code self.code if self.code
57
+ end
58
+ end
59
+
60
+ b.Amount self.amount if self.amount
61
+ b.CurrencyRate self.currency_rate if self.currency_rate
62
+ b.Reference self.reference if self.reference
63
+
64
+ b.Date self.class.format_date(self.date || Date.today)
65
+ end
66
+ end
38
67
 
39
68
  end
40
- end
69
+ end
data/xero_gateway.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "xero_gateway-float"
3
- s.version = "2.0.16"
4
- s.date = "2012-11-02"
3
+ s.version = "2.0.17"
4
+ s.date = "2012-12-18"
5
5
  s.summary = "Enables ruby based applications to communicate with the Xero API"
6
6
  s.email = "tim@connorsoftware.com"
7
7
  s.homepage = "http://github.com/latentflip/xero_gateway"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xero_gateway-float
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.16
4
+ version: 2.0.17
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2012-11-02 00:00:00.000000000 Z
14
+ date: 2012-12-18 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: builder