ledger_sync-quickbooks_online 0.3.0 → 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: c4b5e19720b4663f9e5ffa823f130bb7c45e4a0494b13cd6d021d53e1c9c4c8f
4
- data.tar.gz: a17b5989f741070a84cd18c01b0e94e605cfb9ebe00cf0406bf0a23a52ec4bae
3
+ metadata.gz: 14034a8009fa439eaadc08eba6148a340cce02849d85ffe1d2f273c95b1a8831
4
+ data.tar.gz: 34fce60e7b7f9eee203365815d717d410a945f2b532ac2ea81370067bf2ef00e
5
5
  SHA512:
6
- metadata.gz: ff2c96e34e1b6adb51af4aff4565735acdb8a50ac6b3a458ad5497b866506eae2b1986fdc0da5ff3daca89022fef610e8d6386300e189ad13bd797afdafdf891
7
- data.tar.gz: b819e78fb472bb129c7ae51afec95aa2e4b46cbfec100bb26ce0f686f0c084714906c85ff52ad5d6fbbfab7dda104c5d957e25ff49c0679d4b107241dbf995e3
6
+ metadata.gz: 6d10a6ef31062c9ec3c2e4a70fc3563e9d3defd18537b1b981d9ab8a05c5ced276330bd43d0d9d1b2b0deecce1ce3afa466dc4c6e96ac9c71ef8f0aa34f3beb9
7
+ data.tar.gz: 9531d554f92faba1580a288a5978d590d3c8392ebc3b5233c6f05068c236892b43cc1a45da65c2842bbb64e69ddd543f5b1bbae88c16ba246af69c6d77c18690
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ledger_sync-quickbooks_online (0.3.0)
4
+ ledger_sync-quickbooks_online (0.3.1)
5
5
  dotenv
6
6
  ledger_sync (>= 2.0.2)
7
7
  oauth2
@@ -44,10 +44,10 @@ GEM
44
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.6.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)
@@ -115,11 +119,13 @@ GEM
115
119
  rack (~> 2.2.3)
116
120
  resonad
117
121
  simply_serializable (>= 1.5.1)
122
+ mini_portile2 (2.5.3)
118
123
  minitest (5.14.4)
119
124
  multi_json (1.15.0)
120
125
  multi_xml (0.6.0)
121
126
  multipart-post (2.1.1)
122
- nokogiri (1.11.7-x86_64-darwin)
127
+ nokogiri (1.11.7)
128
+ mini_portile2 (~> 2.5.0)
123
129
  racc (~> 1.4)
124
130
  oauth2 (1.4.7)
125
131
  faraday (>= 0.8, < 2.0)
@@ -175,6 +181,7 @@ GEM
175
181
  json (>= 1.8, < 3)
176
182
  simplecov-html (~> 0.10.0)
177
183
  simplecov-html (0.10.2)
184
+ simplecov-lcov (0.8.0)
178
185
  simply_serializable (1.5.1)
179
186
  fingerprintable (>= 1.2.1)
180
187
  sync (0.5.0)
@@ -209,6 +216,7 @@ DEPENDENCIES
209
216
  rake (~> 13.0)
210
217
  rspec (~> 3.2)
211
218
  rubocop
219
+ simplecov-lcov
212
220
  vcr
213
221
  webmock
214
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,6 +37,7 @@ 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')
@@ -34,8 +34,8 @@ module LedgerSync
34
34
  client_secret:,
35
35
  realm_id:,
36
36
  refresh_token:,
37
- expires_at:,
38
- refresh_token_expires_at:,
37
+ expires_at: nil,
38
+ refresh_token_expires_at: nil,
39
39
  test: false,
40
40
  update_dotenv: true
41
41
  )
@@ -3,7 +3,7 @@
3
3
  # :nocov:
4
4
  module LedgerSync
5
5
  module QuickBooksOnline
6
- VERSION = '0.3.0'
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.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Modern Treasury
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-06-12 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
@@ -434,7 +448,7 @@ files:
434
448
  homepage: https://www.ledgersync.dev
435
449
  licenses: []
436
450
  metadata: {}
437
- post_install_message:
451
+ post_install_message:
438
452
  rdoc_options: []
439
453
  require_paths:
440
454
  - lib
@@ -449,8 +463,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
449
463
  - !ruby/object:Gem::Version
450
464
  version: '0'
451
465
  requirements: []
452
- rubygems_version: 3.1.6
453
- signing_key:
466
+ rubygems_version: 3.0.3
467
+ signing_key:
454
468
  specification_version: 4
455
469
  summary: Sync common objects to accounting software.
456
470
  test_files: []