xero_gateway 2.0.2
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.
- data/CHANGELOG.textile +51 -0
- data/LICENSE +14 -0
- data/README.textile +289 -0
- data/Rakefile +14 -0
- data/examples/oauth.rb +25 -0
- data/init.rb +1 -0
- data/lib/xero_gateway/account.rb +78 -0
- data/lib/xero_gateway/accounts_list.rb +77 -0
- data/lib/xero_gateway/address.rb +97 -0
- data/lib/xero_gateway/ca-certificates.crt +2560 -0
- data/lib/xero_gateway/contact.rb +206 -0
- data/lib/xero_gateway/currency.rb +56 -0
- data/lib/xero_gateway/dates.rb +25 -0
- data/lib/xero_gateway/error.rb +18 -0
- data/lib/xero_gateway/exceptions.rb +41 -0
- data/lib/xero_gateway/gateway.rb +363 -0
- data/lib/xero_gateway/http.rb +128 -0
- data/lib/xero_gateway/http_encoding_helper.rb +49 -0
- data/lib/xero_gateway/invoice.rb +278 -0
- data/lib/xero_gateway/line_item.rb +123 -0
- data/lib/xero_gateway/money.rb +16 -0
- data/lib/xero_gateway/oauth.rb +56 -0
- data/lib/xero_gateway/organisation.rb +61 -0
- data/lib/xero_gateway/payment.rb +40 -0
- data/lib/xero_gateway/phone.rb +77 -0
- data/lib/xero_gateway/private_app.rb +17 -0
- data/lib/xero_gateway/response.rb +37 -0
- data/lib/xero_gateway/tax_rate.rb +63 -0
- data/lib/xero_gateway/tracking_category.rb +62 -0
- data/lib/xero_gateway.rb +33 -0
- data/test/integration/accounts_list_test.rb +109 -0
- data/test/integration/create_contact_test.rb +66 -0
- data/test/integration/create_invoice_test.rb +49 -0
- data/test/integration/get_accounts_test.rb +23 -0
- data/test/integration/get_contact_test.rb +28 -0
- data/test/integration/get_contacts_test.rb +40 -0
- data/test/integration/get_currencies_test.rb +25 -0
- data/test/integration/get_invoice_test.rb +48 -0
- data/test/integration/get_invoices_test.rb +90 -0
- data/test/integration/get_organisation_test.rb +24 -0
- data/test/integration/get_tax_rates_test.rb +25 -0
- data/test/integration/get_tracking_categories_test.rb +26 -0
- data/test/integration/update_contact_test.rb +31 -0
- data/test/stub_responses/accounts.xml +1 -0
- data/test/stub_responses/api_exception.xml +153 -0
- data/test/stub_responses/contact.xml +1 -0
- data/test/stub_responses/contacts.xml +2189 -0
- data/test/stub_responses/create_invoice.xml +64 -0
- data/test/stub_responses/currencies.xml +16 -0
- data/test/stub_responses/invalid_api_key_error.xml +1 -0
- data/test/stub_responses/invalid_consumer_key +1 -0
- data/test/stub_responses/invalid_request_token +1 -0
- data/test/stub_responses/invoice.xml +1 -0
- data/test/stub_responses/invoice_not_found_error.xml +1 -0
- data/test/stub_responses/invoices.xml +1 -0
- data/test/stub_responses/organisation.xml +14 -0
- data/test/stub_responses/tax_rates.xml +52 -0
- data/test/stub_responses/token_expired +1 -0
- data/test/stub_responses/tracking_categories.xml +1 -0
- data/test/stub_responses/unknown_error.xml +1 -0
- data/test/test_helper.rb +81 -0
- data/test/unit/account_test.rb +34 -0
- data/test/unit/contact_test.rb +97 -0
- data/test/unit/currency_test.rb +31 -0
- data/test/unit/gateway_test.rb +79 -0
- data/test/unit/invoice_test.rb +302 -0
- data/test/unit/oauth_test.rb +110 -0
- data/test/unit/organisation_test.rb +34 -0
- data/test/unit/tax_rate_test.rb +38 -0
- data/test/unit/tracking_category_test.rb +30 -0
- data/test/xsd/README +2 -0
- data/test/xsd/create_contact.xsd +61 -0
- data/test/xsd/create_invoice.xsd +107 -0
- data/xero_gateway.gemspec +87 -0
- metadata +172 -0
@@ -0,0 +1,64 @@
|
|
1
|
+
<Response xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
|
2
|
+
<Id>ac61eaae-0700-4f95-813d-aefa09eb57c6</Id>
|
3
|
+
<Status>OK</Status>
|
4
|
+
<ProviderName>XeroGateway Test</ProviderName>
|
5
|
+
<DateTimeUTC>2009-10-17T09:17:48.5216708Z</DateTimeUTC>
|
6
|
+
<Invoices>
|
7
|
+
<Invoice>
|
8
|
+
<Type>ACCREC</Type>
|
9
|
+
<Contact>
|
10
|
+
<ContactID>3e1d3ba5-609a-4e10-bb1d-75b6d31ce922</ContactID>
|
11
|
+
<ContactStatus>ACTIVE</ContactStatus>
|
12
|
+
<Name>AMP</Name>
|
13
|
+
<Addresses>
|
14
|
+
<Address>
|
15
|
+
<AddressType>STREET</AddressType>
|
16
|
+
</Address>
|
17
|
+
<Address>
|
18
|
+
<AddressType>POBOX</AddressType>
|
19
|
+
</Address>
|
20
|
+
</Addresses>
|
21
|
+
<Phones>
|
22
|
+
<Phone>
|
23
|
+
<PhoneType>MOBILE</PhoneType>
|
24
|
+
</Phone>
|
25
|
+
<Phone>
|
26
|
+
<PhoneType>DDI</PhoneType>
|
27
|
+
</Phone>
|
28
|
+
<Phone>
|
29
|
+
<PhoneType>DEFAULT</PhoneType>
|
30
|
+
</Phone>
|
31
|
+
<Phone>
|
32
|
+
<PhoneType>FAX</PhoneType>
|
33
|
+
</Phone>
|
34
|
+
</Phones>
|
35
|
+
<UpdatedDateUTC>2009-09-21T23:07:47.49</UpdatedDateUTC>
|
36
|
+
<IsSupplier>false</IsSupplier>
|
37
|
+
<IsCustomer>true</IsCustomer>
|
38
|
+
</Contact>
|
39
|
+
<DueDate>2009-10-27T00:00:00</DueDate>
|
40
|
+
<Status>DRAFT</Status>
|
41
|
+
<LineAmountTypes>Exclusive</LineAmountTypes>
|
42
|
+
<LineItems>
|
43
|
+
<LineItem>
|
44
|
+
<Description>(17 Oct) something</Description>
|
45
|
+
<Quantity>30.0000</Quantity>
|
46
|
+
<UnitAmount>100.00</UnitAmount>
|
47
|
+
<TaxType>OUTPUT</TaxType>
|
48
|
+
<TaxAmount>375.00</TaxAmount>
|
49
|
+
<LineAmount>3000.00</LineAmount>
|
50
|
+
<AccountCode>200</AccountCode>
|
51
|
+
</LineItem>
|
52
|
+
</LineItems>
|
53
|
+
<SubTotal>3000.00</SubTotal>
|
54
|
+
<TotalTax>375.00</TotalTax>
|
55
|
+
<Total>3375.00</Total>
|
56
|
+
<UpdatedDateUTC>2009-10-17T09:17:47.427</UpdatedDateUTC>
|
57
|
+
<CurrencyCode>NZD</CurrencyCode>
|
58
|
+
<InvoiceID>a99a9aaa-9999-99a9-9aa9-aaaaaa9a9999</InvoiceID>
|
59
|
+
<InvoiceNumber>INV-0001</InvoiceNumber>
|
60
|
+
<AmountDue>3375.00</AmountDue>
|
61
|
+
<AmountPaid>0.00</AmountPaid>
|
62
|
+
</Invoice>
|
63
|
+
</Invoices>
|
64
|
+
</Response>
|
@@ -0,0 +1,16 @@
|
|
1
|
+
<Response xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
|
2
|
+
<Id>244a1123-ca58-4ab8-9893-74bb87b54307</Id>
|
3
|
+
<Status>OK</Status>
|
4
|
+
<ProviderName>Xero Gateway Test</ProviderName>
|
5
|
+
<DateTimeUTC>2009-10-04T03:28:12.048587Z</DateTimeUTC>
|
6
|
+
<Currencies>
|
7
|
+
<Currency>
|
8
|
+
<Code>NZD</Code>
|
9
|
+
<Description>New Zealand Dollar</Description>
|
10
|
+
</Currency>
|
11
|
+
<Currency>
|
12
|
+
<Code>USD</Code>
|
13
|
+
<Description>United States Dollar</Description>
|
14
|
+
</Currency>
|
15
|
+
</Currencies>
|
16
|
+
</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
|
+
oauth_problem=token_rejected&oauth_problem_advice=Unknown%20consumer
|
@@ -0,0 +1 @@
|
|
1
|
+
oauth_problem=token_rejected&oauth_problem_advice=Unexpected%20token
|
@@ -0,0 +1 @@
|
|
1
|
+
<?xml version="1.0"?><Response xmlns:i="http://www.w3.org/2001/XMLSchema-instance"><ID>a99a9aaa-9999-99a9-9aa9-aaaaaa9a9999</ID><Status>OK</Status><ProviderName>YOUR PROVIDER</ProviderName><DateTimeUTC>2008-10-09T00:59:11.1341229Z</DateTimeUTC><Invoice><Type>ACCREC</Type><InvoiceID>a99a9aaa-9999-99a9-9aa9-aaaaaa9a9999</InvoiceID><Contact><ContactID>a99a9aaa-9999-99a9-9aa9-aaaaaa9a9999</ContactID><ContactStatus>ACTIVE</ContactStatus><Name>CONTACT NAME</Name><EmailAddress>bob@example.com</EmailAddress><Addresses><Address><AddressType>POBOX</AddressType><AddressLine1>LINE 1 OF THE ADDRESS</AddressLine1><AddressLine2></AddressLine2><AddressLine3></AddressLine3><AddressLine4></AddressLine4><City>Somewhere</City><Region></Region><PostalCode></PostalCode><Country>Some Country</Country></Address></Addresses><Phones><Phone><PhoneType>MOBILE</PhoneType><PhoneNumber>1234567</PhoneNumber><PhoneAreaCode>123</PhoneAreaCode><PhoneCountryCode></PhoneCountryCode></Phone><Phone><PhoneType>DEFAULT</PhoneType><PhoneNumber></PhoneNumber><PhoneAreaCode></PhoneAreaCode><PhoneCountryCode></PhoneCountryCode></Phone><Phone><PhoneType>FAX</PhoneType><PhoneNumber></PhoneNumber><PhoneAreaCode></PhoneAreaCode><PhoneCountryCode></PhoneCountryCode></Phone><Phone><PhoneType>DDI</PhoneType><PhoneNumber></PhoneNumber><PhoneAreaCode></PhoneAreaCode><PhoneCountryCode></PhoneCountryCode></Phone></Phones></Contact><Date>2008-10-03T00:00:00</Date><DueDate>2008-10-20T00:00:00</DueDate><InvoiceNumber>INV-0001</InvoiceNumber><Reference></Reference><IncludesTax>true</IncludesTax><SubTotal>1000.0000</SubTotal><TotalTax>125.0000</TotalTax><Total>1125.0000</Total><InvoiceStatus>AUTHORISED</InvoiceStatus><LineItems><LineItem><LineItemID>e5a8a4ee-85ee-4532-a79f-a552ec63a0d7</LineItemID><Description>A LINE ITEM</Description><Quantity>100.0</Quantity><UnitAmount>12.34</UnitAmount><TaxType>OUTPUT</TaxType><TaxAmount>125.0000</TaxAmount><LineAmount>1125.0000</LineAmount><Tracking><TrackingCategory><Name>Region</Name><Option>Central</Option></TrackingCategory></Tracking></LineItem></LineItems></Invoice></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
|
+
<?xml version="1.0"?><Response xmlns:i="http://www.w3.org/2001/XMLSchema-instance"><ID>a99a9aaa-9999-99a9-9aa9-aaaaaa9a9999</ID><Status>OK</Status><ProviderName>YOUR PROVIDER</ProviderName><DateTimeUTC>2008-10-09T00:59:11.1341229Z</DateTimeUTC><Invoices><Invoice><InvoiceType>ACCREC</InvoiceType><InvoiceID>a99a9aaa-9999-99a9-9aa9-aaaaaa9a9999</InvoiceID><Contact><ContactID>a99a9aaa-9999-99a9-9aa9-aaaaaa9a9999</ContactID><ContactStatus>ACTIVE</ContactStatus><Name>CONTACT NAME</Name><EmailAddress>bob@example.com</EmailAddress><Addresses><Address><AddressType>POBOX</AddressType><AddressLine1>LINE 1 OF THE ADDRESS</AddressLine1><AddressLine2/><AddressLine3/><AddressLine4/><City>Somewhere</City><Region/><PostalCode/><Country>Some Country</Country></Address></Addresses><Phones><Phone><PhoneType>MOBILE</PhoneType><PhoneNumber>1234567</PhoneNumber><PhoneAreaCode>123</PhoneAreaCode><PhoneCountryCode/></Phone><Phone><PhoneType>DEFAULT</PhoneType><PhoneNumber/><PhoneAreaCode/><PhoneCountryCode/></Phone><Phone><PhoneType>FAX</PhoneType><PhoneNumber/><PhoneAreaCode/><PhoneCountryCode/></Phone><Phone><PhoneType>DDI</PhoneType><PhoneNumber/><PhoneAreaCode/><PhoneCountryCode/></Phone></Phones></Contact><Date>2008-10-03T00:00:00</Date><DueDate>2008-10-20T00:00:00</DueDate><InvoiceNumber>INV-0001</InvoiceNumber><Reference/><IncludesTax>true</IncludesTax><SubTotal>1000.0000</SubTotal><TotalTax>125.0000</TotalTax><Total>1125.0000</Total><InvoiceStatus>AUTHORISED</InvoiceStatus><LineItems/></Invoice><Invoice><InvoiceType>ACCREC</InvoiceType><InvoiceID>a11a1aaa-1111-11a1-1aa1-aaaaaa1a1111</InvoiceID><Contact><ContactID>a11a1aaa-1111-11a1-1aa1-aaaaaa1a1111</ContactID><ContactStatus>ACTIVE</ContactStatus><Name>CONTACT NAME</Name><EmailAddress>bob@example.com</EmailAddress><Addresses><Address><AddressType>POBOX</AddressType><AddressLine1>LINE 1 OF THE ADDRESS</AddressLine1><AddressLine2/><AddressLine3/><AddressLine4/><City>Somewhere</City><Region/><PostalCode/><Country>Some Country</Country></Address></Addresses><Phones><Phone><PhoneType>MOBILE</PhoneType><PhoneNumber>1234567</PhoneNumber><PhoneAreaCode>123</PhoneAreaCode><PhoneCountryCode/></Phone><Phone><PhoneType>DEFAULT</PhoneType><PhoneNumber/><PhoneAreaCode/><PhoneCountryCode/></Phone><Phone><PhoneType>FAX</PhoneType><PhoneNumber/><PhoneAreaCode/><PhoneCountryCode/></Phone><Phone><PhoneType>DDI</PhoneType><PhoneNumber/><PhoneAreaCode/><PhoneCountryCode/></Phone></Phones></Contact><Date>2008-10-03T00:00:00</Date><DueDate>2008-10-20T00:00:00</DueDate><InvoiceNumber>INV-0001</InvoiceNumber><Reference/><IncludesTax>true</IncludesTax><SubTotal>1000.0000</SubTotal><TotalTax>125.0000</TotalTax><Total>1125.0000</Total><InvoiceStatus>AUTHORISED</InvoiceStatus><LineItems/></Invoice></Invoices></Response>
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<Response xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
|
2
|
+
<Id>e3431899-bf76-41e8-a919-4c8c923feb12</Id>
|
3
|
+
<Status>OK</Status>
|
4
|
+
<DateTimeUTC>2009-10-04T03:26:26.6994434Z</DateTimeUTC>
|
5
|
+
<Organisations>
|
6
|
+
<Organisation>
|
7
|
+
<Name>Demo Company (NZ)</Name>
|
8
|
+
<LegalName>Demo Company (NZ)</LegalName>
|
9
|
+
<PaysTax>true</PaysTax>
|
10
|
+
<Version>NZ</Version>
|
11
|
+
<BaseCurrency>NZD</BaseCurrency>
|
12
|
+
</Organisation>
|
13
|
+
</Organisations>
|
14
|
+
</Response>
|
@@ -0,0 +1,52 @@
|
|
1
|
+
<Response xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
|
2
|
+
<Id>ace3dea1-4025-48cf-a91f-50759c32653e</Id>
|
3
|
+
<Status>OK</Status>
|
4
|
+
<ProviderName>Xero Gateway Test</ProviderName>
|
5
|
+
<DateTimeUTC>2009-10-04T03:29:54.6788414Z</DateTimeUTC>
|
6
|
+
<TaxRates>
|
7
|
+
<TaxRate>
|
8
|
+
<Name>GST on Expenses</Name>
|
9
|
+
<TaxType>INPUT</TaxType>
|
10
|
+
<CanApplyToAssets>true</CanApplyToAssets>
|
11
|
+
<CanApplyToEquity>true</CanApplyToEquity>
|
12
|
+
<CanApplyToExpenses>true</CanApplyToExpenses>
|
13
|
+
<CanApplyToLiabilities>true</CanApplyToLiabilities>
|
14
|
+
<CanApplyToRevenue>false</CanApplyToRevenue>
|
15
|
+
<DisplayTaxRate>12.5000</DisplayTaxRate>
|
16
|
+
<EffectiveRate>12.5000</EffectiveRate>
|
17
|
+
</TaxRate>
|
18
|
+
<TaxRate>
|
19
|
+
<Name>GST on Income</Name>
|
20
|
+
<TaxType>OUTPUT</TaxType>
|
21
|
+
<CanApplyToAssets>true</CanApplyToAssets>
|
22
|
+
<CanApplyToEquity>true</CanApplyToEquity>
|
23
|
+
<CanApplyToExpenses>false</CanApplyToExpenses>
|
24
|
+
<CanApplyToLiabilities>true</CanApplyToLiabilities>
|
25
|
+
<CanApplyToRevenue>true</CanApplyToRevenue>
|
26
|
+
<DisplayTaxRate>12.5000</DisplayTaxRate>
|
27
|
+
<EffectiveRate>12.5000</EffectiveRate>
|
28
|
+
</TaxRate>
|
29
|
+
<TaxRate>
|
30
|
+
<Name>No GST</Name>
|
31
|
+
<TaxType>NONE</TaxType>
|
32
|
+
<CanApplyToAssets>true</CanApplyToAssets>
|
33
|
+
<CanApplyToEquity>true</CanApplyToEquity>
|
34
|
+
<CanApplyToExpenses>true</CanApplyToExpenses>
|
35
|
+
<CanApplyToLiabilities>true</CanApplyToLiabilities>
|
36
|
+
<CanApplyToRevenue>true</CanApplyToRevenue>
|
37
|
+
<DisplayTaxRate>0.0000</DisplayTaxRate>
|
38
|
+
<EffectiveRate>0.0000</EffectiveRate>
|
39
|
+
</TaxRate>
|
40
|
+
<TaxRate>
|
41
|
+
<Name>Zero Rated</Name>
|
42
|
+
<TaxType>ZERORATED</TaxType>
|
43
|
+
<CanApplyToAssets>false</CanApplyToAssets>
|
44
|
+
<CanApplyToEquity>false</CanApplyToEquity>
|
45
|
+
<CanApplyToExpenses>false</CanApplyToExpenses>
|
46
|
+
<CanApplyToLiabilities>false</CanApplyToLiabilities>
|
47
|
+
<CanApplyToRevenue>true</CanApplyToRevenue>
|
48
|
+
<DisplayTaxRate>0.0000</DisplayTaxRate>
|
49
|
+
<EffectiveRate>0.0000</EffectiveRate>
|
50
|
+
</TaxRate>
|
51
|
+
</TaxRates>
|
52
|
+
</Response>
|
@@ -0,0 +1 @@
|
|
1
|
+
oauth_problem=token_expired&oauth_problem_advice=Unexpected%20token
|
@@ -0,0 +1 @@
|
|
1
|
+
<?xml version="1.0"?><Response><ID>89a1d50c-f528-470c-b924-c10281ff67d6</ID><Status>OK</Status><ProviderName>XeroTest</ProviderName><DateTimeUTC>2008-04-20T20:16:51.7072529Z</DateTimeUTC><TrackingCategories><TrackingCategory><Name>Activity/Workstream</Name><Options><Option><Name>Documentation</Name></Option><Option><Name>Onsite consultancy</Name></Option><Option><Name>Publications</Name></Option><Option><Name>Support</Name></Option><Option><Name>Training</Name></Option><Option><Name>Website management</Name></Option></Options></TrackingCategory><TrackingCategory><Name>Consultant/Sales person</Name><Options><Option><Name>Felix Wilson</Name></Option><Option><Name>Martin Hudson</Name></Option><Option><Name>Orlena Greenville</Name></Option></Options></TrackingCategory></TrackingCategories></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
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
require "rubygems"
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
require 'mocha'
|
5
|
+
require 'shoulda'
|
6
|
+
|
7
|
+
require 'libxml'
|
8
|
+
|
9
|
+
require File.dirname(__FILE__) + '/../lib/xero_gateway.rb'
|
10
|
+
|
11
|
+
module TestHelper
|
12
|
+
# The integration tests can be run against the Xero test environment. You mush have a company set up in the test
|
13
|
+
# environment, and you must have set up a customer key for that account.
|
14
|
+
#
|
15
|
+
# You can then run the tests against the test environment using the commands (linux or mac):
|
16
|
+
# export STUB_XERO_CALLS=false
|
17
|
+
# rake test
|
18
|
+
# (this probably won't work under OAuth?)
|
19
|
+
#
|
20
|
+
|
21
|
+
STUB_XERO_CALLS = ENV["STUB_XERO_CALLS"].nil? ? true : (ENV["STUB_XERO_CALLS"] == "true") unless defined? STUB_XERO_CALLS
|
22
|
+
|
23
|
+
CONSUMER_KEY = ENV["CONSUMER_KEY"] || "fake_key" unless defined?(CONSUMER_KEY)
|
24
|
+
CONSUMER_SECRET = ENV["CONSUMER_SECRET"] || "fake_secret" unless defined?(CONSUMER_SECRET)
|
25
|
+
|
26
|
+
# Helper constant for checking regex
|
27
|
+
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)
|
28
|
+
|
29
|
+
|
30
|
+
def dummy_invoice(with_line_items = true)
|
31
|
+
invoice = XeroGateway::Invoice.new({
|
32
|
+
:invoice_type => "ACCREC",
|
33
|
+
:date => Time.now,
|
34
|
+
:due_date => Date.today + 20,
|
35
|
+
:invoice_number => STUB_XERO_CALLS ? "INV-0001" : "#{Time.now.to_f}",
|
36
|
+
:reference => "YOUR REFERENCE (NOT NECESSARILY UNIQUE!)",
|
37
|
+
:line_items_downloaded => with_line_items
|
38
|
+
})
|
39
|
+
invoice.contact = dummy_contact
|
40
|
+
if with_line_items
|
41
|
+
invoice.line_items << XeroGateway::LineItem.new(
|
42
|
+
:description => "THE DESCRIPTION OF THE LINE ITEM",
|
43
|
+
:unit_amount => 1000,
|
44
|
+
:tax_amount => 125,
|
45
|
+
:tracking => [
|
46
|
+
XeroGateway::TrackingCategory.new(:name => "THE FIRST TRACKING CATEGORY FOR THE LINE ITEM", :options => ["a", "b"]),
|
47
|
+
XeroGateway::TrackingCategory.new(:name => "THE SECOND TRACKING CATEGORY FOR THE LINE ITEM", :options => "c")
|
48
|
+
]
|
49
|
+
)
|
50
|
+
end
|
51
|
+
invoice
|
52
|
+
end
|
53
|
+
|
54
|
+
def dummy_contact
|
55
|
+
unique_id = Time.now.to_f
|
56
|
+
contact = XeroGateway::Contact.new(:name => STUB_XERO_CALLS ? "CONTACT NAME" : "THE NAME OF THE CONTACT #{unique_id}")
|
57
|
+
contact.email = "bob#{unique_id}@example.com"
|
58
|
+
contact.phone.number = "12345"
|
59
|
+
contact.address.line_1 = "LINE 1 OF THE ADDRESS"
|
60
|
+
contact.address.line_2 = "LINE 2 OF THE ADDRESS"
|
61
|
+
contact.address.line_3 = "LINE 3 OF THE ADDRESS"
|
62
|
+
contact.address.line_4 = "LINE 4 OF THE ADDRESS"
|
63
|
+
contact.address.city = "WELLINGTON"
|
64
|
+
contact.address.region = "WELLINGTON"
|
65
|
+
contact.address.country = "NEW ZEALAND"
|
66
|
+
contact.address.post_code = "6021"
|
67
|
+
|
68
|
+
contact
|
69
|
+
end
|
70
|
+
|
71
|
+
def get_file_as_string(filename)
|
72
|
+
data = ''
|
73
|
+
f = File.open(File.dirname(__FILE__) + "/stub_responses/" + filename, "r")
|
74
|
+
f.each_line do |line|
|
75
|
+
data += line
|
76
|
+
end
|
77
|
+
f.close
|
78
|
+
return data
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '../test_helper.rb')
|
2
|
+
|
3
|
+
class AccountTest < Test::Unit::TestCase
|
4
|
+
# Tests that an account can be converted into XML that Xero can understand, and then converted back to an account
|
5
|
+
def test_build_and_parse_xml
|
6
|
+
account = create_test_account
|
7
|
+
|
8
|
+
# Generate the XML message
|
9
|
+
account_as_xml = account.to_xml
|
10
|
+
|
11
|
+
# Parse the XML message and retrieve the account element
|
12
|
+
account_element = REXML::XPath.first(REXML::Document.new(account_as_xml), "/Account")
|
13
|
+
|
14
|
+
# Build a new account from the XML
|
15
|
+
result_account = XeroGateway::Account.from_xml(account_element)
|
16
|
+
|
17
|
+
# Check the account details
|
18
|
+
assert_equal account, result_account
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def create_test_account
|
25
|
+
account = XeroGateway::Account.new
|
26
|
+
account.code = "200"
|
27
|
+
account.name = "Sales"
|
28
|
+
account.type = "REVENUE"
|
29
|
+
account.tax_type = "OUTPUT"
|
30
|
+
account.description = "Income from any normal business activity"
|
31
|
+
|
32
|
+
account
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '../test_helper.rb')
|
2
|
+
|
3
|
+
class ContactTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@schema = LibXML::XML::Schema.document(LibXML::XML::Document.file(File.join(File.dirname(__FILE__), '../xsd/create_contact.xsd')))
|
6
|
+
end
|
7
|
+
|
8
|
+
# Tests that the XML generated from a contact object validates against the Xero XSD
|
9
|
+
def test_build_xml
|
10
|
+
contact = create_test_contact
|
11
|
+
|
12
|
+
message = contact.to_xml
|
13
|
+
|
14
|
+
# Check that the document matches the XSD
|
15
|
+
assert LibXML::XML::Parser.string(message).parse.validate_schema(@schema), "The XML document generated did not validate against the XSD"
|
16
|
+
end
|
17
|
+
|
18
|
+
# Tests that a contact can be converted into XML that Xero can understand, and then converted back to a contact
|
19
|
+
def test_build_and_parse_xml
|
20
|
+
contact = create_test_contact
|
21
|
+
|
22
|
+
# Generate the XML message
|
23
|
+
contact_as_xml = contact.to_xml
|
24
|
+
|
25
|
+
# Parse the XML message and retrieve the contact element
|
26
|
+
contact_element = REXML::XPath.first(REXML::Document.new(contact_as_xml), "/Contact")
|
27
|
+
|
28
|
+
# Build a new contact from the XML
|
29
|
+
result_contact = XeroGateway::Contact.from_xml(contact_element)
|
30
|
+
|
31
|
+
# Check the contact details
|
32
|
+
assert_equal contact, result_contact
|
33
|
+
end
|
34
|
+
|
35
|
+
# Test Contact#add_address helper creates a valid XeroGateway::Contact object with the passed in values
|
36
|
+
# and appends it to the Contact#addresses attribute.
|
37
|
+
def test_add_address_helper
|
38
|
+
contact = create_test_contact
|
39
|
+
assert_equal(1, contact.addresses.size)
|
40
|
+
|
41
|
+
new_values = {
|
42
|
+
:address_type => 'POBOX',
|
43
|
+
:line_1 => 'NEW LINE 1',
|
44
|
+
:line_2 => 'NEW LINE 2',
|
45
|
+
:line_3 => 'NEW LINE 3',
|
46
|
+
:line_4 => 'NEW LINE 4',
|
47
|
+
:city => 'NEW CITY',
|
48
|
+
:region => 'NEW REGION',
|
49
|
+
:post_code => '5555',
|
50
|
+
:country => 'Australia'
|
51
|
+
}
|
52
|
+
contact.add_address(new_values)
|
53
|
+
|
54
|
+
assert_equal(2, contact.addresses.size)
|
55
|
+
assert_kind_of(XeroGateway::Address, contact.addresses.last)
|
56
|
+
new_values.each { |k,v| assert_equal(v, contact.addresses.last.send("#{k}")) }
|
57
|
+
end
|
58
|
+
|
59
|
+
# Test Contact#add_phone helper creates a valid XeroGateway::Phone object with the passed in values
|
60
|
+
# and appends it to the Contact#phones attribute.
|
61
|
+
def test_add_address_helper
|
62
|
+
contact = create_test_contact
|
63
|
+
assert_equal(1, contact.phones.size)
|
64
|
+
|
65
|
+
new_values = {
|
66
|
+
:phone_type => 'MOBILE',
|
67
|
+
:country_code => '61',
|
68
|
+
:area_code => '406',
|
69
|
+
:number => '123456'
|
70
|
+
}
|
71
|
+
contact.add_phone(new_values)
|
72
|
+
|
73
|
+
assert_equal(2, contact.phones.size)
|
74
|
+
assert_kind_of(XeroGateway::Phone, contact.phones.last)
|
75
|
+
new_values.each { |k,v| assert_equal(v, contact.phones.last.send("#{k}")) }
|
76
|
+
end
|
77
|
+
|
78
|
+
|
79
|
+
private
|
80
|
+
|
81
|
+
def create_test_contact
|
82
|
+
contact = XeroGateway::Contact.new(:contact_id => "55555")
|
83
|
+
contact.contact_number = "aaa111"
|
84
|
+
contact.name = "CONTACT NAME"
|
85
|
+
contact.email = "someone@somewhere.com"
|
86
|
+
contact.address.address_type = "THE ADDRESS TYPE FOR THE CONTACT"
|
87
|
+
contact.address.line_1 = "LINE 1 OF THE ADDRESS"
|
88
|
+
contact.address.line_2 = "LINE 2 OF THE ADDRESS"
|
89
|
+
contact.address.line_3 = "LINE 3 OF THE ADDRESS"
|
90
|
+
contact.address.line_4 = "LINE 4 OF THE ADDRESS"
|
91
|
+
contact.phone.number = "12345"
|
92
|
+
contact.is_customer = true
|
93
|
+
contact.is_supplier = true
|
94
|
+
|
95
|
+
contact
|
96
|
+
end
|
97
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '../test_helper.rb')
|
2
|
+
|
3
|
+
class CurrencyTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
# Tests that a currency can be converted into XML that Xero can understand, and then converted back to a currency
|
6
|
+
def test_build_and_parse_xml
|
7
|
+
currency = create_test_currency
|
8
|
+
|
9
|
+
# Generate the XML message
|
10
|
+
currency_as_xml = currency.to_xml
|
11
|
+
|
12
|
+
# Parse the XML message and retrieve the account element
|
13
|
+
currency_element = REXML::XPath.first(REXML::Document.new(currency_as_xml), "/Currency")
|
14
|
+
|
15
|
+
# Build a new account from the XML
|
16
|
+
result_currency = XeroGateway::Currency.from_xml(currency_element)
|
17
|
+
|
18
|
+
# Check the account details
|
19
|
+
assert_equal currency, result_currency
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def create_test_currency
|
26
|
+
XeroGateway::Currency.new.tap do |currency|
|
27
|
+
currency.code = "NZD"
|
28
|
+
currency.description = "New Zealand Dollar"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,79 @@
|
|
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(CONSUMER_KEY, CONSUMER_SECRET)
|
8
|
+
end
|
9
|
+
|
10
|
+
context "with oauth error handling" do
|
11
|
+
|
12
|
+
should "handle token expired" do
|
13
|
+
XeroGateway::OAuth.any_instance.stubs(:get).returns(stub(:plain_body => get_file_as_string("token_expired"), :code => "401"))
|
14
|
+
|
15
|
+
assert_raises XeroGateway::OAuth::TokenExpired do
|
16
|
+
@gateway.get_accounts
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
should "handle invalid request tokens" do
|
21
|
+
XeroGateway::OAuth.any_instance.stubs(:http_get).returns(stub(:plain_body => get_file_as_string("invalid_request_token"), :code => "401"))
|
22
|
+
|
23
|
+
assert_raises XeroGateway::OAuth::TokenInvalid do
|
24
|
+
@gateway.get_accounts
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
should "handle invalid consumer key" do
|
29
|
+
XeroGateway::OAuth.any_instance.stubs(:http_get).returns(stub(:plain_body => get_file_as_string("invalid_consumer_key"), :code => "401"))
|
30
|
+
|
31
|
+
assert_raises XeroGateway::OAuth::TokenInvalid do
|
32
|
+
@gateway.get_accounts
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
should "handle ApiExceptions" do
|
37
|
+
XeroGateway::OAuth.any_instance.stubs(:put).returns(stub(:plain_body => get_file_as_string("api_exception.xml"), :code => "400"))
|
38
|
+
|
39
|
+
assert_raises XeroGateway::ApiException do
|
40
|
+
@gateway.create_invoice(XeroGateway::Invoice.new)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
should "handle random root elements" do
|
45
|
+
XeroGateway::OAuth.any_instance.stubs(:put).returns(stub(:plain_body => "<RandomRootElement></RandomRootElement>", :code => "200"))
|
46
|
+
|
47
|
+
assert_raises XeroGateway::UnparseableResponse do
|
48
|
+
@gateway.create_invoice(XeroGateway::Invoice.new)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_unknown_error_handling
|
55
|
+
if STUB_XERO_CALLS
|
56
|
+
@gateway.xero_url = "DUMMY_URL"
|
57
|
+
@gateway.stubs(:http_get).with {|client, url, params| url =~ /Invoices\/AN_INVALID_ID$/ }.returns(get_file_as_string("unknown_error.xml"))
|
58
|
+
end
|
59
|
+
|
60
|
+
result = @gateway.get_invoice("AN_INVALID_ID")
|
61
|
+
assert !result.success?
|
62
|
+
assert_equal 1, result.errors.size
|
63
|
+
assert !result.errors.first.type.nil?
|
64
|
+
assert !result.errors.first.description.nil?
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_object_not_found_error_handling
|
68
|
+
if STUB_XERO_CALLS
|
69
|
+
@gateway.xero_url = "DUMMY_URL"
|
70
|
+
@gateway.stubs(:http_get).with {|client, url, params| url =~ /Invoices\/UNKNOWN_INVOICE_NO$/ }.returns(get_file_as_string("invoice_not_found_error.xml"))
|
71
|
+
end
|
72
|
+
|
73
|
+
result = @gateway.get_invoice("UNKNOWN_INVOICE_NO")
|
74
|
+
assert !result.success?
|
75
|
+
assert_equal 1, result.errors.size
|
76
|
+
assert_equal "Xero.API.Library.Exceptions.ObjectDoesNotExistException", result.errors.first.type
|
77
|
+
assert !result.errors.first.description.nil?
|
78
|
+
end
|
79
|
+
end
|