xero_gateway-float 2.0.18 → 2.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. data/Rakefile +7 -1
  2. data/examples/partner_app.rb +2 -2
  3. data/lib/xero_gateway/accounts_list.rb +0 -4
  4. data/lib/xero_gateway/bank_transaction.rb +0 -2
  5. data/lib/xero_gateway/contact.rb +6 -9
  6. data/lib/xero_gateway/credit_note.rb +1 -3
  7. data/lib/xero_gateway/error.rb +16 -0
  8. data/lib/xero_gateway/exceptions.rb +5 -0
  9. data/lib/xero_gateway/gateway.rb +184 -82
  10. data/lib/xero_gateway/http.rb +38 -32
  11. data/lib/xero_gateway/invoice.rb +17 -9
  12. data/lib/xero_gateway/journal_line.rb +102 -0
  13. data/lib/xero_gateway/line_item_calculations.rb +0 -4
  14. data/lib/xero_gateway/manual_journal.rb +163 -0
  15. data/lib/xero_gateway/oauth.rb +29 -23
  16. data/lib/xero_gateway/partner_app.rb +6 -1
  17. data/lib/xero_gateway/response.rb +2 -0
  18. data/lib/xero_gateway/tax_rate.rb +1 -1
  19. data/lib/xero_gateway.rb +3 -0
  20. data/test/integration/accounts_list_test.rb +4 -4
  21. data/test/integration/create_invoice_test.rb +6 -0
  22. data/test/integration/create_manual_journal_test.rb +35 -0
  23. data/test/integration/create_payments_test.rb +35 -0
  24. data/test/integration/get_invoice_test.rb +27 -12
  25. data/test/integration/get_manual_journal_test.rb +50 -0
  26. data/test/integration/get_manual_journals_test.rb +88 -0
  27. data/test/integration/update_manual_journal_test.rb +31 -0
  28. data/test/test_helper.rb +39 -1
  29. data/test/unit/bank_transaction_test.rb +1 -1
  30. data/test/unit/credit_note_test.rb +1 -1
  31. data/test/unit/gateway_test.rb +15 -15
  32. data/test/unit/invoice_test.rb +3 -2
  33. data/test/unit/manual_journal_test.rb +93 -0
  34. data/test/unit/payment_test.rb +34 -0
  35. data/xero_gateway.gemspec +2 -2
  36. metadata +11 -2
data/Rakefile CHANGED
@@ -1,6 +1,6 @@
1
1
  require 'rake'
2
2
  require 'rake/testtask'
3
- require 'rake/rdoctask'
3
+ require 'rdoc/task'
4
4
 
5
5
  desc 'Default: run unit tests.'
6
6
  task :default => :test
@@ -12,3 +12,9 @@ Rake::TestTask.new(:test) do |t|
12
12
  t.verbose = true
13
13
  end
14
14
 
15
+ desc "Deploy gem"
16
+ task :deploy do
17
+ `rm -rf *.gem`
18
+ `gem build xero_gateway.gemspec`
19
+ `gem push *.gem`
20
+ end
@@ -23,7 +23,7 @@ oauth_verifier = gets.chomp
23
23
 
24
24
  gateway.authorize_from_request(gateway.request_token.token, gateway.request_token.secret, :oauth_verifier => oauth_verifier)
25
25
 
26
- puts "Your access token/secret: #{gateway.access_token.token}, #{gateway.access_token.secret}. Expires: #{gateway.authorization_expires_at}"
26
+ puts "Your access token/secret: #{gateway.access_token.token}, #{gateway.access_token.secret}. Expires: #{gateway.expires_at}"
27
27
  puts "(Good for 30 Minutes - but we can renew it!)"
28
28
 
29
29
  puts "Session Handle: #{gateway.session_handle}"
@@ -33,4 +33,4 @@ pp gateway.get_contacts.contacts.map(&:name)
33
33
 
34
34
  # Renew!
35
35
  gateway.renew_access_token(gateway.access_token.token, gateway.access_token.secret, gateway.session_handle)
36
- puts "Your renewed access token/secret is: #{gateway.access_token.token}, #{gateway.access_token.secret}. Expires: #{gateway.authorization_expires_at}"
36
+ puts "Your renewed access token/secret is: #{gateway.access_token.token}, #{gateway.access_token.secret}. Expires: #{gateway.expires_at}"
@@ -1,10 +1,6 @@
1
1
  module XeroGateway
2
2
  class AccountsList
3
3
 
4
- class Error < RuntimeError; end
5
- class NoGatewayError < Error; end
6
- class AccountsListNotLoadedError < Error; end
7
-
8
4
  # Xero::Gateway associated with this invoice.
9
5
  attr_accessor :gateway
10
6
 
@@ -3,8 +3,6 @@ module XeroGateway
3
3
  include Dates
4
4
  include LineItemCalculations
5
5
 
6
- class NoGatewayError < Error; end
7
-
8
6
  GUID_REGEX = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/ unless defined?(GUID_REGEX)
9
7
 
10
8
  TYPES = {
@@ -1,10 +1,7 @@
1
1
  module XeroGateway
2
2
  class Contact
3
3
  include Dates
4
-
5
- class Error < RuntimeError; end
6
- class NoGatewayError < Error; end
7
-
4
+
8
5
  GUID_REGEX = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/ unless defined?(GUID_REGEX)
9
6
 
10
7
  CONTACT_STATUS = {
@@ -126,14 +123,14 @@ module XeroGateway
126
123
  end
127
124
 
128
125
  # Creates this contact record (using gateway.create_contact) with the associated gateway.
129
- # If no gateway set, raise a Xero::Contact::NoGatewayError exception.
126
+ # If no gateway set, raise a NoGatewayError exception.
130
127
  def create
131
128
  raise NoGatewayError unless gateway
132
129
  gateway.create_contact(self)
133
130
  end
134
131
 
135
132
  # Creates this contact record (using gateway.update_contact) with the associated gateway.
136
- # If no gateway set, raise a Xero::Contact::NoGatewayError exception.
133
+ # If no gateway set, raise a NoGatewayError exception.
137
134
  def update
138
135
  raise NoGatewayError unless gateway
139
136
  gateway.update_contact(self)
@@ -143,7 +140,7 @@ module XeroGateway
143
140
  b.Contact {
144
141
  b.ContactID self.contact_id if self.contact_id
145
142
  b.ContactNumber self.contact_number if self.contact_number
146
- b.Name self.name
143
+ b.Name self.name if self.name
147
144
  b.EmailAddress self.email if self.email
148
145
  b.FirstName self.first_name if self.first_name
149
146
  b.LastName self.last_name if self.last_name
@@ -157,10 +154,10 @@ module XeroGateway
157
154
  b.DefaultCurrency if self.default_currency
158
155
  b.Addresses {
159
156
  addresses.each { |address| address.to_xml(b) }
160
- }
157
+ } if self.addresses.any?
161
158
  b.Phones {
162
159
  phones.each { |phone| phone.to_xml(b) }
163
- }
160
+ } if self.phones.any?
164
161
  }
165
162
  end
166
163
 
@@ -4,8 +4,6 @@ module XeroGateway
4
4
  include Money
5
5
  include LineItemCalculations
6
6
 
7
- class NoGatewayError < Error; end
8
-
9
7
  CREDIT_NOTE_TYPE = {
10
8
  'ACCRECCREDIT' => 'Accounts Receivable',
11
9
  'ACCPAYCREDIT' => 'Accounts Payable'
@@ -163,7 +161,7 @@ module XeroGateway
163
161
  end
164
162
 
165
163
  # Creates this credit_note record (using gateway.create_credit_note) with the associated gateway.
166
- # If no gateway set, raise a Xero::CreditNote::NoGatewayError exception.
164
+ # If no gateway set, raise a NoGatewayError exception.
167
165
  def create
168
166
  raise NoGatewayError unless gateway
169
167
  gateway.create_credit_note(self)
@@ -14,5 +14,21 @@ module XeroGateway
14
14
  end
15
15
  return true
16
16
  end
17
+
18
+ # pass a REXML::Element error object to
19
+ # have returned a new Error object
20
+ def self.parse(error_element)
21
+ description = REXML::XPath.first(error_element, "Description")
22
+ date = REXML::XPath.first(error_element, "//DateTime")
23
+ type = REXML::XPath.first(error_element, "//ExceptionType")
24
+ message = REXML::XPath.first(error_element, "//Message")
25
+ Error.new(
26
+ :description => (description.text if description),
27
+ :date_time => (date.text if date),
28
+ :type => (type.text if type),
29
+ :message => (message.text if message)
30
+ )
31
+ end
32
+
17
33
  end
18
34
  end
@@ -1,4 +1,8 @@
1
1
  module XeroGateway
2
+ class NoGatewayError < StandardError; end
3
+ class AccountsListNotLoadedError < StandardError; end
4
+ class InvalidLineItemError < StandardError; end
5
+
2
6
  class ApiException < StandardError
3
7
 
4
8
  def initialize(type, message, request_xml, response_xml)
@@ -43,4 +47,5 @@ module XeroGateway
43
47
  class InvoiceNotFoundError < StandardError; end
44
48
  class BankTransactionNotFoundError < StandardError; end
45
49
  class CreditNoteNotFoundError < StandardError; end
50
+ class ManualJournalNotFoundError < StandardError; end
46
51
  end