Skip to content

Commit 0148f4d

Browse files
authored
Merge branch 'master' into po_updated_date
2 parents a46d3b5 + cd7e9c7 commit 0148f4d

30 files changed

+270
-97
lines changed

README.md

Lines changed: 84 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Xeroizer API Library ![Project status](http://stillmaintained.com/waynerobinson/
55
**Git**: [git://github.com/waynerobinson/xeroizer.git](git://github.com/waynerobinson/xeroizer.git)
66
**Github**: [https://github.com/waynerobinson/xeroizer](https://github.com/waynerobinson/xeroizer)
77
**Author**: Wayne Robinson [http://www.wayne-robinson.com](http://www.wayne-robinson.com)
8-
**Contributors**: See Contributors section below
8+
**Contributors**: See Contributors section below
99
**Copyright**: 2007-2013
1010
**License**: MIT License
1111

@@ -34,7 +34,7 @@ client = Xeroizer::PublicApplication.new(YOUR_OAUTH_CONSUMER_KEY, YOUR_OAUTH_CON
3434
# Retrieve list of contacts (note: all communication must be made through the client).
3535
contacts = client.Contact.all(:order => 'Name')
3636
```
37-
37+
3838
Authentication
3939
--------------
4040

@@ -44,13 +44,13 @@ There are three methods of authentication detailed below:
4444

4545
### All: Consumer Key/Secret
4646

47-
All methods of authentication require your OAuth consumer key and secret. This can be found for your application
47+
All methods of authentication require your OAuth consumer key and secret. This can be found for your application
4848
in the API management console at [http://api.xero.com](http://api.xero.com).
4949

5050
### Public Applications
5151

52-
Public applications use a 3-legged authorisation process. A user will need to authorise your
53-
application against each organisation that you want access to. Your application can have access
52+
Public applications use a 3-legged authorisation process. A user will need to authorise your
53+
application against each organisation that you want access to. Your application can have access
5454
to many organisations at once by going through the authorisation process for each organisation.
5555

5656
The access token received will expire after 30 minutes. If you want access for longer you will need
@@ -75,69 +75,69 @@ redirect_to request_token.authorize_url
7575

7676
# 3. Exchange RequestToken for AccessToken.
7777
# This access token will be used for all subsequent requests but it is stored within the client
78-
# application so you don't have to record it.
78+
# application so you don't have to record it.
7979
#
8080
# Note: This example assumes the callback URL is a Rails action.
8181
client.authorize_from_request(request_token.token, request_token.secret, :oauth_verifier => params[:oauth_verifier])
8282
```
83-
83+
8484
You can now use the client to access the Xero API methods, e.g.
8585

8686
```ruby
8787
contacts = client.Contact.all
8888
```
89-
89+
9090
#### Example Rails Controller
9191

9292
```ruby
9393
class XeroSessionController < ApplicationController
9494

9595
before_filter :get_xero_client
96-
96+
9797
public
98-
98+
9999
def new
100100
request_token = @xero_client.request_token(:oauth_callback => 'http://yourapp.com/xero_session/create')
101101
session[:request_token] = request_token.token
102102
session[:request_secret] = request_token.secret
103-
103+
104104
redirect_to request_token.authorize_url
105105
end
106-
106+
107107
def create
108108
@xero_client.authorize_from_request(
109-
session[:request_token],
110-
session[:request_secret],
109+
session[:request_token],
110+
session[:request_secret],
111111
:oauth_verifier => params[:oauth_verifier] )
112-
112+
113113
session[:xero_auth] = {
114114
:access_token => @xero_client.access_token.token,
115115
:access_key => @xero_client.access_token.secret }
116-
116+
117117
session.data.delete(:request_token)
118118
session.data.delete(:request_secret)
119119
end
120-
120+
121121
def destroy
122122
session.data.delete(:xero_auth)
123123
end
124-
124+
125125
private
126-
126+
127127
def get_xero_client
128128
@xero_client = Xeroizer::PublicApplication.new(YOUR_OAUTH_CONSUMER_KEY, YOUR_OAUTH_CONSUMER_SECRET)
129-
129+
130130
# Add AccessToken if authorised previously.
131131
if session[:xero_auth]
132132
@xero_client.authorize_from_access(
133-
session[:xero_auth][:access_token],
133+
session[:xero_auth][:access_token],
134134
session[:xero_auth][:access_key] )
135135
end
136136
end
137137
end
138138
```
139-
140-
#### Storing AccessToken
139+
140+
#### Storing AccessToken
141141

142142
You can store the access token/secret pair so you can access the API again without user intervention. Currently these
143143
tokens are only valid for 30 minutes and will raise a `Xeroizer::OAuth::TokenExpired` exception if you try to access
@@ -152,9 +152,9 @@ access_secret = client.access_token.secret
152152

153153
### Private Applications
154154

155-
Private applications use a 2-legged authorisation process. When you register your application, you will select
156-
the organisation that is authorised to your application. This cannot be changed afterwards, although you can
157-
register another private application if you have multiple organisations.
155+
Private applications use a 2-legged authorisation process. When you register your application, you will select
156+
the organisation that is authorised to your application. This cannot be changed afterwards, although you can
157+
register another private application if you have multiple organisations.
158158

159159
Note: You can only register organisations you are authorised to yourself.
160160

@@ -178,7 +178,7 @@ contacts = client.Contact.all
178178

179179
Partner applications use a combination of 3-legged authorisation and private key message signing.
180180

181-
You will need to contact Xero (network@xero.com) to get permission to create a partner application.
181+
Visit the [https://developer.xero.com/partner/app-partner](Becoming an app partner) page to get permission to create a partner application.
182182

183183
After you have followed the instructions provided by Xero for partner applications and uploaded your certificate you can
184184
access the partner application in a similar way to public applications.
@@ -188,7 +188,7 @@ Authentication occcurs in 3 steps:
188188
```ruby
189189
client = Xeroizer::PartnerApplication.new(
190190
YOUR_OAUTH_CONSUMER_KEY,
191-
YOUR_OAUTH_CONSUMER_SECRET,
191+
YOUR_OAUTH_CONSUMER_SECRET,
192192
"/path/to/privatekey.pem"
193193
)
194194

@@ -206,7 +206,7 @@ redirect_to request_token.authorize_url
206206

207207
# 3. Exchange RequestToken for AccessToken.
208208
# This access token will be used for all subsequent requests but it is stored within the client
209-
# application so you don't have to record it.
209+
# application so you don't have to record it.
210210
#
211211
# Note: This example assumes the callback URL is a Rails action.
212212
client.authorize_from_request(request_token.token, request_token.secret, :oauth_verifier => params[:oauth_verifier])
@@ -221,7 +221,7 @@ session_handle = client.session_handle
221221
access_key = client.access_token.token
222222
access_secret = client.access_token.secret
223223
```
224-
224+
225225
Two other interesting attributes of the PartnerApplication client are:
226226

227227
> **`#expires_at`**: Time this AccessToken will expire (usually 30 minutes into the future).
@@ -245,6 +245,10 @@ session.
245245

246246
If you lose these details at any stage you can always reauthorise by redirecting the user back to the Xero OAuth gateway.
247247

248+
#### Branding Themes API
249+
250+
Once you are approved as a Xero Partner you can request unofficial documentation to do with customizing Payment Services and Branding Themes using the API. There is more info on that [here]( https://github.com/waynerobinson/xeroizer/pull/439).
251+
248252
Retrieving Data
249253
---------------
250254

@@ -264,10 +268,10 @@ saved = new_contact.save
264268

265269
### \#all([options])
266270

267-
Retrieves list of all records with matching options.
271+
Retrieves list of all records with matching options.
268272

269273
**Note:** Some records (Invoice, CreditNote) only return summary information for the contact and no line items
270-
when returning them this list operation. This library takes care of automatically retrieving the
274+
when returning them this list operation. This library takes care of automatically retrieving the
271275
contact and line items from Xero on first access however, this first access has a large performance penalty
272276
and will count as an extra query towards your 5,000/day and 60/minute request per organisation limit.
273277

@@ -281,6 +285,18 @@ Valid options are:
281285
282286
> Field to order by. Should be formatted as Xero-based field (e.g. 'Name', 'ContactID', etc)
283287
288+
> **:status**
289+
290+
> Status field for PurchaseOrder. Should be a valid Xero purchase order status.
291+
292+
> **:date_from**
293+
294+
> DateFrom field for PurchaseOrder. Should be in YYYY-MM-DD format.
295+
296+
> **:date_to**
297+
298+
> DateTo field for PurchaseOrder. Should be in YYYY-MM-DD format.
299+
284300
> **:where**
285301
286302
> __See *Where Filters* section below.__
@@ -305,11 +321,11 @@ You can specify find filters by providing the :where option with a hash. For exa
305321
```ruby
306322
invoices = Xero.Invoice.all(:where => {:type => 'ACCREC', :amount_due_is_not => 0})
307323
```
308-
324+
309325
will automatically create the Xero string:
310326

311327
Type=="ACCREC"&&AmountDue<>0
312-
328+
313329
The default method for filtering is the equality '==' operator however, these can be overridden
314330
by modifying the postfix of the attribute name (as you can see for the :amount\_due field above).
315331

@@ -318,9 +334,9 @@ by modifying the postfix of the attribute name (as you can see for the :amount\_
318334
\{attribute_name}_is_greater_than_or_equal_to will use '>='
319335
\{attribute_name}_is_less_than will use '<'
320336
\{attribute_name}_is_less_than_or_equal_to will use '<='
321-
337+
322338
The default is '=='
323-
339+
324340
**Note:** Currently, the hash-conversion library only allows for AND-based criteria and doesn't
325341
take into account associations. For these, please use the custom filter method below.
326342

@@ -332,31 +348,31 @@ in the resulting response, including all nested XML elements.
332348
**Example 1: Retrieve all invoices for a specific contact ID:**
333349

334350
invoices = xero.Invoice.all(:where => 'Contact.ContactID.ToString()=="cd09aa49-134d-40fb-a52b-b63c6a91d712"')
335-
351+
336352
**Example 2: Retrieve all unpaid ACCREC Invoices against a particular Contact Name:**
337-
353+
338354
invoices = xero.Invoice.all(:where => 'Contact.Name=="Basket Case" && Type=="ACCREC" && AmountDue<>0')
339-
355+
340356
**Example 3: Retrieve all Invoices PAID between certain dates**
341-
357+
342358
invoices = xero.Invoice.all(:where => 'FullyPaidOnDate>=DateTime.Parse("2010-01-01T00:00:00")&&FullyPaidOnDate<=DateTime.Parse("2010-01-08T00:00:00")')
343-
359+
344360
**Example 4: Retrieve all Invoices using Paging (batches of 100)**
345361

346362
invoices = xero.Invoice.find_in_batches({page_number: 1}) do |invoice_batch|
347363
invoice_batch.each do |invoice|
348364
...
349365
end
350366
end
351-
367+
352368
**Example 5: Retrieve all Bank Accounts:**
353-
369+
354370
accounts = xero.Account.all(:where => 'Type=="BANK"')
355-
371+
356372
**Example 6: Retrieve all DELETED or VOIDED Invoices:**
357-
373+
358374
invoices = xero.Invoice.all(:where => 'Status=="VOIDED" OR Status=="DELETED"')
359-
375+
360376
**Example 7: Retrieve all contacts with specific text in the contact name:**
361377

362378
contacts = xero.Contact.all(:where => 'Name.Contains("Peter")')
@@ -376,7 +392,7 @@ invoice.line_items.each do | line_item |
376392
puts "Line Description: #{line_item.description}"
377393
end
378394
```
379-
395+
380396
**belongs\_to example:**
381397

382398
```ruby
@@ -430,21 +446,21 @@ contact.add_phone(:type => 'DEFAULT', :area_code => '07', :number => '3033 1234'
430446
contact.add_phone(:type => 'MOBILE', :number => '0412 123 456')
431447
contact.save
432448
```
433-
449+
434450
To add to a `has_many` association use the `add_{association}` method. For example:
435451

436452
```ruby
437453
contact.add_address(:type => 'STREET', :line1 => '12 Testing Lane', :city => 'Brisbane')
438454
```
439-
455+
440456
To add to a `belongs_to` association use the `build_{association}` method. For example:
441-
457+
442458
```ruby
443459
invoice.build_contact(:name => 'ABC Company')
444460
```
445461

446462
### Updating
447-
463+
448464
If the primary GUID for the record is present, the library will attempt to update the record instead of
449465
creating it. It is important that this record is downloaded from the Xero API first before attempting
450466
an update. For example:
@@ -454,10 +470,17 @@ contact = xero.Contact.find("cd09aa49-134d-40fb-a52b-b63c6a91d712")
454470
contact.name = "Another Name Change"
455471
contact.save
456472
```
457-
458-
Have a look at the models in `lib/xeroizer/models/` to see the valid attributes, associations and
473+
474+
Have a look at the models in `lib/xeroizer/models/` to see the valid attributes, associations and
459475
minimum validation requirements for each of the record types.
460476

477+
Some Xero endpoints, such as Payment, will only accept specific attributes for updates. Because the library does not have this knowledge encoded (and doesn't do dirty tracking of attributes), it's necessary to construct new objects instead of using the ones retrieved from Xero:
478+
479+
```ruby
480+
delete_payment = gateway.Payment.build(id: payment.id, status: 'DELETED')
481+
delete_payment.save
482+
```
483+
461484
### Bulk Creates & Updates
462485

463486
Xero has a hard daily limit on the number of API requests you can make (currently 5,000 requests
@@ -501,7 +524,7 @@ saved = contact.save
501524

502525
# contact.errors will contain [[:name, "can't be blank"]]
503526
```
504-
527+
505528
\#errors\_for(:attribute\_name) is a helper method to return just the errors associated with
506529
that attribute. For example:
507530

@@ -582,16 +605,16 @@ trial_balance.rows.each do | row |
582605
case row
583606
when Xeroizer::Report::HeaderRow
584607
# do something with header
585-
608+
586609
when Xeroizer::Report::SectionRow
587610
# do something with section, will need to step into the rows for this section
588-
611+
589612
when Xeroizer::Report::Row
590613
# do something for standard report rows
591-
614+
592615
when Xeroizer::Report::SummaryRow
593616
# do something for summary rows
594-
617+
595618
end
596619
end
597620
```
@@ -686,7 +709,7 @@ This option adds the unitdp=4 query string parameter to all requests for models
686709
Tests
687710
-----
688711

689-
The tests within the repository can be run by setting up a [Private App](https://developer.xero.com/documentation/auth-and-limits/private-applications). You can create a Private App in the [developer portal](https://developer.xero.com/myapps/), it's suggested that you create it against the [Demo Company](https://developer.xero.com/documentation/getting-started/development-accounts) (note: the Demo Company expires after 28 days, so you will need to reset it and create a new Private App if you Demo Company has expired).
712+
The tests within the repository can be run by setting up a [Private App](https://developer.xero.com/documentation/auth-and-limits/private-applications). You can create a Private App in the [developer portal](https://developer.xero.com/myapps/), it's suggested that you create it against the [Demo Company (AU)](https://developer.xero.com/documentation/getting-started/development-accounts). Demo Company expires after 28 days, so you will need to reset it and create a new Private App if you Demo Company has expired. Make sure you create the Demo Company in Australia region.
690713

691714
Once you have created your Private App, set these environment variables:
692715
```
@@ -704,6 +727,6 @@ rake test
704727

705728

706729
### Contributors
707-
Xeroizer was inspired by the https://github.com/tlconnor/xero_gateway gem created by Tim Connor
708-
and Nik Wakelin and portions of the networking and authentication code are based completely off
730+
Xeroizer was inspired by the https://github.com/tlconnor/xero_gateway gem created by Tim Connor
731+
and Nik Wakelin and portions of the networking and authentication code are based completely off
709732
this project. Copyright for these components remains held in the name of Tim Connor.

lib/xeroizer.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
require 'xeroizer/models/option'
5757
require 'xeroizer/models/organisation'
5858
require 'xeroizer/models/payment'
59+
require 'xeroizer/models/payment_service'
5960
require 'xeroizer/models/prepayment'
6061
require 'xeroizer/models/overpayment'
6162
require 'xeroizer/models/phone'

0 commit comments

Comments
 (0)