xero_gateway-float 2.0.15

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. data/Gemfile +12 -0
  2. data/LICENSE +14 -0
  3. data/README.textile +357 -0
  4. data/Rakefile +14 -0
  5. data/examples/oauth.rb +25 -0
  6. data/examples/partner_app.rb +36 -0
  7. data/init.rb +1 -0
  8. data/lib/oauth/oauth_consumer.rb +14 -0
  9. data/lib/xero_gateway.rb +39 -0
  10. data/lib/xero_gateway/account.rb +95 -0
  11. data/lib/xero_gateway/accounts_list.rb +87 -0
  12. data/lib/xero_gateway/address.rb +96 -0
  13. data/lib/xero_gateway/bank_transaction.rb +178 -0
  14. data/lib/xero_gateway/ca-certificates.crt +2560 -0
  15. data/lib/xero_gateway/contact.rb +206 -0
  16. data/lib/xero_gateway/credit_note.rb +222 -0
  17. data/lib/xero_gateway/currency.rb +56 -0
  18. data/lib/xero_gateway/dates.rb +30 -0
  19. data/lib/xero_gateway/error.rb +18 -0
  20. data/lib/xero_gateway/exceptions.rb +46 -0
  21. data/lib/xero_gateway/gateway.rb +622 -0
  22. data/lib/xero_gateway/http.rb +138 -0
  23. data/lib/xero_gateway/http_encoding_helper.rb +49 -0
  24. data/lib/xero_gateway/invoice.rb +236 -0
  25. data/lib/xero_gateway/line_item.rb +125 -0
  26. data/lib/xero_gateway/line_item_calculations.rb +55 -0
  27. data/lib/xero_gateway/money.rb +16 -0
  28. data/lib/xero_gateway/oauth.rb +87 -0
  29. data/lib/xero_gateway/organisation.rb +75 -0
  30. data/lib/xero_gateway/partner_app.rb +30 -0
  31. data/lib/xero_gateway/payment.rb +40 -0
  32. data/lib/xero_gateway/phone.rb +77 -0
  33. data/lib/xero_gateway/private_app.rb +17 -0
  34. data/lib/xero_gateway/response.rb +41 -0
  35. data/lib/xero_gateway/tax_rate.rb +63 -0
  36. data/lib/xero_gateway/tracking_category.rb +87 -0
  37. data/test/integration/accounts_list_test.rb +109 -0
  38. data/test/integration/create_bank_transaction_test.rb +38 -0
  39. data/test/integration/create_contact_test.rb +66 -0
  40. data/test/integration/create_credit_note_test.rb +49 -0
  41. data/test/integration/create_invoice_test.rb +49 -0
  42. data/test/integration/get_accounts_test.rb +23 -0
  43. data/test/integration/get_bank_transaction_test.rb +51 -0
  44. data/test/integration/get_bank_transactions_test.rb +88 -0
  45. data/test/integration/get_contact_test.rb +28 -0
  46. data/test/integration/get_contacts_test.rb +40 -0
  47. data/test/integration/get_credit_note_test.rb +48 -0
  48. data/test/integration/get_credit_notes_test.rb +90 -0
  49. data/test/integration/get_currencies_test.rb +25 -0
  50. data/test/integration/get_invoice_test.rb +48 -0
  51. data/test/integration/get_invoices_test.rb +92 -0
  52. data/test/integration/get_organisation_test.rb +24 -0
  53. data/test/integration/get_tax_rates_test.rb +25 -0
  54. data/test/integration/get_tracking_categories_test.rb +27 -0
  55. data/test/integration/update_bank_transaction_test.rb +31 -0
  56. data/test/integration/update_contact_test.rb +31 -0
  57. data/test/integration/update_invoice_test.rb +31 -0
  58. data/test/test_helper.rb +179 -0
  59. data/test/unit/account_test.rb +47 -0
  60. data/test/unit/bank_transaction_test.rb +126 -0
  61. data/test/unit/contact_test.rb +97 -0
  62. data/test/unit/credit_note_test.rb +284 -0
  63. data/test/unit/currency_test.rb +31 -0
  64. data/test/unit/gateway_test.rb +119 -0
  65. data/test/unit/invoice_test.rb +326 -0
  66. data/test/unit/oauth_test.rb +116 -0
  67. data/test/unit/organisation_test.rb +38 -0
  68. data/test/unit/tax_rate_test.rb +38 -0
  69. data/test/unit/tracking_category_test.rb +52 -0
  70. data/xero_gateway.gemspec +15 -0
  71. metadata +164 -0
@@ -0,0 +1,116 @@
1
+ # Shamelessly based on the xero Gem's OAuth implementation by John Nunemaker
2
+ # Thanks!
3
+ #
4
+ # http://xero.rubyforge.org/
5
+ # http://github.com/jnunemaker/xero/
6
+
7
+ require File.join(File.dirname(__FILE__), '../test_helper.rb')
8
+
9
+ class OAuthTest < Test::Unit::TestCase
10
+ should "initialize with consumer token and secret" do
11
+ xero = XeroGateway::OAuth.new('token', 'secret')
12
+
13
+ assert_equal 'token', xero.ctoken
14
+ assert_equal 'secret', xero.csecret
15
+ end
16
+
17
+ should "set autorization path to '/oauth/authorize' by default" do
18
+ xero = XeroGateway::OAuth.new('token', 'secret')
19
+ assert_equal '/oauth/Authorize', xero.consumer.options[:authorize_path]
20
+ end
21
+
22
+ should "have a consumer" do
23
+ consumer = mock('oauth consumer')
24
+ OAuth::Consumer.expects(:new).with('token', 'secret', XeroGateway::OAuth::XERO_CONSUMER_OPTIONS).returns(consumer)
25
+
26
+ xero = XeroGateway::OAuth.new('token', 'secret')
27
+
28
+ assert_equal consumer, xero.consumer
29
+ end
30
+
31
+ should "have a request token from the consumer" do
32
+ consumer = mock('oauth consumer')
33
+ request_token = mock('request token')
34
+ consumer.expects(:get_request_token).returns(request_token)
35
+ OAuth::Consumer.expects(:new).with('token', 'secret', XeroGateway::OAuth::XERO_CONSUMER_OPTIONS).returns(consumer)
36
+ xero = XeroGateway::OAuth.new('token', 'secret')
37
+
38
+ assert_equal request_token, xero.request_token
39
+ end
40
+
41
+ should "be able to create access token from request token and secret" do
42
+ xero = XeroGateway::OAuth.new('token', 'secret')
43
+ consumer = OAuth::Consumer.new('token', 'secret')
44
+ xero.stubs(:consumer).returns(consumer)
45
+
46
+ access_token = mock('access token')
47
+ access_token.expects(:token).twice.returns('atoken')
48
+ access_token.expects(:secret).twice.returns('asecret')
49
+ access_token.stubs(:params).returns({})
50
+
51
+ request_token = mock('request token')
52
+ request_token.expects(:get_access_token).returns(access_token)
53
+ OAuth::RequestToken.expects(:new).with(consumer, 'rtoken', 'rsecret').returns(request_token)
54
+
55
+ xero.authorize_from_request('rtoken', 'rsecret')
56
+ assert xero.access_token.is_a? OAuth::AccessToken
57
+ assert_equal "atoken", xero.access_token.token
58
+ assert_equal "asecret", xero.access_token.secret
59
+ end
60
+
61
+ should "be able to create access token from access token and secret" do
62
+ xero = XeroGateway::OAuth.new('token', 'secret')
63
+ consumer = OAuth::Consumer.new('token', 'secret')
64
+ xero.stubs(:consumer).returns(consumer)
65
+
66
+ xero.authorize_from_access('atoken', 'asecret')
67
+ assert xero.access_token.is_a? OAuth::AccessToken
68
+ assert_equal "atoken", xero.access_token.token
69
+ assert_equal "asecret", xero.access_token.secret
70
+ end
71
+
72
+ should "be able to create request token with callback url" do
73
+ xero = XeroGateway::OAuth.new('token', 'secret')
74
+ consumer = OAuth::Consumer.new('token', 'secret')
75
+ xero.stubs(:consumer).returns(consumer)
76
+
77
+ request_token = mock('request token')
78
+ consumer.expects(:get_request_token).with(:oauth_callback => "http://callback.com").returns(request_token)
79
+
80
+ xero.request_token(:oauth_callback => "http://callback.com")
81
+ end
82
+
83
+ should "be able to create access token with oauth verifier" do
84
+ xero = XeroGateway::OAuth.new('token', 'secret')
85
+ consumer = OAuth::Consumer.new('token', 'secret')
86
+ xero.stubs(:consumer).returns(consumer)
87
+
88
+ access_token = mock('access token')
89
+ access_token.expects(:token).twice.returns('atoken')
90
+ access_token.expects(:secret).twice.returns('asecret')
91
+ access_token.stubs(:params).returns({})
92
+
93
+ request_token = mock('request token')
94
+ request_token.expects(:get_access_token).with(:oauth_verifier => "verifier").returns(access_token)
95
+
96
+ OAuth::RequestToken.expects(:new).with(consumer, 'rtoken', 'rsecret').returns(request_token)
97
+
98
+ xero.authorize_from_request('rtoken', 'rsecret', :oauth_verifier => "verifier")
99
+ end
100
+
101
+ should "delegate get to access token" do
102
+ access_token = mock('access token')
103
+ xero = XeroGateway::OAuth.new('token', 'secret')
104
+ xero.stubs(:access_token).returns(access_token)
105
+ access_token.expects(:get).returns(nil)
106
+ xero.get('/foo')
107
+ end
108
+
109
+ should "delegate post to access token" do
110
+ access_token = mock('access token')
111
+ xero = XeroGateway::OAuth.new('token', 'secret')
112
+ xero.stubs(:access_token).returns(access_token)
113
+ access_token.expects(:post).returns(nil)
114
+ xero.post('/foo')
115
+ end
116
+ end
@@ -0,0 +1,38 @@
1
+ require File.join(File.dirname(__FILE__), '../test_helper.rb')
2
+
3
+ class OrganisationTest < Test::Unit::TestCase
4
+
5
+ # Tests that an organisation can be converted into XML that Xero can understand, and then converted back to an organisation
6
+ def test_build_and_parse_xml
7
+ org = create_test_organisation
8
+
9
+ # Generate the XML message
10
+ org_as_xml = org.to_xml
11
+
12
+ # Parse the XML message and retrieve the account element
13
+ org_element = REXML::XPath.first(REXML::Document.new(org_as_xml), "/Organisation")
14
+
15
+ # Build a new account from the XML
16
+ result_org = XeroGateway::Organisation.from_xml(org_element)
17
+
18
+ # Check the account details
19
+ assert_equal org, result_org
20
+ end
21
+
22
+
23
+ private
24
+
25
+ def create_test_organisation
26
+ XeroGateway::Organisation.new.tap do |org|
27
+ org.name = "Demo Company (NZ)"
28
+ org.legal_name = "Demo Company (NZ)"
29
+ org.pays_tax = true
30
+ org.version = "NZ"
31
+ org.base_currency = "NZD"
32
+ org.country_code = "NZ"
33
+ org.organisation_type = nil
34
+ org.organisation_status = nil
35
+ org.is_demo_company = false
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,38 @@
1
+ require File.join(File.dirname(__FILE__), '../test_helper.rb')
2
+
3
+ class TaxRateTest < Test::Unit::TestCase
4
+
5
+ # Tests that a tax rate can be converted into XML that Xero can understand, and then converted back to a tax rate
6
+ def test_build_and_parse_xml
7
+ tax_rate = create_test_tax_rate
8
+
9
+ # Generate the XML message
10
+ tax_rate_as_xml = tax_rate.to_xml
11
+
12
+ # Parse the XML message and retrieve the account element
13
+ tax_rate_element = REXML::XPath.first(REXML::Document.new(tax_rate_as_xml), "/TaxRate")
14
+
15
+ # Build a new account from the XML
16
+ result_tax_rate = XeroGateway::TaxRate.from_xml(tax_rate_element)
17
+
18
+ # Check the account details
19
+ assert_equal tax_rate, result_tax_rate
20
+ end
21
+
22
+
23
+ private
24
+
25
+ def create_test_tax_rate
26
+ XeroGateway::TaxRate.new.tap do |tax_rate|
27
+ tax_rate.name = "GST on Expenses"
28
+ tax_rate.tax_type = "INPUT"
29
+ tax_rate.can_apply_to_assets = true
30
+ tax_rate.can_apply_to_equity = true
31
+ tax_rate.can_apply_to_expenses = true
32
+ tax_rate.can_apply_to_liabilities = true
33
+ tax_rate.can_apply_to_revenue = false
34
+ tax_rate.display_tax_rate = 12.500
35
+ tax_rate.effective_rate = 12.500
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,52 @@
1
+ require File.join(File.dirname(__FILE__), '../test_helper.rb')
2
+
3
+ class TrackingCategoryTest < Test::Unit::TestCase
4
+ # Tests that a tracking category can be converted into XML that Xero can understand, and then converted back to a tracking category
5
+ def test_build_and_parse_xml
6
+ tracking_category = create_test_tracking_category
7
+
8
+ # Generate the XML message
9
+ tracking_category_as_xml = tracking_category.to_xml
10
+
11
+ # Parse the XML message and retrieve the tracking category element
12
+ tracking_category_element = REXML::XPath.first(REXML::Document.new(tracking_category_as_xml), "/TrackingCategory")
13
+
14
+ # Build a new tracking category from the XML
15
+ result_tracking_category = XeroGateway::TrackingCategory.from_xml(tracking_category_element)
16
+
17
+ # Check the tracking category details
18
+ assert_equal tracking_category, result_tracking_category
19
+ end
20
+
21
+ def test_build_and_parse_xml_from_line_item
22
+ tracking_category = create_test_line_item_tracking_category
23
+
24
+ # Generate the XML message
25
+ tracking_category_as_xml = tracking_category.to_xml_for_invoice_messages
26
+
27
+ # Parse the XML message and retrieve the tracking category element
28
+ tracking_category_element = REXML::XPath.first(REXML::Document.new(tracking_category_as_xml), "/TrackingCategory")
29
+
30
+ # Build a new tracking category from the XML
31
+ result_tracking_category = XeroGateway::TrackingCategory.from_xml(tracking_category_element)
32
+
33
+ # Check the tracking category details
34
+ assert_equal tracking_category, result_tracking_category
35
+ end
36
+
37
+ private
38
+
39
+ def create_test_tracking_category
40
+ tracking_category = XeroGateway::TrackingCategory.new
41
+ tracking_category.name = "REGION"
42
+ tracking_category.options = ["NORTH", "SOUTH", "CENTRAL"]
43
+ tracking_category
44
+ end
45
+
46
+ def create_test_line_item_tracking_category
47
+ tracking_category = XeroGateway::TrackingCategory.new
48
+ tracking_category.name = "REGION"
49
+ tracking_category.options = ["NORTH"]
50
+ tracking_category
51
+ end
52
+ end
@@ -0,0 +1,15 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "xero_gateway-float"
3
+ s.version = "2.0.15"
4
+ s.date = "2012-11-02"
5
+ s.summary = "Enables ruby based applications to communicate with the Xero API"
6
+ s.email = "tim@connorsoftware.com"
7
+ s.homepage = "http://github.com/latentflip/xero_gateway"
8
+ s.description = "Enables ruby based applications to communicate with the Xero API"
9
+ s.has_rdoc = false
10
+ s.authors = ["Tim Connor", "Nik Wakelin", "Philip Roberts"]
11
+ s.files = ["Gemfile", "LICENSE", "Rakefile", "README.textile", "xero_gateway.gemspec"] + Dir['**/*.rb'] + Dir['**/*.crt']
12
+ s.add_dependency('builder', '>= 2.1.2')
13
+ s.add_dependency('oauth', '>= 0.3.6')
14
+ s.add_dependency('activesupport')
15
+ end
metadata ADDED
@@ -0,0 +1,164 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: xero_gateway-float
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.0.15
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Tim Connor
9
+ - Nik Wakelin
10
+ - Philip Roberts
11
+ autorequire:
12
+ bindir: bin
13
+ cert_chain: []
14
+ date: 2012-11-02 00:00:00.000000000 Z
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: builder
18
+ requirement: !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ! '>='
22
+ - !ruby/object:Gem::Version
23
+ version: 2.1.2
24
+ type: :runtime
25
+ prerelease: false
26
+ version_requirements: !ruby/object:Gem::Requirement
27
+ none: false
28
+ requirements:
29
+ - - ! '>='
30
+ - !ruby/object:Gem::Version
31
+ version: 2.1.2
32
+ - !ruby/object:Gem::Dependency
33
+ name: oauth
34
+ requirement: !ruby/object:Gem::Requirement
35
+ none: false
36
+ requirements:
37
+ - - ! '>='
38
+ - !ruby/object:Gem::Version
39
+ version: 0.3.6
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ none: false
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: 0.3.6
48
+ - !ruby/object:Gem::Dependency
49
+ name: activesupport
50
+ requirement: !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ type: :runtime
57
+ prerelease: false
58
+ version_requirements: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ! '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ description: Enables ruby based applications to communicate with the Xero API
65
+ email: tim@connorsoftware.com
66
+ executables: []
67
+ extensions: []
68
+ extra_rdoc_files: []
69
+ files:
70
+ - Gemfile
71
+ - LICENSE
72
+ - Rakefile
73
+ - README.textile
74
+ - xero_gateway.gemspec
75
+ - examples/oauth.rb
76
+ - examples/partner_app.rb
77
+ - init.rb
78
+ - lib/oauth/oauth_consumer.rb
79
+ - lib/xero_gateway/account.rb
80
+ - lib/xero_gateway/accounts_list.rb
81
+ - lib/xero_gateway/address.rb
82
+ - lib/xero_gateway/bank_transaction.rb
83
+ - lib/xero_gateway/contact.rb
84
+ - lib/xero_gateway/credit_note.rb
85
+ - lib/xero_gateway/currency.rb
86
+ - lib/xero_gateway/dates.rb
87
+ - lib/xero_gateway/error.rb
88
+ - lib/xero_gateway/exceptions.rb
89
+ - lib/xero_gateway/gateway.rb
90
+ - lib/xero_gateway/http.rb
91
+ - lib/xero_gateway/http_encoding_helper.rb
92
+ - lib/xero_gateway/invoice.rb
93
+ - lib/xero_gateway/line_item.rb
94
+ - lib/xero_gateway/line_item_calculations.rb
95
+ - lib/xero_gateway/money.rb
96
+ - lib/xero_gateway/oauth.rb
97
+ - lib/xero_gateway/organisation.rb
98
+ - lib/xero_gateway/partner_app.rb
99
+ - lib/xero_gateway/payment.rb
100
+ - lib/xero_gateway/phone.rb
101
+ - lib/xero_gateway/private_app.rb
102
+ - lib/xero_gateway/response.rb
103
+ - lib/xero_gateway/tax_rate.rb
104
+ - lib/xero_gateway/tracking_category.rb
105
+ - lib/xero_gateway.rb
106
+ - test/integration/accounts_list_test.rb
107
+ - test/integration/create_bank_transaction_test.rb
108
+ - test/integration/create_contact_test.rb
109
+ - test/integration/create_credit_note_test.rb
110
+ - test/integration/create_invoice_test.rb
111
+ - test/integration/get_accounts_test.rb
112
+ - test/integration/get_bank_transaction_test.rb
113
+ - test/integration/get_bank_transactions_test.rb
114
+ - test/integration/get_contact_test.rb
115
+ - test/integration/get_contacts_test.rb
116
+ - test/integration/get_credit_note_test.rb
117
+ - test/integration/get_credit_notes_test.rb
118
+ - test/integration/get_currencies_test.rb
119
+ - test/integration/get_invoice_test.rb
120
+ - test/integration/get_invoices_test.rb
121
+ - test/integration/get_organisation_test.rb
122
+ - test/integration/get_tax_rates_test.rb
123
+ - test/integration/get_tracking_categories_test.rb
124
+ - test/integration/update_bank_transaction_test.rb
125
+ - test/integration/update_contact_test.rb
126
+ - test/integration/update_invoice_test.rb
127
+ - test/test_helper.rb
128
+ - test/unit/account_test.rb
129
+ - test/unit/bank_transaction_test.rb
130
+ - test/unit/contact_test.rb
131
+ - test/unit/credit_note_test.rb
132
+ - test/unit/currency_test.rb
133
+ - test/unit/gateway_test.rb
134
+ - test/unit/invoice_test.rb
135
+ - test/unit/oauth_test.rb
136
+ - test/unit/organisation_test.rb
137
+ - test/unit/tax_rate_test.rb
138
+ - test/unit/tracking_category_test.rb
139
+ - lib/xero_gateway/ca-certificates.crt
140
+ homepage: http://github.com/latentflip/xero_gateway
141
+ licenses: []
142
+ post_install_message:
143
+ rdoc_options: []
144
+ require_paths:
145
+ - lib
146
+ required_ruby_version: !ruby/object:Gem::Requirement
147
+ none: false
148
+ requirements:
149
+ - - ! '>='
150
+ - !ruby/object:Gem::Version
151
+ version: '0'
152
+ required_rubygems_version: !ruby/object:Gem::Requirement
153
+ none: false
154
+ requirements:
155
+ - - ! '>='
156
+ - !ruby/object:Gem::Version
157
+ version: '0'
158
+ requirements: []
159
+ rubyforge_project:
160
+ rubygems_version: 1.8.21
161
+ signing_key:
162
+ specification_version: 3
163
+ summary: Enables ruby based applications to communicate with the Xero API
164
+ test_files: []