xeroizer 2.19.0 → 2.20.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1ca2b2dffb8f864a2f4c82295bbfddcdeea61c1b
4
- data.tar.gz: 4b9f39d61e7027ba84df0d548826cccbc0695d08
3
+ metadata.gz: 7a2ed7ed5abbb823dc78470a4a50e31768592a42
4
+ data.tar.gz: 828b5d4e36a703a6f6944f3f183964cf59c19ed8
5
5
  SHA512:
6
- metadata.gz: 1e27f5e7d6b66833b4ef226ce27c9fd67b26ba434eaa35b2ea750106db4ad6c334e566132d4779192b3ccfa964811657b9ef123b552d8a4a185be0d9f78c899d
7
- data.tar.gz: 6ea509718550d68b1560507fc0204c19406df17924c44ba2ebcc2ac0f27d7652929b7fd9716b9a489e564f274304a3d4cb6e72556031186b7150c304aad5a7cc
6
+ metadata.gz: f66a004449f5e9570fed2098ebdb4deb1d55aa0c27e8b355e05bb79989d20171e849a45b33118d9ddbdde9908c20ece199e16b3eceff10188e7c71b0a2dc620e
7
+ data.tar.gz: 6a6a3316543a58ec13f448cbeead6ce143f02a6e8799f0eeb125801e2553da2acb1152cd12797906bf53aa33869ad892ddfdf8f312fbd365838f39e6ad06d787
data/README.md CHANGED
@@ -1,13 +1,13 @@
1
1
  Xeroizer API Library ![Project status](http://stillmaintained.com/waynerobinson/xeroizer.png) [![Build Status](https://travis-ci.org/waynerobinson/xeroizer.svg)](https://travis-ci.org/waynerobinson/xeroizer)
2
2
  ====================
3
3
 
4
- **Homepage**: [http://waynerobinson.github.com/xeroizer](http://waynerobinson.github.com/xeroizer)
5
- **Git**: [git://github.com/waynerobinson/xeroizer.git](git://github.com/waynerobinson/xeroizer.git)
6
- **Github**: [https://github.com/waynerobinson/xeroizer](https://github.com/waynerobinson/xeroizer)
7
- **Author**: Wayne Robinson [http://www.wayne-robinson.com](http://www.wayne-robinson.com)
4
+ **Homepage**: [http://waynerobinson.github.com/xeroizer](http://waynerobinson.github.com/xeroizer)
5
+ **Git**: [git://github.com/waynerobinson/xeroizer.git](git://github.com/waynerobinson/xeroizer.git)
6
+ **Github**: [https://github.com/waynerobinson/xeroizer](https://github.com/waynerobinson/xeroizer)
7
+ **Author**: Wayne Robinson [http://www.wayne-robinson.com](http://www.wayne-robinson.com)
8
8
  **Contributors**: See Contributors section below
9
9
  **Copyright**: 2007-2013
10
- **License**: MIT License
10
+ **License**: MIT License
11
11
 
12
12
  Introduction
13
13
  ------------
@@ -69,7 +69,7 @@ client = Xeroizer::PublicApplication.new(YOUR_OAUTH_CONSUMER_KEY, YOUR_OAUTH_CON
69
69
  request_token = client.request_token(:oauth_callback => 'http://yourapp.com/oauth/callback')
70
70
 
71
71
  # 2. Redirect the user to the URL specified by the RequestToken.
72
- #
72
+ #
73
73
  # Note: example uses redirect_to method defined in Rails controllers.
74
74
  redirect_to request_token.authorize_url
75
75
 
@@ -174,6 +174,16 @@ client = Xeroizer::PrivateApplication.new(YOUR_OAUTH_CONSUMER_KEY, YOUR_OAUTH_CO
174
174
  contacts = client.Contact.all
175
175
  ```
176
176
 
177
+ To provide a private key directly, set the path to nil and pass in a `private_key` option instead. For example:
178
+
179
+ ```ruby
180
+ # Using environment variables (e.g. Heroku):
181
+ client = Xeroizer::PrivateApplication.new(key, secret, nil, private_key: ENV["XERO_PRIVATE_KEY"])
182
+
183
+ # Using Rails Credentials (Rails 5.2+):
184
+ client = Xeroizer::PrivateApplication.new(key, secret, nil, private_key: Rails.application.credentials.xero_private_key)
185
+ ```
186
+
177
187
  ### Partner Applications
178
188
 
179
189
  Partner applications use a combination of 3-legged authorisation and private key message signing.
@@ -200,7 +210,7 @@ client = Xeroizer::PartnerApplication.new(
200
210
  request_token = client.request_token(:oauth_callback => 'http://yourapp.com/oauth/callback')
201
211
 
202
212
  # 2. Redirect the user to the URL specified by the RequestToken.
203
- #
213
+ #
204
214
  # Note: example uses redirect_to method defined in Rails controllers.
205
215
  redirect_to request_token.authorize_url
206
216
 
@@ -224,8 +234,8 @@ access_secret = client.access_token.secret
224
234
 
225
235
  Two other interesting attributes of the PartnerApplication client are:
226
236
 
227
- > **`#expires_at`**: Time this AccessToken will expire (usually 30 minutes into the future).
228
- > **`#authorization_expires_at`**: How long this organisation has authorised you to access their data (usually 10 years into the future).
237
+ > **`#expires_at`**: Time this AccessToken will expire (usually 30 minutes into the future).
238
+ > **`#authorization_expires_at`**: How long this organisation has authorised you to access their data (usually 10 years into the future).
229
239
 
230
240
  #### AccessToken Renewal
231
241
 
@@ -586,6 +596,8 @@ Reports are accessed like the following example:
586
596
  ```ruby
587
597
  trial_balance = xero.TrialBalance.get(:date => DateTime.new(2011,3,21))
588
598
 
599
+ profit_and_loss = xero.ProfitAndLoss.get(fromDate: Date.new(2019,4,1), toDate: Date.new(2019,5,1))
600
+
589
601
  # Array containing report headings.
590
602
  trial_balance.header.cells.map { | cell | cell.value }
591
603
 
@@ -653,7 +665,7 @@ If required, the library can handle these exceptions internally by sleeping 1 se
653
665
  You can set this option when initializing an application:
654
666
 
655
667
  ```ruby
656
- # Sleep for 2 seconds every time the rate limit is exceeded.
668
+ # Sleep for 1 second and retry up to 3 times when Xero claims the nonce was used.
657
669
  client = Xeroizer::PublicApplication.new(YOUR_OAUTH_CONSUMER_KEY,
658
670
  YOUR_OAUTH_CONSUMER_SECRET,
659
671
  :nonce_used_max_attempts => 3)
@@ -33,6 +33,7 @@ require 'xeroizer/models/allocation'
33
33
  require 'xeroizer/models/branding_theme'
34
34
  require 'xeroizer/models/bank_transaction'
35
35
  require 'xeroizer/models/bank_account'
36
+ require 'xeroizer/models/batch_payment'
36
37
  require 'xeroizer/models/from_bank_account'
37
38
  require 'xeroizer/models/to_bank_account'
38
39
  require 'xeroizer/models/bank_transfer'
@@ -15,8 +15,9 @@ module Xeroizer
15
15
  record :Account
16
16
  record :Allocation
17
17
  record :Attachment
18
- record :BrandingTheme
19
18
  record :Balances
19
+ record :BatchPayment
20
+ record :BrandingTheme
20
21
  record :Contact
21
22
  record :ContactGroup
22
23
  record :CreditNote
@@ -0,0 +1,24 @@
1
+ module Xeroizer
2
+ module Record
3
+
4
+ class BatchPaymentModel < BaseModel
5
+ set_permissions :read
6
+ end
7
+
8
+ class BatchPayment < Base
9
+ guid :batch_payment_id
10
+ string :reference
11
+ string :details
12
+ date :date
13
+ string :type
14
+ string :status
15
+ decimal :total_amount
16
+ boolean :is_reconciled
17
+
18
+ datetime_utc :updated_date_utc, :api_name => 'UpdatedDateUTC'
19
+
20
+ belongs_to :account
21
+ has_many :payments
22
+ end
23
+ end
24
+ end
@@ -11,8 +11,53 @@ module Xeroizer
11
11
  string :name
12
12
  string :status
13
13
 
14
+ set_primary_key :contact_group_id
15
+ list_contains_summary_only true
14
16
  has_many :contacts, :list_complete => true
15
17
 
18
+ # Adding Contact uses different API endpoint
19
+ # https://developer.xero.com/documentation/api/contactgroups#PUT
20
+ def add_contact(contact)
21
+ @contacts ||= []
22
+ @contacts << contact
23
+ end
24
+
25
+ def delete
26
+ status = 'DELETED'
27
+ end
28
+
29
+ def name=(value)
30
+ @modified = true unless @attributes[:name].nil? or @attributes[:name] == value
31
+ @attributes[:name] = value
32
+ end
33
+
34
+ def status=(value)
35
+ @modified = true unless @attributes[:status].nil? or @attributes[:status] == value
36
+ @attributes[:status] = value
37
+ end
38
+
39
+ def save!
40
+ super if new_record? or @modified
41
+ @modified = false
42
+ if @contacts
43
+ req = cg_xml
44
+ app = parent.application
45
+ res = app.http_put(app.client, "#{parent.url}/#{CGI.escape(id)}/Contacts", req)
46
+ parse_save_response(res)
47
+ end
48
+ end
49
+
50
+ def cg_xml
51
+ b = Builder::XmlMarkup.new(:indent => 2)
52
+ b.tag!('Contacts') do
53
+ @contacts.each do |c|
54
+ b.tag!('Contact') do
55
+ b.tag!('ContactID', c.id)
56
+ end
57
+ end
58
+ end
59
+ end
60
+
16
61
  end
17
62
 
18
63
  end
@@ -19,6 +19,7 @@ module Xeroizer
19
19
  decimal :tax_amount
20
20
  decimal :line_amount, :calculated => true
21
21
  decimal :discount_rate
22
+ decimal :discount_amount
22
23
  string :line_item_id
23
24
 
24
25
  has_many :tracking, :model_name => 'TrackingCategoryChild'
@@ -40,8 +41,10 @@ module Xeroizer
40
41
 
41
42
  if quantity && unit_amount
42
43
  total = coerce_numeric(quantity) * coerce_numeric(unit_amount)
43
- if discount_rate
44
+ if discount_rate.nonzero?
44
45
  BigDecimal((total * ((100 - discount_rate) / 100)).to_s).round(2)
46
+ elsif discount_amount
47
+ BigDecimal((total - discount_amount).to_s).round(2)
45
48
  else
46
49
  BigDecimal(total.to_s).round(2)
47
50
  end
@@ -1,19 +1,19 @@
1
1
  module Xeroizer
2
2
  module Report
3
3
  module CellXmlHelper
4
-
4
+
5
5
  def self.included(base)
6
6
  base.extend(ClassMethods)
7
7
  base.send :include, InstanceMethods
8
8
  end
9
-
9
+
10
10
  module ClassMethods
11
-
11
+
12
12
  public
13
-
13
+
14
14
  # Create an instance of Cell from the node.
15
15
  #
16
- # Additionally, parse the attributes and return them as a hash to the
16
+ # Additionally, parse the attributes and return them as a hash to the
17
17
  # cell. If a cell's attributes look like:
18
18
  #
19
19
  # <Attributes>
@@ -22,7 +22,7 @@ module Xeroizer
22
22
  # <Id>account</Id>
23
23
  # </Attribute>
24
24
  # </Attributes>
25
- #
25
+ #
26
26
  # Return a hash like:
27
27
  #
28
28
  # {
@@ -42,17 +42,17 @@ module Xeroizer
42
42
  end
43
43
  cell
44
44
  end
45
-
45
+
46
46
  protected
47
47
 
48
48
  def parse_value(value)
49
49
  case value
50
- when /^[-]?\d+(\.\d+)?$/ then BigDecimal(value)
51
- when /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}$/ then Time.xmlschema(value)
52
- else value
50
+ when /\A[-]?\d+(\.\d+)?\z/ then BigDecimal(value)
51
+ when /\A\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\z/ then Time.xmlschema(value)
52
+ else value
53
53
  end
54
54
  end
55
-
55
+
56
56
  def parse_attribute(attribute_node)
57
57
  id = nil
58
58
  value = nil
@@ -65,10 +65,10 @@ module Xeroizer
65
65
  [id, value]
66
66
  end
67
67
  end
68
-
68
+
69
69
  module InstanceMethods
70
70
  end
71
-
71
+
72
72
  end
73
73
  end
74
74
  end
@@ -1,3 +1,3 @@
1
1
  module Xeroizer
2
- VERSION = "2.19.0".freeze
2
+ VERSION = "2.20.0".freeze
3
3
  end
@@ -26,7 +26,7 @@ class LineItemTest < Test::Unit::TestCase
26
26
  line_item.unit_amount = BigDecimal("1337.00")
27
27
 
28
28
  assert_equal "1337.0", line_item.line_amount.to_s,
29
- "expected line_amount to equal unit_amount times quantity"
29
+ "expected line_amount to equal unit_amount times quantity"
30
30
  end
31
31
 
32
32
  it "line_amount equals unit_amount times quantity minus the discount if there is a discount_rate" do
@@ -36,44 +36,17 @@ class LineItemTest < Test::Unit::TestCase
36
36
  line_item.discount_rate = BigDecimal("12.34")
37
37
 
38
38
  assert_equal "1172.01", line_item.line_amount.to_s,
39
- "expected line_amount to equal unit_amount times quantity minus the discount"
39
+ "expected line_amount to equal unit_amount times quantity minus the discount"
40
40
  end
41
41
 
42
- it "line_amount is zero when quantity is nil or zero" do
42
+ it "line_amount equals unit_amount times quantity minus the discount if there is a discount_amount" do
43
43
  line_item = LineItem.new(nil)
44
-
45
- line_item.quantity = nil
46
- line_item.unit_amount = BigDecimal("1.00")
47
-
48
- assert_equal "0.0", line_item.line_amount.to_s,
49
- "expected line amount to be zero when quantity is nil"
50
-
51
- line_item.quantity = 0
52
- assert_equal "0.0", line_item.line_amount.to_s,
53
- "expected line amount to be zero when quantity is zero"
54
- end
55
-
56
- it "is not possible to set unit_amount to zero" do
57
- line_item = LineItem.new(nil)
58
-
59
- line_item.unit_amount = nil
60
-
61
- assert_equal 0.0, line_item.unit_amount,
62
- "Expected setting unit_amount to nil to be ignored, i.e., it should remain zero"
63
- end
64
-
65
- it "line_amount is zero when unit_amount is nil or zero" do
66
- line_item = LineItem.new(nil)
67
-
68
44
  line_item.quantity = 1
69
- line_item.unit_amount = nil
70
-
71
- assert_equal "0.0", line_item.line_amount.to_s,
72
- "expected line amount to be zero when unit_amount is nil"
45
+ line_item.unit_amount = BigDecimal("1337.00")
46
+ line_item.discount_amount = BigDecimal("164.99")
73
47
 
74
- line_item.unit_amount = BigDecimal("0.00")
75
- assert_equal "0.0", line_item.line_amount.to_s,
76
- "expected line amount to be zero when unit_amount is zero"
48
+ assert_equal "1172.01", line_item.line_amount.to_s,
49
+ "expected line_amount to equal unit_amount times quantity minus the discount amount"
77
50
  end
78
51
 
79
52
  it "coerces decimals when calculating line amount" do
@@ -81,6 +54,6 @@ class LineItemTest < Test::Unit::TestCase
81
54
  line_item.quantity = "1"
82
55
  line_item.unit_amount = 50
83
56
  assert_equal 50, line_item.line_amount,
84
- "expected line amount to be calculated from coerced values"
57
+ "expected line amount to be calculated from coerced values"
85
58
  end
86
59
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xeroizer
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.19.0
4
+ version: 2.20.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wayne Robinson
@@ -251,6 +251,7 @@ files:
251
251
  - lib/xeroizer/models/bank_account.rb
252
252
  - lib/xeroizer/models/bank_transaction.rb
253
253
  - lib/xeroizer/models/bank_transfer.rb
254
+ - lib/xeroizer/models/batch_payment.rb
254
255
  - lib/xeroizer/models/batch_payments.rb
255
256
  - lib/xeroizer/models/bills.rb
256
257
  - lib/xeroizer/models/branding_theme.rb