xero-ruby 2.0.0 → 2.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c469455936635d16067b4269ad96bda3ae65b7d8f9a34399532b380a7f34d72b
4
- data.tar.gz: '039093400b943441b6f987a279cc981c23052e6575047f301ba9527192b26d34'
3
+ metadata.gz: 333abb6f3c4cb576451f3fa4f47be4843502e06acb09be2a918ec2f2f313b4c2
4
+ data.tar.gz: adba7b3e9fac9cd66ea70935598c08fcc3506221fb27219200686d9630a2b3ce
5
5
  SHA512:
6
- metadata.gz: bcc87f93d7203239d688b12e4d0f7496953fb1563cd4d3865384f3d9a51342d18b44029c8c2af4670d55e71c27e0561df1c4e24d05bea7afd64da1ac679d0610
7
- data.tar.gz: 9362cfe1d6822dc0caedad0213ec31c35172503bf8da0af3c145e80c5794dbed5122fc739d02ed7ce4234db8d9e159d7458cea082efe42152a31be4106a7b377
6
+ metadata.gz: 4a07d78ad0a2f8c3be6f2ee677342a85dfc862b075095820cc193a572329218ad0bc055d0a1d2fe9484e7cf208056dfd55040b2f1b6dd6b6600589caee3253d5
7
+ data.tar.gz: a7578f993ff86feaa3ef0d221188a64210f5b8ceec35e0fbdb7749424532c8f83a49cfdb9f76cb5b0e832f5d526b9b063a1413743752632906a7f89e332e154a
@@ -1,8 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- xero-ruby (0.4.1)
5
- faraday (~> 0.14, >= 0.14.0)
4
+ xero-ruby (2.0.1)
5
+ faraday (~> 1.0.1, >= 1.0.1)
6
6
  json (~> 2.1, >= 2.1.0)
7
7
 
8
8
  GEM
@@ -12,10 +12,10 @@ GEM
12
12
  byebug (11.1.3)
13
13
  coderay (1.1.3)
14
14
  diff-lcs (1.3)
15
- faraday (0.17.3)
15
+ faraday (1.0.1)
16
16
  multipart-post (>= 1.2, < 3)
17
17
  jaro_winkler (1.5.4)
18
- json (2.3.0)
18
+ json (2.3.1)
19
19
  method_source (1.0.0)
20
20
  multipart-post (2.1.1)
21
21
  parallel (1.19.1)
@@ -60,7 +60,7 @@ PLATFORMS
60
60
  DEPENDENCIES
61
61
  pry-byebug
62
62
  rake (~> 12.3.3)
63
- rspec
63
+ rspec (~> 3.6, >= 3.6.0)
64
64
  rubocop (~> 0.66.0)
65
65
  xero-ruby!
66
66
 
data/README.md CHANGED
@@ -129,7 +129,7 @@ Here is the basic workflow of using SDK once you have a valid `access_token` (an
129
129
  # reference `Authorization & Callback` to first store a valid token_set on the `xero_client`
130
130
  xero_client.refresh_token_set(user.token_set)
131
131
 
132
- # Accounting API set (https://github.com/XeroAPI/xero-ruby/blob/master/accounting/lib/xero-ruby/api/accounting_api.rb)
132
+ # Using the Accounting API set (https://github.com/XeroAPI/xero-ruby/blob/master/accounting/lib/xero-ruby/api/accounting_api.rb)
133
133
 
134
134
  # Examples
135
135
  invoices = xero_client.accounting_api.get_invoices(user.active_tenant_id).invoices
@@ -140,10 +140,25 @@ Here is the basic workflow of using SDK once you have a valid `access_token` (an
140
140
  invoices = { invoices: [{ type: XeroRuby::Accounting::Invoice::ACCREC, contact: { contact_id: contacts[0].contact_id }, line_items: [{ description: "Acme Tires", quantity: BigDecimal("2.0"), unit_amount: BigDecimal("20.99"), account_code: "600", tax_type: XeroRuby::Accounting::TaxType::NONE }], date: "2019-03-11", due_date: "2018-12-10", reference: "Website Design", status: XeroRuby::Accounting::Invoice::DRAFT }]}
141
141
  invoice = xero_client.accounting_api.create_invoices(current_user.active_tenant_id, invoices).invoices.first
142
142
 
143
+ # all money and fields requiring advanced precision utilize BigDecimal
144
+ puts invoice.unit_amount
145
+ => 0.2099e2
146
+
147
+ puts invoice.unit_amount.class
148
+ => BigDecimal
149
+
150
+ puts invoice.unit_amount.to_s("F")
151
+ => "20.99"
152
+
153
+ # or if using Rails https://api.rubyonrails.org/classes/ActionView/Helpers/NumberHelper.html#method-i-number_to_currency
154
+ number_to_currency(invoice.unit_amount, :unit => "$")
155
+
156
+ # creating an object History record
143
157
  payment = xero_client.accounting_api.get_payments(current_user.active_tenant_id).payments.first
144
158
  history_records = { history_records:[ { details: "This payment now has some History #{rand(10000)}" } ]}
145
159
  payment_history = xero_client.accounting_api.create_payment_history(user.active_tenant_id, payment.payment_id, history_records)
146
160
 
161
+ # creating an object Attachment record
147
162
  account = xero_client.accounting_api.get_accounts(current_user.active_tenant_id).accounts.first
148
163
  file_name = "an-account-filename.png"
149
164
  opts = {
@@ -152,7 +167,7 @@ Here is the basic workflow of using SDK once you have a valid `access_token` (an
152
167
  file = File.read(Rails.root.join('app/assets/images/xero-api.png'))
153
168
  attachment = xero_client.accounting_api.create_account_attachment_by_file_name(current_user.active_tenant_id, @account.account_id, file_name, file, opts)
154
169
 
155
- # Asset API set (https://github.com/XeroAPI/xero-ruby/blob/master/accounting/lib/xero-ruby/api/asset_api.rb)
170
+ # Using the Asset API set (https://github.com/XeroAPI/xero-ruby/blob/master/accounting/lib/xero-ruby/api/asset_api.rb)
156
171
  asset = {
157
172
  "assetName": "AssetName: #{rand(10000)}",
158
173
  "assetNumber": "Asset: #{rand(10000)}",
@@ -160,7 +175,7 @@ Here is the basic workflow of using SDK once you have a valid `access_token` (an
160
175
  }
161
176
  asset = xero_client.asset_api.create_asset(current_user.active_tenant_id, asset)
162
177
 
163
- # Project API set (https://github.com/XeroAPI/xero-ruby/blob/master/docs/projects/ProjectApi.md)
178
+ # Using the Project API set (https://github.com/XeroAPI/xero-ruby/blob/master/docs/projects/ProjectApi.md)
164
179
  projects = xero_client.project_api.get_projects(current_user.active_tenant_id).items
165
180
  ```
166
181
 
@@ -9,9 +9,14 @@ mv xero-ruby-<vsn>.gem xero-ruby.gem
9
9
  > xero-ruby-oauth2-app
10
10
 
11
11
  Replace gem file with local path:
12
- `gem 'xero-ruby', path: '/Users/chris.knight/code/sdks/xero-ruby/'`
13
12
  ```bash
13
+ gem 'xero-ruby', path: '/Users/chris.knight/code/sdks/xero-ruby/'
14
14
  bundle install
15
15
  ```
16
16
 
17
- Deploying to Rubygems
17
+ Deploying to Rubygems
18
+
19
+ ```bash
20
+ gem build
21
+ gem push xero-ruby-<vsn>.gem
22
+ ```
@@ -500,30 +500,35 @@ module XeroRuby
500
500
  elsif key.is_a? String
501
501
  camelize(key, first_upper)
502
502
  else
503
- key # Awrence can't camelize anything except strings and symbols
503
+ key # can't camelize anything except strings and symbols
504
504
  end
505
505
  end
506
506
 
507
- def camelize(snake_word, first_upper = true)
507
+ def camelize(word, first_upper = true)
508
508
  if first_upper
509
- str = snake_word.to_s
509
+ str = word.to_s
510
510
  str = gsubbed(str, /(?:^|_)([^_\s]+)/)
511
511
  str = gsubbed(str, %r{/([^/]*)}, "::")
512
512
  str
513
513
  else
514
- parts = snake_word.split("_", 2)
514
+ parts = word.split("_", 2)
515
515
  parts[0] << camelize(parts[1]) if parts.size > 1
516
516
  parts[0] || ""
517
517
  end
518
518
  end
519
519
 
520
520
  def gsubbed(str, pattern, extra = "")
521
- key_map_scronyms = { "id" => "ID" }
521
+ key_map_scronyms = { "id": "ID" }
522
522
  str = str.gsub(pattern) do
523
- extra + (key_map_scronyms[Regexp.last_match(1)] || Regexp.last_match(1).capitalize)
523
+ extra + (key_map_scronyms[Regexp.last_match(1)] || capitalize_first(Regexp.last_match(1)))
524
524
  end
525
525
  str
526
526
  end
527
+
528
+ def capitalize_first(word)
529
+ split = word.split('')
530
+ "#{split[0].capitalize}#{split[1..-1].join}"
531
+ end
527
532
  # END - Re-serializes snake_cased params to PascalCase required by XeroAPI
528
533
 
529
534
  # Build parameter value according to the given collection format.
@@ -11,5 +11,5 @@ OpenAPI Generator version: 4.3.1
11
11
  =end
12
12
 
13
13
  module XeroRuby
14
- VERSION = '2.0.0'
14
+ VERSION = '2.0.2'
15
15
  end
@@ -81,14 +81,103 @@ describe XeroRuby::ApiClient do
81
81
  end
82
82
 
83
83
  describe "#object_to_hash modifies a hash from snake_case to PascalCase" do
84
- it 'Maniuplates a contact object correctly' do
84
+ contact_after = {:Contacts=>[{:Name=>"Bruce Banner", :EmailAddress=>"hulk@avengers.com", :Phones=>[{:PhoneType=>"MOBILE", :PhoneNumber=>"555-1212", :PhoneAreaCode=>"415"}], :PaymentTerms=>{:Bills=>{:Day=>15, :Type=>"OFCURRENTMONTH"}, :Sales=>{:Day=>10, :Type=>"DAYSAFTERBILLMONTH"}}}]}
85
+
86
+ it 'Serializes snake_case object correctly' do
85
87
  contact_before = {:contacts=>[{:name=>"Bruce Banner", :email_address=>"hulk@avengers.com", :phones=>[{:phone_type=>"MOBILE", :phone_number=>"555-1212", :phone_area_code=>"415"}], :payment_terms=>{:bills=>{:day=>15, :type=>"OFCURRENTMONTH"}, :sales=>{:day=>10, :type=>"DAYSAFTERBILLMONTH"}}}]}
86
- contact_after = {:Contacts=>[{:Name=>"Bruce Banner", :EmailAddress=>"hulk@avengers.com", :Phones=>[{:PhoneType=>"MOBILE", :PhoneNumber=>"555-1212", :PhoneAreaCode=>"415"}], :PaymentTerms=>{:Bills=>{:Day=>15, :Type=>"OFCURRENTMONTH"}, :Sales=>{:Day=>10, :Type=>"DAYSAFTERBILLMONTH"}}}]}
87
88
  api_client = XeroRuby::ApiClient.new
88
89
  expect(api_client.object_to_hash(contact_before)).to eq(contact_after)
89
90
  end
90
91
 
91
- # todo - insert every model PascalCase conversion as they are added as sample app examples
92
+ it 'Serializes camelCase object correctly' do
93
+ json_before = {
94
+ type: "ACCREC",
95
+ invoiceNumber: "INV-01",
96
+ dueDate: "2020-01-01",
97
+ lineItems: [
98
+ { quantity: 1.0, unitAmount: 20 }
99
+ ]
100
+ }
101
+ json_after = {
102
+ Type: "ACCREC",
103
+ InvoiceNumber: "INV-01",
104
+ DueDate: "2020-01-01",
105
+ LineItems: [
106
+ { Quantity: 1.0, UnitAmount: 20 }
107
+ ]
108
+ }
109
+ api_client = XeroRuby::ApiClient.new
110
+ expect(api_client.object_to_hash(json_before)).to eq(json_after)
111
+ end
112
+
113
+ it 'Serializes json with multiple nested objects correctly' do
114
+ json_before = {
115
+ "line_Items":[
116
+ {
117
+ "quantity":1.0,
118
+ "unit_amount":20,
119
+ "sub_Items":[
120
+ {
121
+ "quantity":1.0,
122
+ "unit_amount":20
123
+ },
124
+ {
125
+ "quantity":1.0,
126
+ "Unit_amount":20,
127
+ "Deep_Items":[
128
+ {
129
+ "quantity":1.0,
130
+ "unit_amount":20
131
+ },
132
+ {
133
+ "quantity":1.0,
134
+ "unit_Amount":20
135
+ }
136
+ ]
137
+ }
138
+ ]
139
+ }
140
+ ]
141
+ }
142
+
143
+ json_after = {
144
+ "LineItems":[
145
+ {
146
+ "UnitAmount":20,
147
+ "Quantity":1.0,
148
+ "SubItems":[
149
+ {
150
+ "UnitAmount":20,
151
+ "Quantity":1.0
152
+ },
153
+ {
154
+ "UnitAmount":20,
155
+ "Quantity":1.0,
156
+ "DeepItems":[
157
+ {
158
+ "UnitAmount":20,
159
+ "Quantity":1.0
160
+ },
161
+ {
162
+ "UnitAmount":20,
163
+ "Quantity":1.0
164
+ }
165
+ ]
166
+ }
167
+ ]
168
+ }
169
+ ]
170
+ }
171
+ api_client = XeroRuby::ApiClient.new
172
+ expect(api_client.object_to_hash(json_before)).to eq(json_after)
173
+ end
174
+
175
+ it 'Serializes mixed cased keys correctly' do
176
+ contact_after = { :Contacts=>[{:Name=>"Bruce Banner", :EmailAddress=>"hulk@avengers.com", :Phones=>[{:PhoneType=>"MOBILE", :PhoneNumber=>"555-1212", :PhoneAreaCode=>"415"}], :PaymentTerms=>{:Bills=>{:Day=>15, :Type=>"OFCURRENTMONTH"}, :Sales=>{:Day=>10, :Type=>"DAYSAFTERBILLMONTH"}}}]}
177
+ contact_before = {:contacts=>[{:name=>"Bruce Banner", :emailAddress=>"hulk@avengers.com", :phones=>[{:phoneType=>"MOBILE", :phone_number=>"555-1212", :phone_areaCode=>"415"}], :Payment_terms=>{:bills=>{:day=>15, :type=>"OFCURRENTMONTH"}, :sales=>{:day=>10, :type=>"DAYSAFTERBILLMONTH"}}}]}
178
+ api_client = XeroRuby::ApiClient.new
179
+ expect(api_client.object_to_hash(contact_before)).to eq(contact_after)
180
+ end
92
181
  end
93
182
 
94
183
  describe '#build_collection_param' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xero-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Xero API Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-08-05 00:00:00.000000000 Z
11
+ date: 2020-08-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday