ledger_sync-quickbooks_online 0.2.2 → 0.3.1

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
  SHA256:
3
- metadata.gz: 76e1fd52bb9aa4705c7a117b1bcc8302675b57de59d3978e8af12d4d08d5df81
4
- data.tar.gz: 7eb7b9cf44ac2e499486197a57bc0b90dafbdcc653aca38185aba0f39d38292f
3
+ metadata.gz: 14034a8009fa439eaadc08eba6148a340cce02849d85ffe1d2f273c95b1a8831
4
+ data.tar.gz: 34fce60e7b7f9eee203365815d717d410a945f2b532ac2ea81370067bf2ef00e
5
5
  SHA512:
6
- metadata.gz: de2202f77b40cd33a9b6f75817807f466989fedf84d4a26b018296ec9902c674264caf6dc8a9edba5b4504ae94fb1c8951463f3f8a74de9258465799b753a213
7
- data.tar.gz: e8778bc8a621fe16b514cc866d3fa8fe646a31a717d2295a8d771f97509942702f855fa2b145cf13e211d945def40984620e4389bbcb5958486c8cf87ec4aa1c
6
+ metadata.gz: 6d10a6ef31062c9ec3c2e4a70fc3563e9d3defd18537b1b981d9ab8a05c5ced276330bd43d0d9d1b2b0deecce1ce3afa466dc4c6e96ac9c71ef8f0aa34f3beb9
7
+ data.tar.gz: 9531d554f92faba1580a288a5978d590d3c8392ebc3b5233c6f05068c236892b43cc1a45da65c2842bbb64e69ddd543f5b1bbae88c16ba246af69c6d77c18690
data/Gemfile.lock CHANGED
@@ -1,9 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ledger_sync-quickbooks_online (0.2.2)
4
+ ledger_sync-quickbooks_online (0.3.1)
5
5
  dotenv
6
- ledger_sync (>= 2.0.0)
6
+ ledger_sync (>= 2.0.2)
7
7
  oauth2
8
8
 
9
9
  GEM
@@ -41,13 +41,13 @@ GEM
41
41
  dry-configurable (0.12.1)
42
42
  concurrent-ruby (~> 1.0)
43
43
  dry-core (~> 0.5, >= 0.5.0)
44
- dry-container (0.7.2)
44
+ dry-container (0.8.0)
45
45
  concurrent-ruby (~> 1.0)
46
46
  dry-configurable (~> 0.1, >= 0.1.3)
47
- dry-core (0.5.0)
47
+ dry-core (0.7.0)
48
48
  concurrent-ruby (~> 1.0)
49
49
  dry-equalizer (0.3.0)
50
- dry-inflector (0.2.0)
50
+ dry-inflector (0.2.1)
51
51
  dry-initializer (3.0.4)
52
52
  dry-logic (1.2.0)
53
53
  concurrent-ruby (~> 1.0)
@@ -75,12 +75,14 @@ GEM
75
75
  dry-schema (~> 1.5, >= 1.5.2)
76
76
  factory_bot (6.1.0)
77
77
  activesupport (>= 5.0.0)
78
- faraday (1.4.2)
78
+ faraday (1.5.0)
79
79
  faraday-em_http (~> 1.0)
80
80
  faraday-em_synchrony (~> 1.0)
81
81
  faraday-excon (~> 1.1)
82
+ faraday-httpclient (~> 1.0.1)
82
83
  faraday-net_http (~> 1.0)
83
84
  faraday-net_http_persistent (~> 1.1)
85
+ faraday-patron (~> 1.0)
84
86
  multipart-post (>= 1.2, < 3)
85
87
  ruby2_keywords (>= 0.0.4)
86
88
  faraday-detailed_logger (2.3.0)
@@ -88,8 +90,10 @@ GEM
88
90
  faraday-em_http (1.0.0)
89
91
  faraday-em_synchrony (1.0.0)
90
92
  faraday-excon (1.1.0)
93
+ faraday-httpclient (1.0.1)
91
94
  faraday-net_http (1.0.1)
92
95
  faraday-net_http_persistent (1.1.0)
96
+ faraday-patron (1.0.0)
93
97
  faraday_middleware (1.0.0)
94
98
  faraday (~> 1.0)
95
99
  fingerprintable (1.2.1)
@@ -100,7 +104,7 @@ GEM
100
104
  iniparse (1.5.0)
101
105
  json (2.5.1)
102
106
  jwt (2.2.3)
103
- ledger_sync (2.0.0)
107
+ ledger_sync (2.0.2)
104
108
  activemodel
105
109
  colorize
106
110
  dry-schema (~> 1.5.4)
@@ -120,7 +124,7 @@ GEM
120
124
  multi_json (1.15.0)
121
125
  multi_xml (0.6.0)
122
126
  multipart-post (2.1.1)
123
- nokogiri (1.11.6)
127
+ nokogiri (1.11.7)
124
128
  mini_portile2 (~> 2.5.0)
125
129
  racc (~> 1.4)
126
130
  oauth2 (1.4.7)
@@ -177,6 +181,7 @@ GEM
177
181
  json (>= 1.8, < 3)
178
182
  simplecov-html (~> 0.10.0)
179
183
  simplecov-html (0.10.2)
184
+ simplecov-lcov (0.8.0)
180
185
  simply_serializable (1.5.1)
181
186
  fingerprintable (>= 1.2.1)
182
187
  sync (0.5.0)
@@ -211,6 +216,7 @@ DEPENDENCIES
211
216
  rake (~> 13.0)
212
217
  rspec (~> 3.2)
213
218
  rubocop
219
+ simplecov-lcov
214
220
  vcr
215
221
  webmock
216
222
 
data/README.md CHANGED
@@ -1,19 +1,217 @@
1
- # LedgerSync::QuickBooksOnline
1
+ <a name="ledger-sync--quick-books-online" />
2
+
3
+ # LedgerSync for QuickBooksOnline
2
4
 
3
5
  [![Build Status](https://travis-ci.org/LedgerSync/ledger_sync-quickbooks_online.svg?branch=master)](https://travis-ci.org/LedgerSync/ledger_sync-quickbooks_online)
4
6
  [![Gem Version](https://badge.fury.io/rb/ledger_sync-quickbooks_online.svg)](https://badge.fury.io/rb/ledger_sync-quickbooks_online)
5
7
  [![Coverage Status](https://coveralls.io/repos/github/LedgerSync/ledger_sync-quickbooks_online/badge.svg?branch=master)](https://coveralls.io/github/LedgerSync/ledger_sync-quickbooks_online?branch=master)
6
8
 
7
- [ledgersync.dev](www.ledgersync.dev)
8
9
 
9
- ## Usage
10
+ <a name="ledger-sync--quick-books-online--join-the-conversation" />
11
+
12
+ ## Join the Conversation
13
+
14
+ [Click here](https://join.slack.com/t/ledger-sync/shared_invite/zt-e5nbl8qc-eOA~5k7bg3p16_l3J7OS~Q) to join our public Slack group.
15
+
16
+
17
+ <a name="architecture" />
18
+
19
+ ## Architecture
20
+
21
+ This gem is built on top of the core [LedgerSync](https://github.com/LedgerSync/ledger_sync) gem. If you are unfamiliar with the LedgerSync architecture, it is recommended to first read through the [LedgerSync documentation](https://github.com/LedgerSync/ledger_sync).
22
+
23
+ <a name="getting-started" />
24
+
25
+ ## Installation
26
+
27
+ <a name="getting-started--installation--gemfile" />
28
+
29
+ ### Gemfile
30
+
31
+ Add this line to your application’s Gemfile:
32
+
33
+ ```
34
+ gem 'ledger_sync-quickbooks_online'
35
+ ```
36
+
37
+ And then execute:
38
+ ```
39
+ bundle
40
+ ```
41
+
42
+ <a name="getting-started--installation--directly" />
43
+
44
+ ### Directly
45
+
46
+ Or install it yourself as:
47
+
48
+ ```
49
+ gem install ledger_sync-quickbooks_online
50
+ ```
51
+
52
+ <a name="getting-started--oauth" />
53
+
54
+ ## OAuth
55
+
56
+ QuickBooks Online utilizes OAuth 2.0, which requires frequent refreshing of the access and refresh token. The client will handle this automatically, attempting a single token refresh on any single request authentication failure due to an expired access token.
57
+
58
+ The `LedgerSync::QuickBooksOnline::Client` implements a `ledger_attributes_to_save` class method, which is an array of attributes that may change as the client is used (e.g. `access_token`). You can also call the instance method `ledger_attributes_to_save` which will be a hash of these current values. It is a best practice to always store these attributes
59
+ if you are saving access tokens in your database.
60
+
61
+ Should you fail to save the current `refresh_token`, you will have to ask your user to reconnect to QuickBooks Online again.
62
+
63
+ <a name="getting-started--oauth--retrieveAccessToken" />
64
+
65
+ ### Retrieve Access Token
66
+
67
+ The library contains a lightweight script that is helpful in retrieving and refreshing access tokens. It is particularly useful during development, when you do not have an application to handle the redirects and OAuth code exchange. To use, do the following:
68
+
69
+ 1. Create a `.env.local` file in the library root.
70
+ 2. Add values for `QUICKBOOKS_ONLINE_CLIENT_ID` and `QUICKBOOKS_ONLINE_CLIENT_SECRET` (you can copy `.env.test` as a template).
71
+ 3. Ensure your developer application in [the QuickBooks Online developer portal](https://developer.intuit.com) contains this redirect URI: `http://localhost:5678` (note: no trailing slash and port configurable with `PORT` environment variable)
72
+ 4. Run `ruby bin/quickbooks_online_oauth_server.rb` from the library root (note: it must run from the root in order to update `.env.local`).
73
+ 5. Visit the URL output in the terminal.
74
+ 6. Upon redirect back to `http://localhost:5678`, the new values will be printed to the console and saved back to your `.env.local`
75
+
76
+ <a name="getting-started--oauth--ledger-helper-methods" />
77
+
78
+ ### Ledger Helper Methods
79
+
80
+ The client also implements some helper methods for getting tokens. For example, you can set up a client using the following:
81
+
82
+ ```ruby
83
+ # Retrieve the following values from Intuit app settings
84
+ client_id = ENV['QUICKBOOKS_ONLINE_CLIENT_ID']
85
+ client_secret = ENV['QUICKBOOKS_ONLINE_CLIENT_SECRET']
86
+ redirect_uri = 'http://localhost:3000'
87
+
88
+ oauth_client = LedgerSync::QuickBooksOnline::OAuthClientHelper.new(
89
+ client_id: client_id,
90
+ client_secret: client_secret
91
+ )
92
+
93
+ puts oauth_client.authorization_url(redirect_uri: redirect_uri)
94
+
95
+ # Visit on the output URL and authorize a company.
96
+ # You will be redirected back to the redirect_uri.
97
+ # Copy the full url from your browser:
98
+
99
+ uri = 'https://localhost:3000/?code=FOO&state=BAR&realm_id=BAZ'
100
+
101
+ client = LedgerSync::QuickBooksOnline::Client.new_from_oauth_client_uri(
102
+ oauth_client: oauth_client,
103
+ uri: uri
104
+ )
105
+
106
+ # You can test that the auth works:
107
+
108
+ client.refresh!
109
+ ```
110
+
111
+ **Note: If you have a `.env.local` file storing your secrets, the client will automatically update the variables and record previous values whenever values change*
112
+
113
+ <a name="client" />
114
+
115
+ # Client
116
+
117
+ You can instantiate a client like so:
118
+
119
+ ```ruby
120
+ client = LedgerSync::Ledgers::QuickBooksOnline::Client.new(
121
+ access_token: access_token, # assuming this is defined
122
+ client_id: ENV['QUICKBOOKS_ONLINE_CLIENT_ID'],
123
+ client_secret: ENV['QUICKBOOKS_ONLINE_CLIENT_SECRET'],
124
+ realm_id: ENV['QUICKBOOKS_ONLINE_REALM_ID'],
125
+ refresh_token: refresh_token, # assuming this is defined
126
+ update_dotenv: true # Optional: defaults to true
127
+ )
128
+ ```
129
+
130
+ ## `update_dotenv`
131
+
132
+ When `update_dotenv` is `true`, the library will automatically update your `.env.local` (or otherwise configured `.env` file).
133
+
134
+ When `update_dotenv` is `false`, you will need to manually save the refreshed attributes after each operation call. The `result` is the output of calling `operation.perform` and gives you access to the updated `client`. You can access the new values by doing the following:
135
+
136
+ ```ruby
137
+ result.operation.client.ledger_attributes_to_save.each do |key, value|
138
+ # save values
139
+ end
140
+ ```
141
+
142
+ <a name="resources" />
143
+
144
+ # Resources
145
+
146
+ To see all the available resources, you can call `LedgerSync::QuickBooksOnline::Client.resources`, which will give you a hash of keys and resource classes.
147
+
148
+ ## Resource Attributes
149
+
150
+
151
+ To see all the available attributes of a resource you can call the `resource_attributes` class method. For example, you can call `LedgerSync::QuickBooksOnline::Customer.resource_attributes`, which will return a `LedgerSync::ResourceAttributeSet`. This object allows you to see the attributes and the type of each attribute. For example, you can see the attribute `DisplayName` and its type by typing the following:
152
+
153
+ ```bash
154
+ > LedgerSync::QuickBooksOnline::Customer.resource_attributes.attributes[:DisplayName]
155
+ => #<LedgerSync::ResourceAttribute:0x00007fef3dafe568 @name=:DisplayName, @resource_class=LedgerSync::QuickBooksOnline::Customer, @type=#<LedgerSync::Type::String:0x00007fef3dafe540 @true="t", @false="f", @precision=nil, @scale=nil, @limit=nil>, @value=nil>
156
+ ```
157
+ ## Resource Operations
158
+
159
+
160
+ To see all the available operations for a given resource you can call the `operations` class method. For example, you can call `LedgerSync::QuickBooksOnline::Customer.operations`, which will return a hash of keys mapped to operation classes. For example, you can try the following:
161
+
162
+ ```bash
163
+ > LedgerSync::QuickBooksOnline::Customer.operations
164
+ => {:find=>LedgerSync::QuickBooksOnline::Customer::Operations::Find, :create=>LedgerSync::QuickBooksOnline::Customer::Operations::Create, :update=>LedgerSync::QuickBooksOnline::Customer::Operations::Update}
165
+ ```
166
+
167
+ <a name="examples" />
168
+
169
+ # Examples
170
+
171
+ ## Create a Customer
172
+
173
+ ```ruby
174
+ client = LedgerSync::Ledgers::QuickBooksOnline::Client.new(
175
+ access_token: access_token, # assuming this is defined
176
+ client_id: ENV['QUICKBOOKS_ONLINE_CLIENT_ID'],
177
+ client_secret: ENV['QUICKBOOKS_ONLINE_CLIENT_SECRET'],
178
+ realm_id: ENV['QUICKBOOKS_ONLINE_REALM_ID'],
179
+ refresh_token: refresh_token # assuming this is defined
180
+ )
181
+
182
+ resource = LedgerSync::Ledgers::QuickBooksOnline::Customer.new(
183
+ DisplayName: 'Sample Customer',
184
+ external_id: customer_external_id # A unique ID from your platform
185
+ )
186
+
187
+ operation = LedgerSync::Ledgers::QuickBooksOnline::Customer::Operations::Create.new(
188
+ client: client,
189
+ resource: resource
190
+ )
191
+
192
+ result = operation.perform # Returns a LedgerSync::OperationResult
193
+
194
+ if result.success?
195
+ resource = result.operation.resource
196
+ # Do something with resource
197
+ else # result.failure?
198
+ raise result.error
199
+ end
200
+
201
+ ```
202
+
203
+ <a name="errors" />
204
+
205
+ # Errors
206
+
207
+ While LedgerSync tries to catch and translate errors, not all errors will be caught (e.g. new errors from the QuickBooks Online API). In these cases, you can rescue a generic `LedgerSync::OperationError` and determine what to do based on the response body.
208
+
209
+ [QuickBooks Online Error Documentation](https://developer.intuit.com/app/developer/qbo/docs/develop/troubleshooting/error-codes)
210
+
211
+
212
+
213
+ <a name="ledger-sync--quick-books-online--license" />
10
214
 
11
- This template ledger enables you to easily create your own ledger for public or private use. Although this is not an
12
- exhaustive list, a good place to start assuming your ledger name is `NewLedger`:
215
+ ## License
13
216
 
14
- 1. Find and replace all `QUICK_BOOKS_ONLINE` with `NEW_LEDGER`
15
- 2. Find and replace all `QuickBooksOnline` with `NewLedger`
16
- 3. Find and replace all `quickbooks_online` with `new_ledger`
17
- 4. Find and replace all `QuickBooks Online` with `New Ledger`
18
- 5. Find and replace all `quickbooks_online` directories and files with `new_ledger`
19
- 6. Remove `SampleResource` example files.
217
+ This gem and all code contained in the repository is licensed under the same license as the core [LedgerSync](https://github.com/LedgerSync/ledger_sync) license. You can view all license details in the [LedgerSync](https://github.com/LedgerSync/ledger_sync) repo.
@@ -37,10 +37,11 @@ Gem::Specification.new do |spec|
37
37
  spec.add_development_dependency('rake', '~> 13.0')
38
38
  spec.add_development_dependency('rspec', '~> 3.2')
39
39
  spec.add_development_dependency('rubocop', '>= 0')
40
+ spec.add_development_dependency('simplecov-lcov')
40
41
  spec.add_development_dependency('vcr', '>= 0')
41
42
  spec.add_development_dependency('webmock', '>= 0')
42
43
  spec.add_runtime_dependency('dotenv')
43
- spec.add_runtime_dependency('ledger_sync', '>= 2.0.0')
44
+ spec.add_runtime_dependency('ledger_sync', '>= 2.0.2')
44
45
  # spec.add_runtime_dependency('nokogiri', '>= 0')
45
46
  spec.add_runtime_dependency('oauth2', '>= 0')
46
47
  end
@@ -34,6 +34,8 @@ module LedgerSync
34
34
  client_secret:,
35
35
  realm_id:,
36
36
  refresh_token:,
37
+ expires_at: nil,
38
+ refresh_token_expires_at: nil,
37
39
  test: false,
38
40
  update_dotenv: true
39
41
  )
@@ -42,6 +44,8 @@ module LedgerSync
42
44
  @client_secret = client_secret
43
45
  @realm_id = realm_id
44
46
  @refresh_token = refresh_token
47
+ @expires_at = expires_at
48
+ @refresh_token_expires_at = refresh_token_expires_at
45
49
  @test = test
46
50
  @update_dotenv = update_dotenv
47
51
 
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative '../account/deserializer'
3
4
  require_relative '../reference/deserializer'
4
5
  require_relative '../payment_line/deserializer'
5
6
 
@@ -32,8 +32,10 @@ module LedgerSync
32
32
 
33
33
  def match?
34
34
  code == 3200 ||
35
- message.include?('authenticationfailed') ||
36
- message.include?('errorcode=003200')
35
+ code == '3200' ||
36
+ message.downcase.include?('statuscode=401') ||
37
+ message.downcase.include?('authenticationfailed') ||
38
+ message.downcase.include?('errorcode=003200')
37
39
  end
38
40
  end
39
41
 
@@ -48,8 +50,9 @@ module LedgerSync
48
50
 
49
51
  def match?
50
52
  code == 3100 ||
51
- message.include?('authorizationfailed') ||
52
- message.include?('errorcode=003100')
53
+ code == '3100' ||
54
+ message.downcase.include?('authorizationfailed') ||
55
+ message.downcase.include?('errorcode=003100')
53
56
  end
54
57
  end
55
58
 
@@ -3,7 +3,7 @@
3
3
  # :nocov:
4
4
  module LedgerSync
5
5
  module QuickBooksOnline
6
- VERSION = '0.2.2'
6
+ VERSION = '0.3.1'
7
7
 
8
8
  def self.version(args = {})
9
9
  pre = args.fetch(:pre, false)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ledger_sync-quickbooks_online
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Modern Treasury
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-06-02 00:00:00.000000000 Z
11
+ date: 2021-07-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: awesome_print
@@ -164,6 +164,20 @@ dependencies:
164
164
  - - ">="
165
165
  - !ruby/object:Gem::Version
166
166
  version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: simplecov-lcov
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
167
181
  - !ruby/object:Gem::Dependency
168
182
  name: vcr
169
183
  requirement: !ruby/object:Gem::Requirement
@@ -212,14 +226,14 @@ dependencies:
212
226
  requirements:
213
227
  - - ">="
214
228
  - !ruby/object:Gem::Version
215
- version: 2.0.0
229
+ version: 2.0.2
216
230
  type: :runtime
217
231
  prerelease: false
218
232
  version_requirements: !ruby/object:Gem::Requirement
219
233
  requirements:
220
234
  - - ">="
221
235
  - !ruby/object:Gem::Version
222
- version: 2.0.0
236
+ version: 2.0.2
223
237
  - !ruby/object:Gem::Dependency
224
238
  name: oauth2
225
239
  requirement: !ruby/object:Gem::Requirement