tlconnor-xero_gateway 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.textile +3 -2
- data/README.textile +27 -9
- data/lib/xero_gateway/account.rb +2 -17
- data/lib/xero_gateway/address.rb +2 -17
- data/lib/xero_gateway/contact.rb +4 -19
- data/lib/xero_gateway/dates.rb +0 -14
- data/lib/xero_gateway/gateway.rb +1 -15
- data/lib/xero_gateway/http.rb +2 -16
- data/lib/xero_gateway/invoice.rb +4 -20
- data/lib/xero_gateway/line_item.rb +4 -19
- data/lib/xero_gateway/messages/account_message.rb +1 -15
- data/lib/xero_gateway/messages/contact_message.rb +2 -16
- data/lib/xero_gateway/messages/invoice_message.rb +3 -17
- data/lib/xero_gateway/money.rb +0 -14
- data/lib/xero_gateway/phone.rb +2 -17
- data/lib/xero_gateway/response.rb +1 -15
- data/lib/xero_gateway.rb +0 -14
- data/test/integration/stub_responses/contact.xml +1 -1
- data/test/integration/stub_responses/contacts.xml +1 -1
- data/test/test_helper.rb +1 -14
- data/test/unit/messages/contact_message_test.rb +1 -15
- data/test/unit/messages/invoice_message_test.rb +2 -15
- data/xero_gateway.gemspec +1 -1
- metadata +1 -1
- data/test/integration/gateway_test.rb +0 -166
data/CHANGELOG.textile
CHANGED
@@ -1,6 +1,7 @@
|
|
1
|
-
h2. 1.0.1, releases
|
1
|
+
h2. 1.0.1, releases 02/12/2008
|
2
2
|
|
3
|
-
|
3
|
+
* Added implementation of GET /api.xro/1.0/accounts
|
4
|
+
* Replaced Invoice.id, Contact.id etc with Invoice.invoice_id, Contact.contact_id to avoid Object.id errors
|
4
5
|
|
5
6
|
|
6
7
|
h2. 1.0.0, released 01/12/2008
|
data/README.textile
CHANGED
@@ -20,31 +20,39 @@ h2. Usage
|
|
20
20
|
|
21
21
|
h2. Implemented interface methods
|
22
22
|
|
23
|
+
|
24
|
+
|
23
25
|
h3. GET /api.xro/1.0/contact (get_contact_by_id)
|
24
26
|
|
25
|
-
|
27
|
+
Gets a contact record for a specific Xero organisation
|
26
28
|
<pre><code>
|
27
29
|
result = gateway.get_contact_by_id(contact_id)
|
28
30
|
contact = result.contact if result.success?
|
29
31
|
</code></pre>
|
30
32
|
|
33
|
+
|
34
|
+
|
31
35
|
h3. GET /api.xro/1.0/contact (get_contact_by_number)
|
32
36
|
|
33
|
-
|
37
|
+
Gets a contact record for a specific Xero organisation
|
34
38
|
<pre><code>
|
35
39
|
gateway.get_contact_by_number(contact_number)
|
36
40
|
</code></pre>
|
37
41
|
|
42
|
+
|
43
|
+
|
38
44
|
h3. GET /api.xro/1.0/contacts (get_contacts)
|
39
45
|
|
40
|
-
|
46
|
+
Gets all contact records for a particular Xero customer.
|
41
47
|
<pre><code>
|
42
48
|
gateway.get_contacts(:type => :all, :sort => :name, :direction => :desc)
|
43
49
|
</code></pre>
|
44
50
|
|
51
|
+
|
52
|
+
|
45
53
|
h3. PUT /api.xro/1.0/contact
|
46
54
|
|
47
|
-
|
55
|
+
Saves a contact record for a particular Xero customer. If the contact record does not exist (based on either ContactID or ContactNumber) then it’s created, otherwise it’s updated.
|
48
56
|
<pre><code>
|
49
57
|
contact = XeroGateway::Contact.new
|
50
58
|
contact.name = "The contacts name"
|
@@ -60,30 +68,38 @@ Example:
|
|
60
68
|
gateway.create_contact(contact)
|
61
69
|
</code></pre>
|
62
70
|
|
71
|
+
|
72
|
+
|
63
73
|
h3. GET /api.xro/1.0/invoice (get_invoice_by_id)
|
64
74
|
|
65
|
-
|
75
|
+
Gets an invoice record for a specific Xero organisation
|
66
76
|
<pre><code>
|
67
77
|
gateway.get_invoice_by_id(invoice_id)
|
68
78
|
</code></pre>
|
69
79
|
|
80
|
+
|
81
|
+
|
70
82
|
h3. GET /api.xro/1.0/invoice (get_invoice_by_number)
|
71
83
|
|
72
|
-
|
84
|
+
Gets an invoice record for a specific Xero organisation
|
73
85
|
<pre><code>
|
74
86
|
gateway.get_invoice_by_number(invoice_number)
|
75
87
|
</code></pre>
|
76
88
|
|
89
|
+
|
90
|
+
|
77
91
|
h3. GET /api.xro/1.0/invoices (get_invoices)
|
78
92
|
|
79
|
-
|
93
|
+
Gets all invoice records for a particular Xero customer.
|
80
94
|
<pre><code>
|
81
95
|
gateway.get_invoices(modified_since = nil)
|
82
96
|
</code></pre>
|
83
97
|
|
98
|
+
|
99
|
+
|
84
100
|
h3. PUT /api.xro/1.0/invoice
|
85
101
|
|
86
|
-
|
102
|
+
Inserts an invoice for a specific organization in Xero. (Currently only adding new invoices is allowed).
|
87
103
|
<pre><code>
|
88
104
|
invoice = XeroGateway::Invoice.new({
|
89
105
|
:invoice_type => "ACCREC",
|
@@ -111,9 +127,11 @@ Example:
|
|
111
127
|
gateway.create_invoice(invoice)
|
112
128
|
</code></pre>
|
113
129
|
|
130
|
+
|
131
|
+
|
114
132
|
h3. GET /api.xro/1.0/accounts
|
115
133
|
|
116
|
-
|
134
|
+
Gets all accounts for a specific organization in Xero.
|
117
135
|
<pre><code>
|
118
136
|
gateway.get_accounts
|
119
137
|
</code></pre>
|
data/lib/xero_gateway/account.rb
CHANGED
@@ -1,17 +1,3 @@
|
|
1
|
-
# Copyright (c) 2008 Tim Connor <tlconnor@gmail.com>
|
2
|
-
#
|
3
|
-
# Permission to use, copy, modify, and/or distribute this software for any
|
4
|
-
# purpose with or without fee is hereby granted, provided that the above
|
5
|
-
# copyright notice and this permission notice appear in all copies.
|
6
|
-
#
|
7
|
-
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
8
|
-
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
9
|
-
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
10
|
-
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
11
|
-
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
12
|
-
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
13
|
-
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
14
|
-
|
15
1
|
module XeroGateway
|
16
2
|
class Account
|
17
3
|
attr_accessor :code, :name, :type, :tax_type, :description
|
@@ -24,11 +10,10 @@ module XeroGateway
|
|
24
10
|
end
|
25
11
|
|
26
12
|
def ==(other)
|
27
|
-
equal = true
|
28
13
|
[:code, :name, :type, :tax_type, :description].each do |field|
|
29
|
-
|
14
|
+
return false if send(field) != other.send(field)
|
30
15
|
end
|
31
|
-
return
|
16
|
+
return true
|
32
17
|
end
|
33
18
|
end
|
34
19
|
end
|
data/lib/xero_gateway/address.rb
CHANGED
@@ -1,17 +1,3 @@
|
|
1
|
-
# Copyright (c) 2008 Tim Connor <tlconnor@gmail.com>
|
2
|
-
#
|
3
|
-
# Permission to use, copy, modify, and/or distribute this software for any
|
4
|
-
# purpose with or without fee is hereby granted, provided that the above
|
5
|
-
# copyright notice and this permission notice appear in all copies.
|
6
|
-
#
|
7
|
-
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
8
|
-
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
9
|
-
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
10
|
-
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
11
|
-
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
12
|
-
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
13
|
-
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
14
|
-
|
15
1
|
module XeroGateway
|
16
2
|
class Address
|
17
3
|
attr_accessor :address_type, :line_1, :line_2, :line_3, :line_4, :city, :region, :post_code, :country
|
@@ -37,11 +23,10 @@ module XeroGateway
|
|
37
23
|
end
|
38
24
|
|
39
25
|
def ==(other)
|
40
|
-
equal = true
|
41
26
|
[:address_type, :line_1, :line_2, :line_3, :line_4, :city, :region, :post_code, :country].each do |field|
|
42
|
-
|
27
|
+
return false if send(field) != other.send(field)
|
43
28
|
end
|
44
|
-
return
|
29
|
+
return true
|
45
30
|
end
|
46
31
|
end
|
47
32
|
end
|
data/lib/xero_gateway/contact.rb
CHANGED
@@ -1,20 +1,6 @@
|
|
1
|
-
# Copyright (c) 2008 Tim Connor <tlconnor@gmail.com>
|
2
|
-
#
|
3
|
-
# Permission to use, copy, modify, and/or distribute this software for any
|
4
|
-
# purpose with or without fee is hereby granted, provided that the above
|
5
|
-
# copyright notice and this permission notice appear in all copies.
|
6
|
-
#
|
7
|
-
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
8
|
-
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
9
|
-
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
10
|
-
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
11
|
-
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
12
|
-
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
13
|
-
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
14
|
-
|
15
1
|
module XeroGateway
|
16
2
|
class Contact
|
17
|
-
attr_accessor :
|
3
|
+
attr_accessor :contact_id, :contact_number, :status, :name, :email, :addresses, :phones, :updated_at
|
18
4
|
|
19
5
|
def initialize(params = {})
|
20
6
|
params = {}.merge(params)
|
@@ -44,11 +30,10 @@ module XeroGateway
|
|
44
30
|
end
|
45
31
|
|
46
32
|
def ==(other)
|
47
|
-
equal = true
|
48
33
|
[:contact_number, :status, :name, :email, :addresses, :phones].each do |field|
|
49
|
-
|
34
|
+
return false if send(field) != other.send(field)
|
50
35
|
end
|
51
|
-
return
|
36
|
+
return true
|
52
37
|
end
|
53
38
|
end
|
54
|
-
end
|
39
|
+
end
|
data/lib/xero_gateway/dates.rb
CHANGED
@@ -1,17 +1,3 @@
|
|
1
|
-
# Copyright (c) 2008 Tim Connor <tlconnor@gmail.com>
|
2
|
-
#
|
3
|
-
# Permission to use, copy, modify, and/or distribute this software for any
|
4
|
-
# purpose with or without fee is hereby granted, provided that the above
|
5
|
-
# copyright notice and this permission notice appear in all copies.
|
6
|
-
#
|
7
|
-
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
8
|
-
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
9
|
-
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
10
|
-
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
11
|
-
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
12
|
-
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
13
|
-
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
14
|
-
|
15
1
|
module XeroGateway
|
16
2
|
module Dates
|
17
3
|
def self.included(base)
|
data/lib/xero_gateway/gateway.rb
CHANGED
@@ -1,17 +1,3 @@
|
|
1
|
-
# Copyright (c) 2008 Tim Connor <tlconnor@gmail.com>
|
2
|
-
#
|
3
|
-
# Permission to use, copy, modify, and/or distribute this software for any
|
4
|
-
# purpose with or without fee is hereby granted, provided that the above
|
5
|
-
# copyright notice and this permission notice appear in all copies.
|
6
|
-
#
|
7
|
-
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
8
|
-
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
9
|
-
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
10
|
-
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
11
|
-
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
12
|
-
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
13
|
-
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
14
|
-
|
15
1
|
module XeroGateway
|
16
2
|
class Gateway
|
17
3
|
include Http
|
@@ -260,7 +246,7 @@ module XeroGateway
|
|
260
246
|
|
261
247
|
def build_response(response_document)
|
262
248
|
response = XeroGateway::Response.new({
|
263
|
-
:
|
249
|
+
:response_id => REXML::XPath.first(response_document, "/Response/ID").text,
|
264
250
|
:status => REXML::XPath.first(response_document, "/Response/Status").text,
|
265
251
|
:provider => REXML::XPath.first(response_document, "/Response/ProviderName").text,
|
266
252
|
:date_time => REXML::XPath.first(response_document, "/Response/DateTimeUTC").text,
|
data/lib/xero_gateway/http.rb
CHANGED
@@ -1,21 +1,7 @@
|
|
1
|
-
# Copyright (c) 2008 Tim Connor <tlconnor@gmail.com>
|
2
|
-
#
|
3
|
-
# Permission to use, copy, modify, and/or distribute this software for any
|
4
|
-
# purpose with or without fee is hereby granted, provided that the above
|
5
|
-
# copyright notice and this permission notice appear in all copies.
|
6
|
-
#
|
7
|
-
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
8
|
-
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
9
|
-
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
10
|
-
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
11
|
-
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
12
|
-
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
13
|
-
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
14
|
-
|
15
1
|
module XeroGateway
|
16
2
|
module Http
|
17
|
-
OPEN_TIMEOUT = 10
|
18
|
-
READ_TIMEOUT = 60
|
3
|
+
OPEN_TIMEOUT = 10 unless defined? OPEN_TIMEOUT
|
4
|
+
READ_TIMEOUT = 60 unless defined? READ_TIMEOUT
|
19
5
|
|
20
6
|
def http_get(url, extra_params = {})
|
21
7
|
params = {:apiKey => @api_key, :xeroKey => @customer_key}
|
data/lib/xero_gateway/invoice.rb
CHANGED
@@ -1,21 +1,7 @@
|
|
1
|
-
# Copyright (c) 2008 Tim Connor <tlconnor@gmail.com>
|
2
|
-
#
|
3
|
-
# Permission to use, copy, modify, and/or distribute this software for any
|
4
|
-
# purpose with or without fee is hereby granted, provided that the above
|
5
|
-
# copyright notice and this permission notice appear in all copies.
|
6
|
-
#
|
7
|
-
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
8
|
-
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
9
|
-
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
10
|
-
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
11
|
-
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
12
|
-
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
13
|
-
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
14
|
-
|
15
1
|
module XeroGateway
|
16
2
|
class Invoice
|
17
3
|
# All accessible fields
|
18
|
-
attr_accessor :
|
4
|
+
attr_accessor :invoice_id, :invoice_number, :invoice_type, :invoice_status, :date, :due_date, :reference, :tax_inclusive, :includes_tax, :sub_total, :total_tax, :total, :line_items, :contact
|
19
5
|
|
20
6
|
def initialize(params = {})
|
21
7
|
params = {
|
@@ -34,15 +20,13 @@ module XeroGateway
|
|
34
20
|
end
|
35
21
|
|
36
22
|
def ==(other)
|
37
|
-
equal = true
|
38
23
|
["invoice_number", "invoice_type", "invoice_status", "reference", "tax_inclusive", "includes_tax", "sub_total", "total_tax", "total", "contact", "line_items"].each do |field|
|
39
|
-
|
24
|
+
return false if send(field) != other.send(field)
|
40
25
|
end
|
41
26
|
["date", "due_date"].each do |field|
|
42
|
-
|
27
|
+
return false if send(field).to_s != other.send(field).to_s
|
43
28
|
end
|
44
|
-
|
45
|
-
return equal
|
29
|
+
return true
|
46
30
|
end
|
47
31
|
end
|
48
32
|
end
|
@@ -1,21 +1,7 @@
|
|
1
|
-
# Copyright (c) 2008 Tim Connor <tlconnor@gmail.com>
|
2
|
-
#
|
3
|
-
# Permission to use, copy, modify, and/or distribute this software for any
|
4
|
-
# purpose with or without fee is hereby granted, provided that the above
|
5
|
-
# copyright notice and this permission notice appear in all copies.
|
6
|
-
#
|
7
|
-
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
8
|
-
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
9
|
-
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
10
|
-
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
11
|
-
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
12
|
-
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
13
|
-
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
14
|
-
|
15
1
|
module XeroGateway
|
16
2
|
class LineItem
|
17
3
|
# All accessible fields
|
18
|
-
attr_accessor :
|
4
|
+
attr_accessor :line_item_id, :description, :quantity, :unit_amount, :tax_type, :tax_amount, :line_amount, :account_code, :tracking_category, :tracking_option
|
19
5
|
|
20
6
|
def initialize(params = {})
|
21
7
|
params = {
|
@@ -29,12 +15,11 @@ module XeroGateway
|
|
29
15
|
end
|
30
16
|
|
31
17
|
def ==(other)
|
32
|
-
return true
|
33
|
-
equal = true
|
34
18
|
[:description, :quantity, :unit_amount, :tax_type, :tax_amount, :line_amount, :account_code, :tracking_category, :tracking_option].each do |field|
|
35
|
-
|
19
|
+
puts field if send(field) != other.send(field)
|
20
|
+
return false if send(field) != other.send(field)
|
36
21
|
end
|
37
|
-
return
|
22
|
+
return true
|
38
23
|
end
|
39
24
|
end
|
40
25
|
end
|
@@ -1,17 +1,3 @@
|
|
1
|
-
# Copyright (c) 2008 Tim Connor <tlconnor@gmail.com>
|
2
|
-
#
|
3
|
-
# Permission to use, copy, modify, and/or distribute this software for any
|
4
|
-
# purpose with or without fee is hereby granted, provided that the above
|
5
|
-
# copyright notice and this permission notice appear in all copies.
|
6
|
-
#
|
7
|
-
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
8
|
-
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
9
|
-
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
10
|
-
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
11
|
-
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
12
|
-
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
13
|
-
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
14
|
-
|
15
1
|
module XeroGateway
|
16
2
|
module Messages
|
17
3
|
class AccountMessage
|
@@ -37,7 +23,7 @@ module XeroGateway
|
|
37
23
|
line_item = LineItem.new
|
38
24
|
line_item_element.children.each do |element|
|
39
25
|
case(element.name)
|
40
|
-
when "LineItemID" then line_item.
|
26
|
+
when "LineItemID" then line_item.line_item_id = element.text
|
41
27
|
when "Description" then line_item.description = element.text
|
42
28
|
when "Quantity" then line_item.quantity = element.text.to_i
|
43
29
|
when "UnitAmount" then line_item.unit_amount = BigDecimal.new(element.text)
|
@@ -1,17 +1,3 @@
|
|
1
|
-
# Copyright (c) 2008 Tim Connor <tlconnor@gmail.com>
|
2
|
-
#
|
3
|
-
# Permission to use, copy, modify, and/or distribute this software for any
|
4
|
-
# purpose with or without fee is hereby granted, provided that the above
|
5
|
-
# copyright notice and this permission notice appear in all copies.
|
6
|
-
#
|
7
|
-
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
8
|
-
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
9
|
-
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
10
|
-
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
11
|
-
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
12
|
-
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
13
|
-
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
14
|
-
|
15
1
|
module XeroGateway
|
16
2
|
module Messages
|
17
3
|
class ContactMessage
|
@@ -21,7 +7,7 @@ module XeroGateway
|
|
21
7
|
b = Builder::XmlMarkup.new
|
22
8
|
|
23
9
|
b.Contact {
|
24
|
-
b.ContactID contact.
|
10
|
+
b.ContactID contact.contact_id if contact.contact_id
|
25
11
|
b.ContactNumber contact.contact_number if contact.contact_number
|
26
12
|
b.Name contact.name
|
27
13
|
b.EmailAddress contact.email if contact.email
|
@@ -58,7 +44,7 @@ module XeroGateway
|
|
58
44
|
contact = Contact.new
|
59
45
|
contact_element.children.each do |element|
|
60
46
|
case(element.name)
|
61
|
-
when "ContactID" then contact.
|
47
|
+
when "ContactID" then contact.contact_id = element.text
|
62
48
|
when "ContactNumber" then contact.contact_number = element.text
|
63
49
|
when "ContactStatus" then contact.status = element.text
|
64
50
|
when "Name" then contact.name = element.text
|
@@ -1,17 +1,3 @@
|
|
1
|
-
# Copyright (c) 2008 Tim Connor <tlconnor@gmail.com>
|
2
|
-
#
|
3
|
-
# Permission to use, copy, modify, and/or distribute this software for any
|
4
|
-
# purpose with or without fee is hereby granted, provided that the above
|
5
|
-
# copyright notice and this permission notice appear in all copies.
|
6
|
-
#
|
7
|
-
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
8
|
-
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
9
|
-
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
10
|
-
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
11
|
-
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
12
|
-
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
13
|
-
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
14
|
-
|
15
1
|
module XeroGateway
|
16
2
|
module Messages
|
17
3
|
class InvoiceMessage
|
@@ -24,7 +10,7 @@ module XeroGateway
|
|
24
10
|
b.Invoice {
|
25
11
|
b.InvoiceType invoice.invoice_type
|
26
12
|
b.Contact {
|
27
|
-
b.ContactID invoice.contact.
|
13
|
+
b.ContactID invoice.contact.contact_id if invoice.contact.contact_id
|
28
14
|
b.Name invoice.contact.name
|
29
15
|
b.EmailAddress invoice.contact.email if invoice.contact.email
|
30
16
|
b.Addresses {
|
@@ -90,7 +76,7 @@ module XeroGateway
|
|
90
76
|
invoice_element.children.each do |element|
|
91
77
|
case(element.name)
|
92
78
|
when "InvoiceStatus" then invoice.invoice_status = element.text
|
93
|
-
when "InvoiceID" then invoice.
|
79
|
+
when "InvoiceID" then invoice.invoice_id = element.text
|
94
80
|
when "InvoiceNumber" then invoice.invoice_number = element.text
|
95
81
|
when "InvoiceType" then invoice.invoice_type = element.text
|
96
82
|
when "InvoiceDate" then invoice.date = parse_date_time(element.text)
|
@@ -114,7 +100,7 @@ module XeroGateway
|
|
114
100
|
line_item = LineItem.new
|
115
101
|
line_item_element.children.each do |element|
|
116
102
|
case(element.name)
|
117
|
-
when "LineItemID" then line_item.
|
103
|
+
when "LineItemID" then line_item.line_item_id = element.text
|
118
104
|
when "Description" then line_item.description = element.text
|
119
105
|
when "Quantity" then line_item.quantity = element.text.to_i
|
120
106
|
when "UnitAmount" then line_item.unit_amount = BigDecimal.new(element.text)
|
data/lib/xero_gateway/money.rb
CHANGED
@@ -1,17 +1,3 @@
|
|
1
|
-
# Copyright (c) 2008 Tim Connor <tlconnor@gmail.com>
|
2
|
-
#
|
3
|
-
# Permission to use, copy, modify, and/or distribute this software for any
|
4
|
-
# purpose with or without fee is hereby granted, provided that the above
|
5
|
-
# copyright notice and this permission notice appear in all copies.
|
6
|
-
#
|
7
|
-
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
8
|
-
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
9
|
-
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
10
|
-
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
11
|
-
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
12
|
-
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
13
|
-
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
14
|
-
|
15
1
|
module XeroGateway
|
16
2
|
module Money
|
17
3
|
def self.included(base)
|
data/lib/xero_gateway/phone.rb
CHANGED
@@ -1,17 +1,3 @@
|
|
1
|
-
# Copyright (c) 2008 Tim Connor <tlconnor@gmail.com>
|
2
|
-
#
|
3
|
-
# Permission to use, copy, modify, and/or distribute this software for any
|
4
|
-
# purpose with or without fee is hereby granted, provided that the above
|
5
|
-
# copyright notice and this permission notice appear in all copies.
|
6
|
-
#
|
7
|
-
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
8
|
-
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
9
|
-
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
10
|
-
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
11
|
-
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
12
|
-
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
13
|
-
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
14
|
-
|
15
1
|
module XeroGateway
|
16
2
|
class Phone
|
17
3
|
attr_accessor :phone_type, :number, :area_code, :country_code
|
@@ -28,11 +14,10 @@ module XeroGateway
|
|
28
14
|
end
|
29
15
|
|
30
16
|
def ==(other)
|
31
|
-
equal = true
|
32
17
|
[:phone_type, :number, :area_code, :country_code].each do |field|
|
33
|
-
|
18
|
+
return false if send(field) != other.send(field)
|
34
19
|
end
|
35
|
-
return
|
20
|
+
return true
|
36
21
|
end
|
37
22
|
end
|
38
23
|
end
|
@@ -1,20 +1,6 @@
|
|
1
|
-
# Copyright (c) 2008 Tim Connor <tlconnor@gmail.com>
|
2
|
-
#
|
3
|
-
# Permission to use, copy, modify, and/or distribute this software for any
|
4
|
-
# purpose with or without fee is hereby granted, provided that the above
|
5
|
-
# copyright notice and this permission notice appear in all copies.
|
6
|
-
#
|
7
|
-
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
8
|
-
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
9
|
-
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
10
|
-
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
11
|
-
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
12
|
-
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
13
|
-
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
14
|
-
|
15
1
|
module XeroGateway
|
16
2
|
class Response
|
17
|
-
attr_accessor :
|
3
|
+
attr_accessor :response_id, :status, :errors, :provider, :date_time, :response_item, :request_params, :request_xml, :response_xml
|
18
4
|
|
19
5
|
alias_method :invoice, :response_item
|
20
6
|
alias_method :invoices, :response_item
|
data/lib/xero_gateway.rb
CHANGED
@@ -1,17 +1,3 @@
|
|
1
|
-
# Copyright (c) 2008 Tim Connor <tlconnor@gmail.com>
|
2
|
-
#
|
3
|
-
# Permission to use, copy, modify, and/or distribute this software for any
|
4
|
-
# purpose with or without fee is hereby granted, provided that the above
|
5
|
-
# copyright notice and this permission notice appear in all copies.
|
6
|
-
#
|
7
|
-
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
8
|
-
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
9
|
-
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
10
|
-
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
11
|
-
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
12
|
-
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
13
|
-
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
14
|
-
|
15
1
|
require 'cgi'
|
16
2
|
require "uri"
|
17
3
|
require 'net/https'
|
@@ -1 +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-09T02:40:54.3997437Z</DateTimeUTC><Contact><ContactID>
|
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-09T02:40:54.3997437Z</DateTimeUTC><Contact><ContactID>e8d9ecd8-c17a-49c4-a445-708875ccb042</ContactID><ContactNumber>12345</ContactNumber><Name>CONTACT NAME</Name><EmailAddress>bob@example.com</EmailAddress><Addresses><Address><AddressType>DEFAULT</AddressType><AddressLine1>LINE 1 OF THE ADDRESS</AddressLine1><AddressLine2>LINE 2 OF THE ADDRESS</AddressLine2><AddressLine3>LINE 3 OF THE ADDRESS</AddressLine3><AddressLine4>LINE 4 OF THE ADDRESS</AddressLine4><City>WELLINGTON</City><Region>WELLINGTON</Region><PostalCode>6021</PostalCode><Country>NEW ZEALAND</Country></Address></Addresses><Phones><Phone><PhoneType>DEFAULT</PhoneType><PhoneNumber>12345</PhoneNumber></Phone></Phones></Contact></Response>
|
@@ -1 +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-09T02:40:54.3997437Z</DateTimeUTC><Contacts><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><Contact><ContactID>
|
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-09T02:40:54.3997437Z</DateTimeUTC><Contacts><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><Contact><ContactID>e8d9ecd8-c17a-49c4-a445-708875ccb042</ContactID><ContactNumber>12345</ContactNumber><Name>CONTACT NAME</Name><EmailAddress>bob@example.com</EmailAddress><Addresses><Address><AddressType>DEFAULT</AddressType><AddressLine1>LINE 1 OF THE ADDRESS</AddressLine1><AddressLine2>LINE 2 OF THE ADDRESS</AddressLine2><AddressLine3>LINE 3 OF THE ADDRESS</AddressLine3><AddressLine4>LINE 4 OF THE ADDRESS</AddressLine4><City>WELLINGTON</City><Region>WELLINGTON</Region><PostalCode>6021</PostalCode><Country>NEW ZEALAND</Country></Address></Addresses><Phones><Phone><PhoneType>DEFAULT</PhoneType><PhoneNumber>12345</PhoneNumber></Phone></Phones></Contact></Contacts></Response>
|
data/test/test_helper.rb
CHANGED
@@ -1,17 +1,3 @@
|
|
1
|
-
# Copyright (c) 2008 Tim Connor <tlconnor@gmail.com>
|
2
|
-
#
|
3
|
-
# Permission to use, copy, modify, and/or distribute this software for any
|
4
|
-
# purpose with or without fee is hereby granted, provided that the above
|
5
|
-
# copyright notice and this permission notice appear in all copies.
|
6
|
-
#
|
7
|
-
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
8
|
-
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
9
|
-
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
10
|
-
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
11
|
-
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
12
|
-
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
13
|
-
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
14
|
-
|
15
1
|
require "rubygems"
|
16
2
|
|
17
3
|
require 'test/unit'
|
@@ -20,3 +6,4 @@ require 'mocha'
|
|
20
6
|
require 'libxml'
|
21
7
|
|
22
8
|
require File.dirname(__FILE__) + '/../lib/xero_gateway.rb'
|
9
|
+
require File.dirname(__FILE__) + '/integration/integration_test_methods.rb'
|
@@ -1,17 +1,3 @@
|
|
1
|
-
# Copyright (c) 2008 Tim Connor <tlconnor@gmail.com>
|
2
|
-
#
|
3
|
-
# Permission to use, copy, modify, and/or distribute this software for any
|
4
|
-
# purpose with or without fee is hereby granted, provided that the above
|
5
|
-
# copyright notice and this permission notice appear in all copies.
|
6
|
-
#
|
7
|
-
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
8
|
-
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
9
|
-
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
10
|
-
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
11
|
-
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
12
|
-
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
13
|
-
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
14
|
-
|
15
1
|
require File.join(File.dirname(__FILE__), '../../test_helper.rb')
|
16
2
|
|
17
3
|
class ContactMessageTest < Test::Unit::TestCase
|
@@ -50,7 +36,7 @@ class ContactMessageTest < Test::Unit::TestCase
|
|
50
36
|
private
|
51
37
|
|
52
38
|
def create_test_contact
|
53
|
-
contact = XeroGateway::Contact.new(:
|
39
|
+
contact = XeroGateway::Contact.new(:contact_id => "55555")
|
54
40
|
contact.contact_number = "aaa111"
|
55
41
|
contact.name = "CONTACT NAME"
|
56
42
|
contact.email = "someone@somewhere.com"
|
@@ -1,17 +1,3 @@
|
|
1
|
-
# Copyright (c) 2008 Tim Connor <tlconnor@gmail.com>
|
2
|
-
#
|
3
|
-
# Permission to use, copy, modify, and/or distribute this software for any
|
4
|
-
# purpose with or without fee is hereby granted, provided that the above
|
5
|
-
# copyright notice and this permission notice appear in all copies.
|
6
|
-
#
|
7
|
-
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
8
|
-
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
9
|
-
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
10
|
-
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
11
|
-
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
12
|
-
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
13
|
-
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
14
|
-
|
15
1
|
require File.join(File.dirname(__FILE__), '../../test_helper.rb')
|
16
2
|
|
17
3
|
class InvoiceMessageTest < Test::Unit::TestCase
|
@@ -59,7 +45,7 @@ class InvoiceMessageTest < Test::Unit::TestCase
|
|
59
45
|
invoice.total_tax = BigDecimal.new("125")
|
60
46
|
invoice.total = BigDecimal.new("1125")
|
61
47
|
|
62
|
-
invoice.contact = XeroGateway::Contact.new(:
|
48
|
+
invoice.contact = XeroGateway::Contact.new(:contact_id => 55555)
|
63
49
|
invoice.contact.name = "CONTACT NAME"
|
64
50
|
invoice.contact.address.address_type = "THE ADDRESS TYPE FOR THE CONTACT"
|
65
51
|
invoice.contact.address.line_1 = "LINE 1 OF THE ADDRESS"
|
@@ -67,6 +53,7 @@ class InvoiceMessageTest < Test::Unit::TestCase
|
|
67
53
|
|
68
54
|
invoice.line_items << XeroGateway::LineItem.new({
|
69
55
|
:description => "A LINE ITEM",
|
56
|
+
:account_code => "200",
|
70
57
|
:unit_amount => BigDecimal.new("100"),
|
71
58
|
:tax_amount => BigDecimal.new("12.5"),
|
72
59
|
:line_amount => BigDecimal.new("125")
|
data/xero_gateway.gemspec
CHANGED
metadata
CHANGED
@@ -1,166 +0,0 @@
|
|
1
|
-
# Copyright (c) 2008 Tim Connor <tlconnor@gmail.com>
|
2
|
-
#
|
3
|
-
# Permission to use, copy, modify, and/or distribute this software for any
|
4
|
-
# purpose with or without fee is hereby granted, provided that the above
|
5
|
-
# copyright notice and this permission notice appear in all copies.
|
6
|
-
#
|
7
|
-
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
8
|
-
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
9
|
-
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
10
|
-
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
11
|
-
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
12
|
-
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
13
|
-
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
14
|
-
|
15
|
-
require File.dirname(__FILE__) + '/../test_helper'
|
16
|
-
|
17
|
-
class GatewayTest < Test::Unit::TestCase
|
18
|
-
# If false, the tests will be run against the Xero test environment
|
19
|
-
STUB_XERO_CALLS = true
|
20
|
-
|
21
|
-
# If the requests are not stubbed, enter your API key and you test company customer key here
|
22
|
-
API_KEY = "OWFKZTA4YZNHYWNKNDDJM2JKNZQWOW"
|
23
|
-
CUSTOMER_KEY = "YWZIMZQ3ZGVJMME1NDCWNTK3YWZMNW"
|
24
|
-
|
25
|
-
|
26
|
-
def setup
|
27
|
-
@gateway = XeroGateway::Gateway.new(
|
28
|
-
:customer_key => CUSTOMER_KEY,
|
29
|
-
:api_key => API_KEY
|
30
|
-
)
|
31
|
-
|
32
|
-
if STUB_XERO_CALLS
|
33
|
-
@gateway.xero_url = "DUMMY_URL"
|
34
|
-
# Stub out the HTTP request
|
35
|
-
@gateway.stubs(:http_get).with {|url, params| url =~ /contact$/ }.returns(get_file_as_string("contact.xml"))
|
36
|
-
@gateway.stubs(:http_get).with {|url, params| url =~ /contacts$/ }.returns(get_file_as_string("contacts.xml"))
|
37
|
-
@gateway.stubs(:http_get).with {|url, params| url =~ /invoice$/ }.returns(get_file_as_string("invoice.xml"))
|
38
|
-
@gateway.stubs(:http_get).with {|url, params| url =~ /invoices$/ }.returns(get_file_as_string("invoices.xml"))
|
39
|
-
@gateway.stubs(:http_get).with {|url, params| url =~ /accounts$/ }.returns(get_file_as_string("accounts.xml"))
|
40
|
-
@gateway.stubs(:http_put).with {|url, body, params| url =~ /invoice$/ }.returns(get_file_as_string("invoice.xml"))
|
41
|
-
@gateway.stubs(:http_put).with {|url, body, params| url =~ /contact$/ }.returns(get_file_as_string("contact.xml"))
|
42
|
-
|
43
|
-
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
def dummy_invoice
|
48
|
-
invoice = XeroGateway::Invoice.new({
|
49
|
-
:invoice_type => "ACCREC",
|
50
|
-
:due_date => Date.today + 20,
|
51
|
-
:invoice_number => STUB_XERO_CALLS ? "INV-0001" : "#{Time.now.to_i}",
|
52
|
-
:reference => "YOUR REFERENCE (NOT NECESSARILY UNIQUE!)",
|
53
|
-
:sub_total => 1000,
|
54
|
-
:total_tax => 125,
|
55
|
-
:total => 1125
|
56
|
-
})
|
57
|
-
invoice.contact = dummy_contact
|
58
|
-
invoice.line_items << XeroGateway::LineItem.new(
|
59
|
-
:description => "THE DESCRIPTION OF THE LINE ITEM",
|
60
|
-
:unit_amount => 1000,
|
61
|
-
:tax_amount => 125,
|
62
|
-
:line_amount => 1000,
|
63
|
-
:tracking_category => "THE TRACKING CATEGORY FOR THE LINE ITEM",
|
64
|
-
:tracking_option => "THE TRACKING OPTION FOR THE LINE ITEM"
|
65
|
-
)
|
66
|
-
invoice
|
67
|
-
end
|
68
|
-
|
69
|
-
def dummy_contact
|
70
|
-
contact = XeroGateway::Contact.new(:name => STUB_XERO_CALLS ? "CONTACT NAME" : "THE NAME OF THE CONTACT #{Time.now.to_i}")
|
71
|
-
contact.contact_number = STUB_XERO_CALLS ? "12345" : "#{Time.now.to_i}"
|
72
|
-
contact.email = "whoever@something.com"
|
73
|
-
contact.phone.number = "12345"
|
74
|
-
contact.address.line_1 = "LINE 1 OF THE ADDRESS"
|
75
|
-
contact.address.line_2 = "LINE 2 OF THE ADDRESS"
|
76
|
-
contact.address.line_3 = "LINE 3 OF THE ADDRESS"
|
77
|
-
contact.address.line_4 = "LINE 4 OF THE ADDRESS"
|
78
|
-
contact.address.city = "WELLINGTON"
|
79
|
-
contact.address.region = "WELLINGTON"
|
80
|
-
contact.address.country = "NEW ZEALAND"
|
81
|
-
contact.address.post_code = "6021"
|
82
|
-
|
83
|
-
contact
|
84
|
-
end
|
85
|
-
|
86
|
-
def get_file_as_string(filename)
|
87
|
-
data = ''
|
88
|
-
f = File.open(File.dirname(__FILE__) + "/stub_responses/" + filename, "r")
|
89
|
-
f.each_line do |line|
|
90
|
-
data += line
|
91
|
-
end
|
92
|
-
f.close
|
93
|
-
return data
|
94
|
-
end
|
95
|
-
|
96
|
-
def test_create_and_get_contact
|
97
|
-
contact = dummy_contact
|
98
|
-
|
99
|
-
create_contact_result = @gateway.create_contact(contact)
|
100
|
-
assert create_contact_result.success?
|
101
|
-
|
102
|
-
contact_from_create_request = create_contact_result.contact
|
103
|
-
assert contact_from_create_request.name == contact.name
|
104
|
-
|
105
|
-
get_contact_by_id_result = @gateway.get_contact_by_id(contact_from_create_request.id)
|
106
|
-
assert get_contact_by_id_result.success?
|
107
|
-
assert get_contact_by_id_result.contact.name == contact.name
|
108
|
-
|
109
|
-
get_contact_by_number_result = @gateway.get_contact_by_number(contact.contact_number)
|
110
|
-
assert get_contact_by_number_result.success?
|
111
|
-
assert get_contact_by_number_result.contact.name == contact.name
|
112
|
-
end
|
113
|
-
|
114
|
-
def test_create_and_get_invoice
|
115
|
-
invoice = dummy_invoice
|
116
|
-
|
117
|
-
result = @gateway.create_invoice(invoice)
|
118
|
-
assert result.success?
|
119
|
-
|
120
|
-
invoice_from_create_request = result.invoice
|
121
|
-
assert invoice_from_create_request.invoice_number == invoice.invoice_number
|
122
|
-
|
123
|
-
result = @gateway.get_invoice_by_id(invoice_from_create_request.id)
|
124
|
-
assert result.success?
|
125
|
-
assert result.invoice.invoice_number == invoice_from_create_request.invoice_number
|
126
|
-
|
127
|
-
result = @gateway.get_invoice_by_number(invoice_from_create_request.invoice_number)
|
128
|
-
assert result.success?
|
129
|
-
assert result.invoice.id == invoice_from_create_request.id
|
130
|
-
end
|
131
|
-
|
132
|
-
def test_get_contacts
|
133
|
-
result = @gateway.get_contacts
|
134
|
-
assert result.success?
|
135
|
-
assert result.contacts.size > 0
|
136
|
-
end
|
137
|
-
|
138
|
-
def test_get_invoices
|
139
|
-
# Create a test invoice
|
140
|
-
invoice = dummy_invoice
|
141
|
-
@gateway.create_invoice(invoice)
|
142
|
-
|
143
|
-
# Check that it is returned
|
144
|
-
result = @gateway.get_invoices
|
145
|
-
assert result.success?
|
146
|
-
assert result.invoices.collect {|response_invoice| response_invoice.invoice_number}.include?(invoice.invoice_number)
|
147
|
-
end
|
148
|
-
|
149
|
-
def test_get_invoices_with_modified_since_date
|
150
|
-
# Create a test invoice
|
151
|
-
invoice = dummy_invoice
|
152
|
-
@gateway.create_invoice(invoice)
|
153
|
-
|
154
|
-
# Check that it is returned
|
155
|
-
result = @gateway.get_invoices(Date.today - 1)
|
156
|
-
assert result.success?
|
157
|
-
assert result.invoices.collect {|response_invoice| response_invoice.invoice_number}.include?(invoice.invoice_number)
|
158
|
-
end
|
159
|
-
|
160
|
-
def test_get_accounts
|
161
|
-
result = @gateway.get_accounts
|
162
|
-
assert result.success?
|
163
|
-
assert result.accounts.size > 0
|
164
|
-
assert_equal XeroGateway::Account, result.accounts.first.class
|
165
|
-
end
|
166
|
-
end
|