tlconnor-xero_gateway 1.0.2 → 1.0.3

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.
Files changed (42) hide show
  1. data/CHANGELOG.textile +8 -2
  2. data/lib/xero_gateway/account.rb +27 -0
  3. data/lib/xero_gateway/contact.rb +88 -0
  4. data/lib/xero_gateway/error.rb +19 -0
  5. data/lib/xero_gateway/gateway.rb +54 -157
  6. data/lib/xero_gateway/invoice.rb +116 -0
  7. data/lib/xero_gateway/response.rb +1 -0
  8. data/lib/xero_gateway/tracking_category.rb +26 -0
  9. data/lib/xero_gateway.rb +1 -4
  10. data/test/integration/create_contact_test.rb +3 -1
  11. data/test/integration/create_invoice_test.rb +3 -1
  12. data/test/integration/get_accounts_test.rb +3 -2
  13. data/test/integration/get_contact_test.rb +3 -1
  14. data/test/integration/get_contacts_test.rb +3 -1
  15. data/test/integration/get_invoice_test.rb +5 -1
  16. data/test/integration/get_invoices_test.rb +5 -1
  17. data/test/integration/get_tracking_categories_test.rb +4 -1
  18. data/test/integration/update_contact_test.rb +3 -1
  19. data/test/stub_responses/accounts.xml +1 -0
  20. data/test/{integration/stub_responses → stub_responses}/contact.xml +0 -0
  21. data/test/{integration/stub_responses → stub_responses}/contacts.xml +0 -0
  22. data/test/stub_responses/invalid_api_key_error.xml +1 -0
  23. data/test/stub_responses/invalid_customer_key_error.xml +1 -0
  24. data/test/{integration/stub_responses → stub_responses}/invoice.xml +0 -0
  25. data/test/stub_responses/invoice_not_found_error.xml +1 -0
  26. data/test/{integration/stub_responses → stub_responses}/invoices.xml +0 -0
  27. data/test/{integration/stub_responses → stub_responses}/tracking_categories.xml +0 -0
  28. data/test/stub_responses/unknown_error.xml +1 -0
  29. data/test/test_helper.rb +65 -1
  30. data/test/unit/{messages/account_message_test.rb → account_test.rb} +4 -4
  31. data/test/unit/{messages/contact_message_test.rb → contact_test.rb} +6 -6
  32. data/test/unit/gateway_test.rb +66 -0
  33. data/test/unit/{messages/invoice_message_test.rb → invoice_test.rb} +6 -6
  34. data/test/unit/{messages/tracking_category_message_test.rb → tracking_category_test.rb} +4 -4
  35. data/xero_gateway.gemspec +18 -17
  36. metadata +18 -17
  37. data/lib/xero_gateway/messages/account_message.rb +0 -33
  38. data/lib/xero_gateway/messages/contact_message.rb +0 -93
  39. data/lib/xero_gateway/messages/invoice_message.rb +0 -122
  40. data/lib/xero_gateway/messages/tracking_category_message.rb +0 -32
  41. data/test/integration/integration_test_methods.rb +0 -64
  42. data/test/integration/stub_responses/accounts.xml +0 -1
@@ -1,12 +1,12 @@
1
1
  require File.dirname(__FILE__) + '/../test_helper'
2
2
 
3
3
  class GetAccountsTest < Test::Unit::TestCase
4
- include IntegrationTestMethods
4
+ include TestHelper
5
5
 
6
6
  def setup
7
7
  @gateway = XeroGateway::Gateway.new(
8
8
  :customer_key => CUSTOMER_KEY,
9
- :api_key => API_KEY
9
+ :api_key => API_KEY
10
10
  )
11
11
 
12
12
  if STUB_XERO_CALLS
@@ -19,6 +19,7 @@ class GetAccountsTest < Test::Unit::TestCase
19
19
  def test_get_accounts
20
20
  result = @gateway.get_accounts
21
21
  assert result.success?
22
+ assert !result.response_xml.nil?
22
23
  assert result.accounts.size > 0
23
24
  assert_equal XeroGateway::Account, result.accounts.first.class
24
25
  end
@@ -1,7 +1,7 @@
1
1
  require File.dirname(__FILE__) + '/../test_helper'
2
2
 
3
3
  class GetContactTest < Test::Unit::TestCase
4
- include IntegrationTestMethods
4
+ include TestHelper
5
5
 
6
6
  def setup
7
7
  @gateway = XeroGateway::Gateway.new(
@@ -24,6 +24,8 @@ class GetContactTest < Test::Unit::TestCase
24
24
 
25
25
  result = @gateway.get_contact_by_id(contact.contact_id)
26
26
  assert result.success?
27
+ assert !result.request_params.nil?
28
+ assert !result.response_xml.nil?
27
29
  assert_equal result.contact.name, contact.name
28
30
  end
29
31
  end
@@ -1,7 +1,7 @@
1
1
  require File.dirname(__FILE__) + '/../test_helper'
2
2
 
3
3
  class GetContactsTest < Test::Unit::TestCase
4
- include IntegrationTestMethods
4
+ include TestHelper
5
5
 
6
6
  def setup
7
7
  @gateway = XeroGateway::Gateway.new(
@@ -24,6 +24,8 @@ class GetContactsTest < Test::Unit::TestCase
24
24
 
25
25
  result = @gateway.get_contacts
26
26
  assert result.success?
27
+ assert !result.request_params.nil?
28
+ assert !result.response_xml.nil?
27
29
  assert result.contacts.collect {|c| c.contact_id}.include?(contact.contact_id)
28
30
  end
29
31
  end
@@ -1,7 +1,7 @@
1
1
  require File.dirname(__FILE__) + '/../test_helper'
2
2
 
3
3
  class GetInvoiceTest < Test::Unit::TestCase
4
- include IntegrationTestMethods
4
+ include TestHelper
5
5
 
6
6
  def setup
7
7
  @gateway = XeroGateway::Gateway.new(
@@ -23,10 +23,14 @@ class GetInvoiceTest < Test::Unit::TestCase
23
23
 
24
24
  result = @gateway.get_invoice_by_id(invoice.invoice_id)
25
25
  assert result.success?
26
+ assert !result.request_params.nil?
27
+ assert !result.response_xml.nil?
26
28
  assert_equal result.invoice.invoice_number, invoice.invoice_number
27
29
 
28
30
  result = @gateway.get_invoice_by_number(invoice.invoice_number)
29
31
  assert result.success?
32
+ assert !result.request_params.nil?
33
+ assert !result.response_xml.nil?
30
34
  assert_equal result.invoice.invoice_id, invoice.invoice_id
31
35
  end
32
36
  end
@@ -1,7 +1,7 @@
1
1
  require File.dirname(__FILE__) + '/../test_helper'
2
2
 
3
3
  class GetInvoicesTest < Test::Unit::TestCase
4
- include IntegrationTestMethods
4
+ include TestHelper
5
5
 
6
6
  def setup
7
7
  @gateway = XeroGateway::Gateway.new(
@@ -23,6 +23,8 @@ class GetInvoicesTest < Test::Unit::TestCase
23
23
 
24
24
  result = @gateway.get_invoices
25
25
  assert result.success?
26
+ assert !result.request_params.nil?
27
+ assert !result.response_xml.nil?
26
28
  assert result.invoices.collect {|i| i.invoice_number}.include?(invoice.invoice_number)
27
29
  end
28
30
 
@@ -34,6 +36,8 @@ class GetInvoicesTest < Test::Unit::TestCase
34
36
  # Check that it is returned
35
37
  result = @gateway.get_invoices(Date.today - 1)
36
38
  assert result.success?
39
+ assert !result.request_params.nil?
40
+ assert !result.response_xml.nil?
37
41
  assert result.request_params.keys.include?(:modifiedSince) # make sure the flag was sent
38
42
  assert result.invoices.collect {|response_invoice| response_invoice.invoice_number}.include?(invoice.invoice_number)
39
43
  end
@@ -1,7 +1,7 @@
1
1
  require File.dirname(__FILE__) + '/../test_helper'
2
2
 
3
3
  class GetTrackingCategoriesTest < Test::Unit::TestCase
4
- include IntegrationTestMethods
4
+ include TestHelper
5
5
 
6
6
  def setup
7
7
  @gateway = XeroGateway::Gateway.new(:customer_key => CUSTOMER_KEY, :api_key => API_KEY)
@@ -16,7 +16,10 @@ class GetTrackingCategoriesTest < Test::Unit::TestCase
16
16
  def test_get_tracking_categories
17
17
  result = @gateway.get_tracking_categories
18
18
  assert result.success?
19
+ assert !result.response_xml.nil?
19
20
  if STUB_XERO_CALLS
21
+ # When operating against the Xero test environment, there may not be any tracking categories present,
22
+ # so this assertion can only be done when operating against stub responses
20
23
  assert result.tracking_categories.size == 2
21
24
  end
22
25
  end
@@ -1,7 +1,7 @@
1
1
  require File.dirname(__FILE__) + '/../test_helper'
2
2
 
3
3
  class UpdateContactTest < Test::Unit::TestCase
4
- include IntegrationTestMethods
4
+ include TestHelper
5
5
 
6
6
  def setup
7
7
  @gateway = XeroGateway::Gateway.new(
@@ -26,6 +26,8 @@ class UpdateContactTest < Test::Unit::TestCase
26
26
  result = @gateway.update_contact(contact)
27
27
 
28
28
  assert result.success?
29
+ assert !result.request_xml.nil?
30
+ assert !result.response_xml.nil?
29
31
  assert_equal contact.contact_id, result.contact.contact_id
30
32
  assert_equal "123 4567", result.contact.phone.number if !STUB_XERO_CALLS
31
33
  end
@@ -0,0 +1 @@
1
+ <?xml version="1.0"?><Response xmlns:i="http://www.w3.org/2001/XMLSchema-instance"><ID>cf37ba46-29a7-4824-ad63-43482463afed</ID><Status>OK</Status><ProviderName>YOUR PROVIDER</ProviderName><DateTimeUTC>2008-12-01T08:39:54.70175Z</DateTimeUTC><Accounts><Account><Code>200</Code><Name>Sales</Name><Type>REVENUE</Type><TaxType>OUTPUT</TaxType><Description>Income from any normal business activity</Description></Account><Account><Code>260</Code><Name>Other Revenue</Name><Type>REVENUE</Type><TaxType>OUTPUT</TaxType><Description>Any other income that does not relate to normal business activities and is not recurring</Description></Account><Account><Code>270</Code><Name>Interest Income</Name><Type>REVENUE</Type><TaxType>NONE</TaxType><Description>Gross interest income (i.e. before deducting Residential Withholding Tax), such as bank interest</Description></Account><Account><Code>400</Code><Name>Advertising</Name><Type>OVERHEADS</Type><TaxType>INPUT</TaxType><Description>Expenses incurred for advertising while trying to increase sales</Description></Account><Account><Code>404</Code><Name>Bank Fees</Name><Type>OVERHEADS</Type><TaxType>NONE</TaxType><Description>Fees charged by your bank for transactions regarding your bank account(s).</Description></Account><Account><Code>408</Code><Name>Cleaning</Name><Type>OVERHEADS</Type><TaxType>INPUT</TaxType><Description>Expenses incurred for cleaning business property.</Description></Account><Account><Code>412</Code><Name>Consulting &amp; Accounting</Name><Type>OVERHEADS</Type><TaxType>INPUT</TaxType><Description>Expenses related to paying consultants</Description></Account><Account><Code>416</Code><Name>Depreciation</Name><Type>OVERHEADS</Type><TaxType>NONE</TaxType><Description>The amount of the asset's cost (based on the useful life) that was consumed during the period</Description></Account><Account><Code>420</Code><Name>Entertainment</Name><Type>OVERHEADS</Type><TaxType>INPUT</TaxType><Description>50% of the total expense relating to business-related entertainment. E.g. shouting clients or employees a drink or a meal etc.</Description></Account><Account><Code>424</Code><Name>Entertainment - Non deductible</Name><Type>OVERHEADS</Type><TaxType>NONE</TaxType><Description>Expenses paid by company for the business but are not deductable for income tax purposes.</Description></Account><Account><Code>425</Code><Name>Freight &amp; Courier</Name><Type>OVERHEADS</Type><TaxType>INPUT</TaxType><Description>Expenses incurred on courier &amp; freight costs</Description></Account><Account><Code>429</Code><Name>General Expenses</Name><Type>OVERHEADS</Type><TaxType>INPUT</TaxType><Description>General expenses related to the running of the business.</Description></Account><Account><Code>433</Code><Name>Insurance</Name><Type>OVERHEADS</Type><TaxType>INPUT</TaxType><Description>Expenses incurred for insuring the business' assets</Description></Account><Account><Code>437</Code><Name>Interest Expense</Name><Type>OVERHEADS</Type><TaxType>NONE</TaxType><Description>Any interest expenses paid to IRD, business bank accounts or credit card accounts.</Description></Account><Account><Code>441</Code><Name>Legal expenses</Name><Type>OVERHEADS</Type><TaxType>INPUT</TaxType><Description>Expenses incurred on any legal matters</Description></Account><Account><Code>445</Code><Name>Light, Power, Heating</Name><Type>OVERHEADS</Type><TaxType>INPUT</TaxType><Description>Expenses incurred for lighting, powering or heating the premises</Description></Account><Account><Code>449</Code><Name>Motor Vehicle Expenses</Name><Type>OVERHEADS</Type><TaxType>INPUT</TaxType><Description>Expenses incurred on the running of company motor vehicles</Description></Account><Account><Code>453</Code><Name>Office Expenses</Name><Type>OVERHEADS</Type><TaxType>INPUT</TaxType><Description>General expenses related to the running of the business office.</Description></Account><Account><Code>461</Code><Name>Printing &amp; Stationery</Name><Type>OVERHEADS</Type><TaxType>INPUT</TaxType><Description>Expenses incurred by the entity as a result of printing and stationery</Description></Account><Account><Code>469</Code><Name>Rent</Name><Type>OVERHEADS</Type><TaxType>INPUT</TaxType><Description>The payment to lease a building or area.</Description></Account><Account><Code>473</Code><Name>Repairs and Maintenance</Name><Type>OVERHEADS</Type><TaxType>INPUT</TaxType><Description>Expenses incurred on a damaged or run down asset that will bring the asset back to its original condition.</Description></Account><Account><Code>477</Code><Name>Salaries</Name><Type>OVERHEADS</Type><TaxType>NONE</TaxType><Description>Payment to employees in exchange for their resources</Description></Account><Account><Code>478</Code><Name>KiwiSaver Employer Contributions</Name><Type>OVERHEADS</Type><TaxType>NONE</TaxType><Description>KiwiSaver employer contributions</Description></Account><Account><Code>485</Code><Name>Subscriptions</Name><Type>OVERHEADS</Type><TaxType>INPUT</TaxType><Description>E.g. Magazines, professional bodies.</Description></Account><Account><Code>489</Code><Name>Telephone &amp; Internet</Name><Type>OVERHEADS</Type><TaxType>INPUT</TaxType><Description>Expenditure incurred from any business-related phone calls, phone lines, or internet connections</Description></Account><Account><Code>493</Code><Name>Travel - National</Name><Type>OVERHEADS</Type><TaxType>INPUT</TaxType><Description>Expenses incurred from domestic travel which has a business purpose</Description></Account><Account><Code>494</Code><Name>Travel - International</Name><Type>OVERHEADS</Type><TaxType>NONE</TaxType><Description>Expenses incurred from international travel which has a business purpose</Description></Account><Account><Code>505</Code><Name>Income Tax Expense</Name><Type>EXPENSE</Type><TaxType>NONE</TaxType><Description>A percentage of total earnings paid to the government.</Description></Account><Account><Code>610</Code><Name>Accounts Receivable</Name><Type>CURRENT</Type><TaxType>NONE</TaxType><Description>Outstanding invoices the company has issued out to the client but has not yet received in cash at balance date.</Description></Account><Account><Code>611</Code><Name>less Provision for Doubtful Debts</Name><Type>CURRENT</Type><TaxType>NONE</TaxType><Description>A provision anticipating that some of the accounts receivables will become bad debts.</Description></Account><Account><Code>620</Code><Name>Prepayments</Name><Type>CURRENT</Type><TaxType>NONE</TaxType><Description>An expenditure that has been paid for in advance.</Description></Account><Account><Code>625</Code><Name>Withholding tax paid</Name><Type>CURRENT</Type><TaxType>NONE</TaxType><Description>Withholding tax paid</Description></Account><Account><Code>710</Code><Name>Office Equipment</Name><Type>FIXED</Type><TaxType>INPUT</TaxType><Description>Office equipment that is owned and controlled by the business</Description></Account><Account><Code>711</Code><Name>Less Accumulated Depreciation on Office Equipment</Name><Type>FIXED</Type><TaxType>NONE</TaxType><Description>The total amount of office equipment cost that has been consumed by the entity (based on the useful life)</Description></Account><Account><Code>720</Code><Name>Computer Equipment</Name><Type>FIXED</Type><TaxType>INPUT</TaxType><Description>Computer equipment that is owned and controlled by the business</Description></Account><Account><Code>721</Code><Name>Less Accumulated Depreciation on Computer Equipment</Name><Type>FIXED</Type><TaxType>NONE</TaxType><Description>The total amount of computer equipment cost that has been consumed by the business (based on the useful life)</Description></Account><Account><Code>800</Code><Name>Accounts Payable</Name><Type>CURRLIAB</Type><TaxType>NONE</TaxType><Description>Outstanding invoices the company has received from suppliers but has not yet paid at balance date</Description></Account><Account><Code>801</Code><Name>Unpaid Expense Claims</Name><Type>CURRLIAB</Type><TaxType>NONE</TaxType><Description>Expense claims typically made by employees/shareholder employees still outstanding.</Description></Account><Account><Code>820</Code><Name>GST</Name><Type>CURRLIAB</Type><TaxType>NONE</TaxType><Description>The balance in this account represents GST owing to or from the IRD. At the end of the GST period, it is this account that should be used to code against either the 'refunds from' or 'payments to' the IRD that will appear on the bank statement. Xero has been designed to use only one GST account to track GST on income and expenses, so there is no need to add any new GST accounts to Xero.</Description></Account><Account><Code>821</Code><Name>GST On Imports</Name><Type>CURRLIAB</Type><TaxType>NONE</TaxType><Description>GST paid to customs.</Description></Account><Account><Code>825</Code><Name>PAYE Payable</Name><Type>CURRLIAB</Type><TaxType>NONE</TaxType><Description>The amount of PAYE tax that is due to be paid</Description></Account><Account><Code>830</Code><Name>Income Tax</Name><Type>CURRLIAB</Type><TaxType>NONE</TaxType><Description>The amount of income tax that is due to be paid, also resident withholding tax paid on interest received.</Description></Account><Account><Code>840</Code><Name>Historical Adjustment</Name><Type>CURRLIAB</Type><TaxType>NONE</TaxType><Description>For accountant adjustments</Description></Account><Account><Code>850</Code><Name>Suspense</Name><Type>CURRLIAB</Type><TaxType>NONE</TaxType><Description>An entry that allows an unknown transaction to be entered, so the accounts can still be worked on in balance and the entry can be dealt with later.</Description></Account><Account><Code>860</Code><Name>Rounding</Name><Type>CURRLIAB</Type><TaxType>NONE</TaxType><Description>An adjustment entry to allow for rounding</Description></Account><Account><Code>877</Code><Name>Tracking Transfers</Name><Type>CURRLIAB</Type><TaxType>NONE</TaxType><Description>Transfers between tracking categories</Description></Account><Account><Code>900</Code><Name>Loan</Name><Type>TERMLIAB</Type><TaxType>NONE</TaxType><Description>Money that has been borrowed from a creditor</Description></Account><Account><Code>960</Code><Name>Retained Earnings</Name><Type>EQUITY</Type><TaxType>NONE</TaxType><Description>Do not Use</Description></Account><Account><Code>970</Code><Name>Owner A Funds Introduced</Name><Type>EQUITY</Type><TaxType>NONE</TaxType><Description>Funds contributed by the owner</Description></Account><Account><Code>980</Code><Name>Owner A Drawings</Name><Type>EQUITY</Type><TaxType>NONE</TaxType><Description>Withdrawals by the owners</Description></Account></Accounts></Response>
@@ -0,0 +1 @@
1
+ <html><head><title>Object moved</title></head><body><h2>Object moved to <a href="%2fLogin.xro%2fLogin%3fReturnUrl%3d%252fapi.xro%252f1.0%252finvoice%253fapiKey%253dAN_INVALID_API_KEY%2526xeroKey%253dYWZIMZQ3ZGVJMME1NDCWNTK3YWZMNW%2526invoiceID%253dAN_INVALID_ID%26apiKey%3dAN_INVALID_API_KEY%26xeroKey%3dYWZIMZQ3ZGVJMME1NDCWNTK3YWZMNW%26invoiceID%3dAN_INVALID_ID">here</a>.</h2></body></html>
@@ -0,0 +1 @@
1
+ <Response xmlns:i="http://www.w3.org/2001/XMLSchema-instance"><Errors><Error><Description>AN_INVALID_CUSTOMER_KEY is not a valid Xero authentication key for YOUR_PROVIDER. A key for YOUR_PROVIDER must be set up by each Xero customer</Description><Exception><DateTime>2008-12-08T20:55:16.518375Z</DateTime><ExceptionType>Xero.API.Library.Exceptions.AuthKeyNotValidForProviderException</ExceptionType><Message>AN_INVALID_CUSTOMER_KEY is not a valid Xero authentication key for YOUR_PROVIDER. A key for YOUR_PROVIDER must be set up by each Xero customer</Message><Source>Xero.API.Library</Source><StackTrace> at Xero.API.Library.Model.Organisation.ValidateAuthKey(IOrganisationService organisationService, Provider provider) in D:\Projects\network\project\Xero.API.Library\Model\Organisation.cs:line 36 at Xero.API.MVC.Controllers.APIController.InitialiseMethod(String apiKey, String xeroKey, Boolean checkAuthKey, String[] allowableMethods) in D:\Projects\network\project\Xero.API.MVC\Controllers\APIController.cs:line 101</StackTrace></Exception></Error></Errors><ID>7a3f5fb3-a22b-4d3f-8995-0e95d80d59d2</ID><Status>InternalServerError</Status><ProviderName>YOUR_PROVIDER</ProviderName><DateTimeUTC>2008-12-08T20:55:16.50275Z</DateTimeUTC></Response>
@@ -0,0 +1 @@
1
+ <Response xmlns:i="http://www.w3.org/2001/XMLSchema-instance"><Errors><Error><Description>Invoice with invoice number 123 does not exist for this organisation</Description><Exception><DateTime>2008-12-05T21:03:15.4445759Z</DateTime><ExceptionType>Xero.API.Library.Exceptions.ObjectDoesNotExistException</ExceptionType><Message>Invoice with invoice number 123 does not exist for this organisation</Message><Source>Xero.API.Library</Source><StackTrace> at Xero.API.Library.Services.InvoiceService.GetInvoice(Guid organisationID, String invoiceNumber) in D:\Projects\network\project\Xero.API.Library\Services\InvoiceService.cs:line 508 at Xero.API.Web.Controllers.InvoiceController.Get(String apiKey, String xeroKey, String invoiceID, String invoiceNumber) in D:\Projects\network\project\Xero.API.Web\Controllers\InvoiceController.cs:line 37</StackTrace></Exception></Error></Errors><ID>eaf9db6c-d3b2-49e8-939a-d9f23cc7c412</ID><Status>InternalServerError</Status><ProviderName>YOUR PROVIDER</ProviderName><DateTimeUTC>2008-12-05T21:03:15.3508067Z</DateTimeUTC></Response>
@@ -0,0 +1 @@
1
+ <Response xmlns:i="http://www.w3.org/2001/XMLSchema-instance"><Errors><Error><Description>Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx).</Description><Exception><DateTime>2008-12-05T21:02:09.9624179Z</DateTime><ExceptionType>System.FormatException</ExceptionType><Message>Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx).</Message><Source>mscorlib</Source><StackTrace> at System.Guid..ctor(String g) at Xero.API.Web.Controllers.InvoiceController.Get(String apiKey, String xeroKey, String invoiceID, String invoiceNumber) in D:\Projects\network\project\Xero.API.Web\Controllers\InvoiceController.cs:line 37</StackTrace></Exception></Error></Errors><ID>225ad11e-601e-4e2a-bdb1-48e8517efbb3</ID><Status>InternalServerError</Status><ProviderName>YOUR PROVIDER</ProviderName><DateTimeUTC>2008-12-05T21:02:09.9467897Z</DateTimeUTC></Response>
data/test/test_helper.rb CHANGED
@@ -6,4 +6,68 @@ require 'mocha'
6
6
  require 'libxml'
7
7
 
8
8
  require File.dirname(__FILE__) + '/../lib/xero_gateway.rb'
9
- require File.dirname(__FILE__) + '/integration/integration_test_methods.rb'
9
+
10
+ module TestHelper
11
+ # The integration tests can be run against the Xero test environment. You mush have a company set up in the test
12
+ # environment, and you must have set up a customer key for that account.
13
+ #
14
+ # You can then run the tests against the test environment using the commands (linux or mac):
15
+ # export STUB_XERO_CALLS=false
16
+ # export API_KEY=[your_api_key]
17
+ # export CUSTOMER_KEY=[your_customer_key]
18
+ # rake test
19
+ STUB_XERO_CALLS = ENV["STUB_XERO_CALLS"].nil? ? true : (ENV["STUB_XERO_CALLS"] == "true") unless defined? STUB_XERO_CALLS
20
+
21
+ API_KEY = ENV["API_KEY"] unless defined? API_KEY
22
+ CUSTOMER_KEY = ENV["CUSTOMER_KEY"] unless defined? CUSTOMER_KEY
23
+
24
+
25
+ def dummy_invoice
26
+ invoice = XeroGateway::Invoice.new({
27
+ :invoice_type => "ACCREC",
28
+ :due_date => Date.today + 20,
29
+ :invoice_number => STUB_XERO_CALLS ? "INV-0001" : "#{Time.now.to_f}",
30
+ :reference => "YOUR REFERENCE (NOT NECESSARILY UNIQUE!)",
31
+ :sub_total => 1000,
32
+ :total_tax => 125,
33
+ :total => 1125
34
+ })
35
+ invoice.contact = dummy_contact
36
+ invoice.line_items << XeroGateway::LineItem.new(
37
+ :description => "THE DESCRIPTION OF THE LINE ITEM",
38
+ :unit_amount => 1000,
39
+ :tax_amount => 125,
40
+ :line_amount => 1000,
41
+ :tracking_category => "THE TRACKING CATEGORY FOR THE LINE ITEM",
42
+ :tracking_option => "THE TRACKING OPTION FOR THE LINE ITEM"
43
+ )
44
+ invoice
45
+ end
46
+
47
+ def dummy_contact
48
+ unique_id = Time.now.to_f
49
+ contact = XeroGateway::Contact.new(:name => STUB_XERO_CALLS ? "CONTACT NAME" : "THE NAME OF THE CONTACT #{unique_id}")
50
+ contact.email = "bob#{unique_id}@example.com"
51
+ contact.phone.number = "12345"
52
+ contact.address.line_1 = "LINE 1 OF THE ADDRESS"
53
+ contact.address.line_2 = "LINE 2 OF THE ADDRESS"
54
+ contact.address.line_3 = "LINE 3 OF THE ADDRESS"
55
+ contact.address.line_4 = "LINE 4 OF THE ADDRESS"
56
+ contact.address.city = "WELLINGTON"
57
+ contact.address.region = "WELLINGTON"
58
+ contact.address.country = "NEW ZEALAND"
59
+ contact.address.post_code = "6021"
60
+
61
+ contact
62
+ end
63
+
64
+ def get_file_as_string(filename)
65
+ data = ''
66
+ f = File.open(File.dirname(__FILE__) + "/stub_responses/" + filename, "r")
67
+ f.each_line do |line|
68
+ data += line
69
+ end
70
+ f.close
71
+ return data
72
+ end
73
+ end
@@ -1,18 +1,18 @@
1
- require File.join(File.dirname(__FILE__), '../../test_helper.rb')
1
+ require File.join(File.dirname(__FILE__), '../test_helper.rb')
2
2
 
3
- class AccountMessageTest < Test::Unit::TestCase
3
+ class AccountTest < Test::Unit::TestCase
4
4
  # Tests that an account can be converted into XML that Xero can understand, and then converted back to an account
5
5
  def test_build_and_parse_xml
6
6
  account = create_test_account
7
7
 
8
8
  # Generate the XML message
9
- account_as_xml = XeroGateway::Messages::AccountMessage.build_xml(account)
9
+ account_as_xml = account.to_xml
10
10
 
11
11
  # Parse the XML message and retrieve the account element
12
12
  account_element = REXML::XPath.first(REXML::Document.new(account_as_xml), "/Account")
13
13
 
14
14
  # Build a new account from the XML
15
- result_account = XeroGateway::Messages::AccountMessage.from_xml(account_element)
15
+ result_account = XeroGateway::Account.from_xml(account_element)
16
16
 
17
17
  # Check the account details
18
18
  assert_equal account, result_account
@@ -1,15 +1,15 @@
1
- require File.join(File.dirname(__FILE__), '../../test_helper.rb')
1
+ require File.join(File.dirname(__FILE__), '../test_helper.rb')
2
2
 
3
- class ContactMessageTest < Test::Unit::TestCase
3
+ class ContactTest < Test::Unit::TestCase
4
4
  def setup
5
- @schema = LibXML::XML::Schema.document(LibXML::XML::Document.file(File.join(File.dirname(__FILE__), '../../xsd/create_contact.xsd')))
5
+ @schema = LibXML::XML::Schema.document(LibXML::XML::Document.file(File.join(File.dirname(__FILE__), '../xsd/create_contact.xsd')))
6
6
  end
7
7
 
8
8
  # Tests that the XML generated from a contact object validates against the Xero XSD
9
9
  def test_build_xml
10
10
  contact = create_test_contact
11
11
 
12
- message = XeroGateway::Messages::ContactMessage.build_xml(contact)
12
+ message = contact.to_xml
13
13
 
14
14
  # Check that the document matches the XSD
15
15
  assert LibXML::XML::Parser.string(message).parse.validate_schema(@schema), "The XML document generated did not validate against the XSD"
@@ -20,13 +20,13 @@ class ContactMessageTest < Test::Unit::TestCase
20
20
  contact = create_test_contact
21
21
 
22
22
  # Generate the XML message
23
- contact_as_xml = XeroGateway::Messages::ContactMessage.build_xml(contact)
23
+ contact_as_xml = contact.to_xml
24
24
 
25
25
  # Parse the XML message and retrieve the contact element
26
26
  contact_element = REXML::XPath.first(REXML::Document.new(contact_as_xml), "/Contact")
27
27
 
28
28
  # Build a new contact from the XML
29
- result_contact = XeroGateway::Messages::ContactMessage.from_xml(contact_element)
29
+ result_contact = XeroGateway::Contact.from_xml(contact_element)
30
30
 
31
31
  # Check the contact details
32
32
  assert_equal contact, result_contact
@@ -0,0 +1,66 @@
1
+ require File.join(File.dirname(__FILE__), '../test_helper.rb')
2
+
3
+ class GatewayTest < Test::Unit::TestCase
4
+ include TestHelper
5
+
6
+ def setup
7
+ @gateway = XeroGateway::Gateway.new(
8
+ :customer_key => CUSTOMER_KEY,
9
+ :api_key => API_KEY
10
+ )
11
+ end
12
+
13
+ def test_invalid_api_key_error_handling
14
+ if STUB_XERO_CALLS
15
+ @gateway.xero_url = "DUMMY_URL"
16
+ @gateway.stubs(:http_get).with {|url, params| url =~ /invoices$/ }.returns(get_file_as_string("invalid_api_key_error.xml"))
17
+ end
18
+
19
+ @gateway.api_key = "AN_INVALID_API_KEY"
20
+
21
+ result = @gateway.get_invoices
22
+ assert !result.success?
23
+ assert_equal "INVALID_API_KEY", result.status
24
+ end
25
+
26
+ def test_invalid_customer_key_error_handling
27
+ if STUB_XERO_CALLS
28
+ @gateway.xero_url = "DUMMY_URL"
29
+ @gateway.stubs(:http_get).with {|url, params| url =~ /invoices$/ }.returns(get_file_as_string("invalid_customer_key_error.xml"))
30
+ end
31
+
32
+ @gateway.customer_key = "AN_INVALID_CUSTOMER_KEY"
33
+
34
+ result = @gateway.get_invoices
35
+
36
+ assert !result.success?
37
+ assert_equal 1, result.errors.size
38
+ assert result.errors.first.description =~ /^AN_INVALID_CUSTOMER_KEY is not a valid Xero authentication key/
39
+ end
40
+
41
+ def test_unknown_error_handling
42
+ if STUB_XERO_CALLS
43
+ @gateway.xero_url = "DUMMY_URL"
44
+ @gateway.stubs(:http_get).with {|url, params| url =~ /invoice$/ }.returns(get_file_as_string("unknown_error.xml"))
45
+ end
46
+
47
+ result = @gateway.get_invoice_by_id("AN_INVALID_ID")
48
+ assert !result.success?
49
+ assert_equal 1, result.errors.size
50
+ assert !result.errors.first.type.nil?
51
+ assert !result.errors.first.description.nil?
52
+ end
53
+
54
+ def test_object_not_found_error_handling
55
+ if STUB_XERO_CALLS
56
+ @gateway.xero_url = "DUMMY_URL"
57
+ @gateway.stubs(:http_get).with {|url, params| url =~ /invoice$/ }.returns(get_file_as_string("invoice_not_found_error.xml"))
58
+ end
59
+
60
+ result = @gateway.get_invoice_by_number("UNKNOWN_INVOICE_NO")
61
+ assert !result.success?
62
+ assert_equal 1, result.errors.size
63
+ assert_equal "Xero.API.Library.Exceptions.ObjectDoesNotExistException", result.errors.first.type
64
+ assert !result.errors.first.description.nil?
65
+ end
66
+ end
@@ -1,15 +1,15 @@
1
- require File.join(File.dirname(__FILE__), '../../test_helper.rb')
1
+ require File.join(File.dirname(__FILE__), '../test_helper.rb')
2
2
 
3
- class InvoiceMessageTest < Test::Unit::TestCase
3
+ class InvoiceTest < Test::Unit::TestCase
4
4
  def setup
5
- @schema = LibXML::XML::Schema.document(LibXML::XML::Document.file(File.join(File.dirname(__FILE__), '../../xsd/create_invoice.xsd')))
5
+ @schema = LibXML::XML::Schema.document(LibXML::XML::Document.file(File.join(File.dirname(__FILE__), '../xsd/create_invoice.xsd')))
6
6
  end
7
7
 
8
8
  # Tests that the XML generated from an invoice object validates against the Xero XSD
9
9
  def test_build_xml
10
10
  invoice = create_test_invoice
11
11
 
12
- message = XeroGateway::Messages::InvoiceMessage.build_xml(invoice)
12
+ message = invoice.to_xml
13
13
 
14
14
  # Check that the document matches the XSD
15
15
  assert LibXML::XML::Parser.string(message).parse.validate_schema(@schema), "The XML document generated did not validate against the XSD"
@@ -20,13 +20,13 @@ class InvoiceMessageTest < Test::Unit::TestCase
20
20
  invoice = create_test_invoice
21
21
 
22
22
  # Generate the XML message
23
- invoice_as_xml = XeroGateway::Messages::InvoiceMessage.build_xml(invoice)
23
+ invoice_as_xml = invoice.to_xml
24
24
 
25
25
  # Parse the XML message and retrieve the invoice element
26
26
  invoice_element = REXML::XPath.first(REXML::Document.new(invoice_as_xml), "/Invoice")
27
27
 
28
28
  # Build a new invoice from the XML
29
- result_invoice = XeroGateway::Messages::InvoiceMessage.from_xml(invoice_element)
29
+ result_invoice = XeroGateway::Invoice.from_xml(invoice_element)
30
30
 
31
31
  assert_equal(invoice, result_invoice)
32
32
  end
@@ -1,18 +1,18 @@
1
- require File.join(File.dirname(__FILE__), '../../test_helper.rb')
1
+ require File.join(File.dirname(__FILE__), '../test_helper.rb')
2
2
 
3
- class TrackingCategoryMessageTest < Test::Unit::TestCase
3
+ class TrackingCategoryTest < Test::Unit::TestCase
4
4
  # Tests that a tracking category can be converted into XML that Xero can understand, and then converted back to a tracking category
5
5
  def test_build_and_parse_xml
6
6
  tracking_category = create_test_tracking_category
7
7
 
8
8
  # Generate the XML message
9
- tracking_category_as_xml = XeroGateway::Messages::TrackingCategoryMessage.build_xml(tracking_category)
9
+ tracking_category_as_xml = tracking_category.to_xml
10
10
 
11
11
  # Parse the XML message and retrieve the tracking category element
12
12
  tracking_category_element = REXML::XPath.first(REXML::Document.new(tracking_category_as_xml), "/TrackingCategory")
13
13
 
14
14
  # Build a new tracking category from the XML
15
- result_tracking_category = XeroGateway::Messages::TrackingCategoryMessage.from_xml(tracking_category_element)
15
+ result_tracking_category = XeroGateway::TrackingCategory.from_xml(tracking_category_element)
16
16
 
17
17
  # Check the tracking category details
18
18
  assert_equal tracking_category, result_tracking_category
data/xero_gateway.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "xero_gateway"
3
- s.version = "1.0.2"
4
- s.date = "2008-12-04"
3
+ s.version = "1.0.3"
4
+ s.date = "2008-12-09"
5
5
  s.summary = "Enables ruby based applications to communicate with the Xero API"
6
6
  s.email = "tlconnor@gmail.com"
7
7
  s.homepage = "http://github.com/tlconnor/xero_gateway"
@@ -19,6 +19,7 @@ Gem::Specification.new do |s|
19
19
  "lib/xero_gateway/address.rb",
20
20
  "lib/xero_gateway/contact.rb",
21
21
  "lib/xero_gateway/dates.rb",
22
+ "lib/xero_gateway/error.rb",
22
23
  "lib/xero_gateway/gateway.rb",
23
24
  "lib/xero_gateway/http.rb",
24
25
  "lib/xero_gateway/invoice.rb",
@@ -27,10 +28,6 @@ Gem::Specification.new do |s|
27
28
  "lib/xero_gateway/phone.rb",
28
29
  "lib/xero_gateway/response.rb",
29
30
  "lib/xero_gateway/tracking_category.rb",
30
- "lib/xero_gateway/messages/account_message.rb",
31
- "lib/xero_gateway/messages/contact_message.rb",
32
- "lib/xero_gateway/messages/invoice_message.rb",
33
- "lib/xero_gateway/messages/tracking_category_message.rb",
34
31
  "test/test_helper.rb",
35
32
  "test/integration/create_contact_test.rb",
36
33
  "test/integration/create_invoice_test.rb",
@@ -40,18 +37,22 @@ Gem::Specification.new do |s|
40
37
  "test/integration/get_invoice_test.rb",
41
38
  "test/integration/get_invoices_test.rb",
42
39
  "test/integration/get_tracking_categories_test.rb",
43
- "test/integration/integration_test_methods.rb",
44
- "test/integration/stub_responses/accounts.xml",
45
- "test/integration/stub_responses/contact.xml",
46
- "test/integration/stub_responses/contacts.xml",
47
- "test/integration/stub_responses/invoice.xml",
48
- "test/integration/stub_responses/invoices.xml",
49
- "test/integration/stub_responses/tracking_categories.xml",
50
40
  "test/integration/update_contact_test.rb",
51
- "test/unit/messages/account_message_test.rb",
52
- "test/unit/messages/contact_message_test.rb",
53
- "test/unit/messages/invoice_message_test.rb",
54
- "test/unit/messages/tracking_category_message_test.rb",
41
+ "test/stub_responses/accounts.xml",
42
+ "test/stub_responses/contact.xml",
43
+ "test/stub_responses/contacts.xml",
44
+ "test/stub_responses/invoice.xml",
45
+ "test/stub_responses/invoices.xml",
46
+ "test/stub_responses/invalid_api_key_error.xml",
47
+ "test/stub_responses/invalid_customer_key_error.xml",
48
+ "test/stub_responses/tracking_categories.xml",
49
+ "test/stub_responses/invoice_not_found_error.xml",
50
+ "test/stub_responses/unknown_error.xml",
51
+ "test/unit/account_test.rb",
52
+ "test/unit/contact_test.rb",
53
+ "test/unit/gateway_test.rb",
54
+ "test/unit/invoice_test.rb",
55
+ "test/unit/tracking_category_test.rb",
55
56
  "test/xsd/README",
56
57
  "test/xsd/create_contact.xsd",
57
58
  "test/xsd/create_invoice.xsd",
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tlconnor-xero_gateway
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Connor
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-12-04 00:00:00 -08:00
12
+ date: 2008-12-09 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -40,6 +40,7 @@ files:
40
40
  - lib/xero_gateway/address.rb
41
41
  - lib/xero_gateway/contact.rb
42
42
  - lib/xero_gateway/dates.rb
43
+ - lib/xero_gateway/error.rb
43
44
  - lib/xero_gateway/gateway.rb
44
45
  - lib/xero_gateway/http.rb
45
46
  - lib/xero_gateway/invoice.rb
@@ -48,10 +49,6 @@ files:
48
49
  - lib/xero_gateway/phone.rb
49
50
  - lib/xero_gateway/response.rb
50
51
  - lib/xero_gateway/tracking_category.rb
51
- - lib/xero_gateway/messages/account_message.rb
52
- - lib/xero_gateway/messages/contact_message.rb
53
- - lib/xero_gateway/messages/invoice_message.rb
54
- - lib/xero_gateway/messages/tracking_category_message.rb
55
52
  - test/test_helper.rb
56
53
  - test/integration/create_contact_test.rb
57
54
  - test/integration/create_invoice_test.rb
@@ -61,18 +58,22 @@ files:
61
58
  - test/integration/get_invoice_test.rb
62
59
  - test/integration/get_invoices_test.rb
63
60
  - test/integration/get_tracking_categories_test.rb
64
- - test/integration/integration_test_methods.rb
65
- - test/integration/stub_responses/accounts.xml
66
- - test/integration/stub_responses/contact.xml
67
- - test/integration/stub_responses/contacts.xml
68
- - test/integration/stub_responses/invoice.xml
69
- - test/integration/stub_responses/invoices.xml
70
- - test/integration/stub_responses/tracking_categories.xml
71
61
  - test/integration/update_contact_test.rb
72
- - test/unit/messages/account_message_test.rb
73
- - test/unit/messages/contact_message_test.rb
74
- - test/unit/messages/invoice_message_test.rb
75
- - test/unit/messages/tracking_category_message_test.rb
62
+ - test/stub_responses/accounts.xml
63
+ - test/stub_responses/contact.xml
64
+ - test/stub_responses/contacts.xml
65
+ - test/stub_responses/invoice.xml
66
+ - test/stub_responses/invoices.xml
67
+ - test/stub_responses/invalid_api_key_error.xml
68
+ - test/stub_responses/invalid_customer_key_error.xml
69
+ - test/stub_responses/tracking_categories.xml
70
+ - test/stub_responses/invoice_not_found_error.xml
71
+ - test/stub_responses/unknown_error.xml
72
+ - test/unit/account_test.rb
73
+ - test/unit/contact_test.rb
74
+ - test/unit/gateway_test.rb
75
+ - test/unit/invoice_test.rb
76
+ - test/unit/tracking_category_test.rb
76
77
  - test/xsd/README
77
78
  - test/xsd/create_contact.xsd
78
79
  - test/xsd/create_invoice.xsd
@@ -1,33 +0,0 @@
1
- module XeroGateway
2
- module Messages
3
- class AccountMessage
4
-
5
- def self.build_xml(account)
6
- b = Builder::XmlMarkup.new
7
-
8
- b.Account {
9
- b.Code account.code
10
- b.Name account.name
11
- b.Type account.type
12
- b.TaxType account.tax_type
13
- b.Description account.description
14
- }
15
- end
16
-
17
- # Take an Account element and convert it into an Account object
18
- def self.from_xml(account_element)
19
- account = Account.new
20
- account_element.children.each do |element|
21
- case(element.name)
22
- when "Code" then account.code = element.text
23
- when "Name" then account.name = element.text
24
- when "Type" then account.type = element.text
25
- when "TaxType" then account.tax_type = element.text
26
- when "Description" then account.description = element.text
27
- end
28
- end
29
- account
30
- end
31
- end
32
- end
33
- end