ledger_sync 1.1.3 → 1.3.1
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 +4 -4
- data/.env.template +25 -0
- data/.gitignore +3 -1
- data/.rubocop_todo.yml +4 -1
- data/.travis.yml +1 -1
- data/Gemfile.lock +59 -25
- data/README.md +160 -8
- data/_config.yml +1 -0
- data/bin/qa +3 -0
- data/ledger_sync.gemspec +4 -0
- data/lib/ledger_sync.rb +40 -30
- data/lib/ledger_sync/adaptor_configuration.rb +17 -11
- data/lib/ledger_sync/adaptor_configuration_store.rb +13 -9
- data/lib/ledger_sync/adaptors/adaptor.rb +9 -1
- data/lib/ledger_sync/adaptors/ledger_serializer.rb +3 -6
- data/lib/ledger_sync/adaptors/ledger_serializer_attribute_set.rb +1 -1
- data/lib/ledger_sync/adaptors/ledger_serializer_type/references_many_type.rb +1 -1
- data/lib/ledger_sync/adaptors/mixins/infer_adaptor_class_mixin.rb +24 -0
- data/lib/ledger_sync/adaptors/mixins/infer_ledger_serializer_mixin.rb +31 -0
- data/lib/ledger_sync/adaptors/mixins/infer_resource_class_mixin.rb +22 -0
- data/lib/ledger_sync/adaptors/mixins/offset_and_limit_pagination_searcher_mixin.rb +37 -0
- data/lib/ledger_sync/adaptors/netsuite/account/ledger_deserializer.rb +24 -0
- data/lib/ledger_sync/adaptors/netsuite/account/ledger_serializer.rb +22 -0
- data/lib/ledger_sync/adaptors/netsuite/account/operations/create.rb +28 -0
- data/lib/ledger_sync/adaptors/netsuite/account/operations/find.rb +28 -0
- data/lib/ledger_sync/adaptors/netsuite/account/searcher.rb +28 -0
- data/lib/ledger_sync/adaptors/netsuite/adaptor.rb +145 -0
- data/lib/ledger_sync/adaptors/netsuite/config.rb +6 -0
- data/lib/ledger_sync/adaptors/netsuite/currency/deledger_serializer.rb +28 -0
- data/lib/ledger_sync/adaptors/netsuite/currency/ledger_serializer.rb +25 -0
- data/lib/ledger_sync/adaptors/netsuite/currency/operations/create.rb +25 -0
- data/lib/ledger_sync/adaptors/netsuite/currency/operations/delete.rb +23 -0
- data/lib/ledger_sync/adaptors/netsuite/currency/operations/find.rb +23 -0
- data/lib/ledger_sync/adaptors/netsuite/currency/operations/update.rb +23 -0
- data/lib/ledger_sync/adaptors/netsuite/customer/ledger_deserializer.rb +27 -0
- data/lib/ledger_sync/adaptors/netsuite/customer/ledger_serializer.rb +38 -0
- data/lib/ledger_sync/adaptors/netsuite/customer/operations/create.rb +24 -0
- data/lib/ledger_sync/adaptors/netsuite/customer/operations/delete.rb +24 -0
- data/lib/ledger_sync/adaptors/netsuite/customer/operations/find.rb +24 -0
- data/lib/ledger_sync/adaptors/netsuite/customer/operations/update.rb +24 -0
- data/lib/ledger_sync/adaptors/netsuite/ledger_serializer.rb +30 -0
- data/lib/ledger_sync/adaptors/netsuite/ledger_serializer_type/reference_type.rb +24 -0
- data/lib/ledger_sync/adaptors/netsuite/ledger_serializer_type/subsidiary_type.rb +22 -0
- data/lib/ledger_sync/adaptors/netsuite/operation.rb +25 -0
- data/lib/ledger_sync/adaptors/netsuite/operation/create.rb +65 -0
- data/lib/ledger_sync/adaptors/netsuite/operation/delete.rb +49 -0
- data/lib/ledger_sync/adaptors/netsuite/operation/find.rb +56 -0
- data/lib/ledger_sync/adaptors/netsuite/operation/update.rb +68 -0
- data/lib/ledger_sync/adaptors/netsuite/record/http_method.rb +38 -0
- data/lib/ledger_sync/adaptors/netsuite/record/metadata.rb +75 -0
- data/lib/ledger_sync/adaptors/netsuite/record/property.rb +45 -0
- data/lib/ledger_sync/adaptors/netsuite/searcher.rb +17 -0
- data/lib/ledger_sync/adaptors/netsuite/token.rb +162 -0
- data/lib/ledger_sync/adaptors/netsuite/vendor/ledger_deserializer.rb +32 -0
- data/lib/ledger_sync/adaptors/netsuite/vendor/ledger_serializer.rb +35 -0
- data/lib/ledger_sync/adaptors/netsuite/vendor/operations/create.rb +27 -0
- data/lib/ledger_sync/adaptors/netsuite/vendor/operations/delete.rb +27 -0
- data/lib/ledger_sync/adaptors/netsuite/vendor/operations/find.rb +27 -0
- data/lib/ledger_sync/adaptors/netsuite/vendor/operations/update.rb +27 -0
- data/lib/ledger_sync/adaptors/netsuite_soap/adaptor.rb +92 -0
- data/lib/ledger_sync/adaptors/netsuite_soap/config.rb +5 -0
- data/lib/ledger_sync/adaptors/netsuite_soap/customer/ledger_serializer.rb +13 -0
- data/lib/ledger_sync/adaptors/netsuite_soap/customer/operations/create.rb +64 -0
- data/lib/ledger_sync/adaptors/netsuite_soap/customer/operations/find.rb +49 -0
- data/lib/ledger_sync/adaptors/netsuite_soap/ledger_serializer.rb +25 -0
- data/lib/ledger_sync/adaptors/netsuite_soap/operation.rb +40 -0
- data/lib/ledger_sync/adaptors/netsuite_soap/operation/create.rb +29 -0
- data/lib/ledger_sync/adaptors/netsuite_soap/operation/find.rb +15 -0
- data/lib/ledger_sync/adaptors/netsuite_soap/subsidiary/operations/create.rb +42 -0
- data/lib/ledger_sync/adaptors/netsuite_soap/subsidiary/operations/find.rb +38 -0
- data/lib/ledger_sync/adaptors/operation.rb +7 -11
- data/lib/ledger_sync/adaptors/quickbooks_online/account/searcher.rb +2 -13
- data/lib/ledger_sync/adaptors/quickbooks_online/adaptor.rb +158 -109
- data/lib/ledger_sync/adaptors/quickbooks_online/bill/searcher.rb +1 -15
- data/lib/ledger_sync/adaptors/quickbooks_online/config.rb +3 -2
- data/lib/ledger_sync/adaptors/quickbooks_online/customer/operations/create.rb +1 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/customer/operations/find.rb +1 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/customer/operations/update.rb +1 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/customer/searcher.rb +2 -16
- data/lib/ledger_sync/adaptors/quickbooks_online/dashboard_url_helper.rb +57 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/department/ledger_serializer.rb +38 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/department/operations/create.rb +23 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/department/operations/find.rb +23 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/department/operations/update.rb +25 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/department/searcher.rb +17 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/deposit/ledger_serializer.rb +3 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/deposit/operations/create.rb +1 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/deposit/operations/find.rb +1 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/deposit/operations/update.rb +1 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/deposit/searcher.rb +0 -15
- data/lib/ledger_sync/adaptors/quickbooks_online/expense/ledger_serializer.rb +0 -2
- data/lib/ledger_sync/adaptors/quickbooks_online/expense/searcher.rb +1 -15
- data/lib/ledger_sync/adaptors/quickbooks_online/invoice/ledger_serializer.rb +35 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/invoice/operations/create.rb +27 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/invoice/operations/find.rb +25 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/invoice/operations/update.rb +25 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/invoice_sales_line_item/ledger_serializer.rb +30 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/item/ledger_serializer.rb +13 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/journal_entry/searcher.rb +1 -15
- data/lib/ledger_sync/adaptors/quickbooks_online/ledger_class/ledger_serializer.rb +25 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/ledger_class/operations/create.rb +23 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/ledger_class/operations/find.rb +23 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/ledger_class/operations/update.rb +25 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/ledger_class/searcher.rb +15 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/ledger_serializer.rb +8 -5
- data/lib/ledger_sync/adaptors/quickbooks_online/ledger_serializer_type/entity_reference_type.rb +4 -14
- data/lib/ledger_sync/adaptors/quickbooks_online/ledger_serializer_type/transaction_reference_type.rb +49 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/oauth_client.rb +93 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/operation.rb +42 -7
- data/lib/ledger_sync/adaptors/quickbooks_online/operation/create.rb +5 -8
- data/lib/ledger_sync/adaptors/quickbooks_online/operation/find.rb +9 -9
- data/lib/ledger_sync/adaptors/quickbooks_online/operation/full_update.rb +17 -15
- data/lib/ledger_sync/adaptors/quickbooks_online/payment/ledger_serializer.rb +25 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/payment/operations/create.rb +9 -6
- data/lib/ledger_sync/adaptors/quickbooks_online/payment/operations/find.rb +9 -2
- data/lib/ledger_sync/adaptors/quickbooks_online/payment/operations/update.rb +8 -1
- data/lib/ledger_sync/adaptors/quickbooks_online/payment_line_item/ledger_serializer.rb +19 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/request.rb +98 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/searcher.rb +29 -13
- data/lib/ledger_sync/adaptors/quickbooks_online/util/operation_error_parser.rb +1 -1
- data/lib/ledger_sync/adaptors/quickbooks_online/vendor/operations/create.rb +3 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/vendor/operations/find.rb +3 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/vendor/operations/update.rb +3 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/vendor/searcher.rb +5 -54
- data/lib/ledger_sync/adaptors/quickbooks_online/webhook.rb +58 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/webhook_event.rb +79 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/webhook_notification.rb +42 -0
- data/lib/ledger_sync/adaptors/request.rb +53 -0
- data/lib/ledger_sync/adaptors/response.rb +55 -0
- data/lib/ledger_sync/adaptors/searcher.rb +3 -1
- data/lib/ledger_sync/adaptors/stripe/adaptor.rb +45 -0
- data/lib/ledger_sync/adaptors/stripe/config.rb +6 -0
- data/lib/ledger_sync/adaptors/stripe/customer/operations/create.rb +44 -0
- data/lib/ledger_sync/adaptors/stripe/customer/operations/delete.rb +35 -0
- data/lib/ledger_sync/adaptors/stripe/customer/operations/find.rb +44 -0
- data/lib/ledger_sync/adaptors/stripe/customer/operations/update.rb +43 -0
- data/lib/ledger_sync/adaptors/stripe/operation.rb +35 -0
- data/lib/ledger_sync/adaptors/stripe/operation/create.rb +17 -0
- data/lib/ledger_sync/adaptors/stripe/operation/delete.rb +17 -0
- data/lib/ledger_sync/adaptors/stripe/operation/find.rb +15 -0
- data/lib/ledger_sync/adaptors/stripe/operation/update.rb +17 -0
- data/lib/ledger_sync/adaptors/test/config.rb +0 -1
- data/lib/ledger_sync/adaptors/test/customer/operations/create.rb +1 -0
- data/lib/ledger_sync/adaptors/test/customer/operations/find.rb +1 -0
- data/lib/ledger_sync/adaptors/test/customer/operations/invalid.rb +1 -0
- data/lib/ledger_sync/adaptors/test/customer/operations/update.rb +1 -0
- data/lib/ledger_sync/adaptors/test/customer/operations/valid.rb +1 -0
- data/lib/ledger_sync/adaptors/test/payment/operations/create.rb +8 -1
- data/lib/ledger_sync/adaptors/test/payment/operations/find.rb +9 -2
- data/lib/ledger_sync/adaptors/test/payment/operations/update.rb +9 -5
- data/lib/ledger_sync/adaptors/test/vendor/operations/create.rb +5 -0
- data/lib/ledger_sync/adaptors/test/vendor/operations/find.rb +3 -0
- data/lib/ledger_sync/adaptors/test/vendor/operations/invalid.rb +5 -0
- data/lib/ledger_sync/adaptors/test/vendor/operations/update.rb +5 -0
- data/lib/ledger_sync/adaptors/test/vendor/operations/valid.rb +5 -0
- data/lib/ledger_sync/error/adaptor_errors.rb +18 -5
- data/lib/ledger_sync/error/operation_errors.rb +13 -4
- data/lib/ledger_sync/resource.rb +6 -0
- data/lib/ledger_sync/resource_attribute/dirty_mixin.rb +16 -15
- data/lib/ledger_sync/resources/bill.rb +7 -1
- data/lib/ledger_sync/resources/bill_line_item.rb +2 -0
- data/lib/ledger_sync/resources/currency.rb +9 -0
- data/lib/ledger_sync/resources/customer.rb +16 -0
- data/lib/ledger_sync/resources/department.rb +14 -0
- data/lib/ledger_sync/resources/deposit.rb +7 -0
- data/lib/ledger_sync/resources/deposit_line_item.rb +6 -0
- data/lib/ledger_sync/resources/expense.rb +5 -0
- data/lib/ledger_sync/resources/expense_line_item.rb +2 -0
- data/lib/ledger_sync/resources/invoice.rb +23 -0
- data/lib/ledger_sync/resources/invoice_sales_line_item.rb +17 -0
- data/lib/ledger_sync/resources/item.rb +5 -0
- data/lib/ledger_sync/resources/journal_entry.rb +5 -1
- data/lib/ledger_sync/resources/journal_entry_line_item.rb +4 -0
- data/lib/ledger_sync/resources/ledger_class.rb +14 -0
- data/lib/ledger_sync/resources/payment.rb +13 -0
- data/lib/ledger_sync/resources/payment_line_item.rb +15 -0
- data/lib/ledger_sync/resources/subsidiary.rb +8 -0
- data/lib/ledger_sync/resources/transfer.rb +4 -0
- data/lib/ledger_sync/resources/vendor.rb +9 -2
- data/lib/ledger_sync/type/reference_many.rb +12 -1
- data/lib/ledger_sync/type/reference_one.rb +1 -1
- data/lib/ledger_sync/util/resonad.rb +18 -0
- data/lib/ledger_sync/util/signer.rb +36 -0
- data/lib/ledger_sync/util/string_helpers.rb +12 -12
- data/lib/ledger_sync/version.rb +1 -1
- data/qa/env_spec.rb +5 -0
- data/qa/netsuite/account_spec.rb +20 -0
- data/qa/netsuite/currency_spec.rb +16 -0
- data/qa/netsuite/customer.rb +76 -0
- data/qa/netsuite/customer_spec.rb +21 -0
- data/qa/netsuite/vendor.rb +76 -0
- data/qa/netsuite/vendor_spec.rb +23 -0
- data/qa/netsuite_soap/customer_spec.rb +21 -0
- data/qa/netsuite_soap/subsidiary_spec.rb +0 -0
- data/qa/netsuite_test.rb +42 -0
- data/qa/qa_helper.rb +58 -0
- data/qa/quickbooks_online/account_spec.rb +14 -0
- data/qa/quickbooks_online/customer_spec.rb +13 -0
- data/qa/quickbooks_online/expense_spec.rb +31 -0
- data/qa/quickbooks_online/vendor_spec.rb +13 -0
- data/qa/stripe/customers_spec.rb +15 -0
- data/qa/support/adaptor_helpers.rb +99 -0
- data/qa/support/adaptor_support_setup.rb +23 -0
- data/qa/support/netsuite_helpers.rb +33 -0
- data/qa/support/netsuite_shared_examples.rb +30 -0
- data/qa/support/netsuite_soap_helpers.rb +33 -0
- data/qa/support/netsuite_soap_shared_examples.rb +10 -0
- data/qa/support/quickbooks_online_helpers.rb +42 -0
- data/qa/support/quickbooks_online_shared_examples.rb +82 -0
- data/qa/support/shared_examples.rb +127 -0
- data/qa/support/stripe_helpers.rb +22 -0
- data/qa/support/stripe_shared_examples.rb +10 -0
- data/qa/test.rb +67 -0
- data/release.sh +13 -1
- metadata +189 -3
- data/qa.rb +0 -142
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
module LedgerSync
|
|
2
|
+
module Adaptors
|
|
3
|
+
module QuickBooksOnline
|
|
4
|
+
module Invoice
|
|
5
|
+
module Operations
|
|
6
|
+
class Find < Operation::Find
|
|
7
|
+
class Contract < LedgerSync::Adaptors::Contract
|
|
8
|
+
schema do
|
|
9
|
+
required(:external_id).maybe(:string)
|
|
10
|
+
optional(:account).hash(Types::Reference)
|
|
11
|
+
optional(:currency).maybe(:string)
|
|
12
|
+
optional(:customer).hash(Types::Reference)
|
|
13
|
+
optional(:deposit).maybe(:integer)
|
|
14
|
+
required(:ledger_id).filled(:string)
|
|
15
|
+
optional(:line_items).array(Types::Reference)
|
|
16
|
+
optional(:memo).maybe(:string)
|
|
17
|
+
optional(:transaction_date).maybe(:date?)
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
module LedgerSync
|
|
2
|
+
module Adaptors
|
|
3
|
+
module QuickBooksOnline
|
|
4
|
+
module Invoice
|
|
5
|
+
module Operations
|
|
6
|
+
class Update < Operation::FullUpdate
|
|
7
|
+
class Contract < LedgerSync::Adaptors::Contract
|
|
8
|
+
schema do
|
|
9
|
+
required(:external_id).maybe(:string)
|
|
10
|
+
optional(:account).hash(Types::Reference)
|
|
11
|
+
required(:currency).filled(:string)
|
|
12
|
+
required(:customer).hash(Types::Reference)
|
|
13
|
+
optional(:deposit).maybe(:integer)
|
|
14
|
+
required(:ledger_id).filled(:string)
|
|
15
|
+
required(:line_items).array(Types::Reference)
|
|
16
|
+
optional(:memo).filled(:string)
|
|
17
|
+
optional(:transaction_date).filled(:date?)
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module LedgerSync
|
|
4
|
+
module Adaptors
|
|
5
|
+
module QuickBooksOnline
|
|
6
|
+
module InvoiceSalesLineItem
|
|
7
|
+
class LedgerSerializer < QuickBooksOnline::LedgerSerializer
|
|
8
|
+
id
|
|
9
|
+
|
|
10
|
+
attribute ledger_attribute: 'DetailType' do
|
|
11
|
+
'SalesItemLineDetail'
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
attribute ledger_attribute: 'SalesItemLineDetail.ItemRef.value',
|
|
15
|
+
resource_attribute: 'item.ledger_id'
|
|
16
|
+
|
|
17
|
+
attribute ledger_attribute: 'SalesItemLineDetail.ClassRef.value',
|
|
18
|
+
resource_attribute: 'ledger_class.ledger_id'
|
|
19
|
+
|
|
20
|
+
attribute ledger_attribute: 'Amount',
|
|
21
|
+
resource_attribute: :amount,
|
|
22
|
+
type: LedgerSerializerType::AmountType
|
|
23
|
+
|
|
24
|
+
attribute ledger_attribute: 'Description',
|
|
25
|
+
resource_attribute: :description
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
+
|
|
2
3
|
require_relative '../searcher'
|
|
3
4
|
|
|
4
5
|
module LedgerSync
|
|
@@ -6,21 +7,6 @@ module LedgerSync
|
|
|
6
7
|
module QuickBooksOnline
|
|
7
8
|
module JournalEntry
|
|
8
9
|
class Searcher < QuickBooksOnline::Searcher
|
|
9
|
-
def resources
|
|
10
|
-
@resources ||= begin
|
|
11
|
-
adaptor
|
|
12
|
-
.query(
|
|
13
|
-
resource: 'journal_entry',
|
|
14
|
-
limit: limit,
|
|
15
|
-
offset: offset
|
|
16
|
-
)
|
|
17
|
-
.map do |c|
|
|
18
|
-
LedgerSync::JournalEntry.new(
|
|
19
|
-
ledger_id: c.fetch('Id')
|
|
20
|
-
)
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
10
|
end
|
|
25
11
|
end
|
|
26
12
|
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module LedgerSync
|
|
4
|
+
module Adaptors
|
|
5
|
+
module QuickBooksOnline
|
|
6
|
+
module LedgerClass
|
|
7
|
+
class LedgerSerializer < QuickBooksOnline::LedgerSerializer
|
|
8
|
+
id
|
|
9
|
+
|
|
10
|
+
attribute ledger_attribute: 'Name',
|
|
11
|
+
resource_attribute: :name
|
|
12
|
+
attribute ledger_attribute: 'Active',
|
|
13
|
+
resource_attribute: :active
|
|
14
|
+
attribute ledger_attribute: 'SubClass',
|
|
15
|
+
resource_attribute: :sub_class
|
|
16
|
+
attribute ledger_attribute: 'FullyQualifiedName',
|
|
17
|
+
resource_attribute: :fully_qualified_name
|
|
18
|
+
|
|
19
|
+
attribute ledger_attribute: 'ParentRef.value',
|
|
20
|
+
resource_attribute: 'parent.ledger_id'
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
module LedgerSync
|
|
2
|
+
module Adaptors
|
|
3
|
+
module QuickBooksOnline
|
|
4
|
+
module LedgerClass
|
|
5
|
+
module Operations
|
|
6
|
+
class Create < QuickBooksOnline::Operation::Create
|
|
7
|
+
class Contract < LedgerSync::Adaptors::Contract
|
|
8
|
+
params do
|
|
9
|
+
required(:external_id).maybe(:string)
|
|
10
|
+
required(:ledger_id).value(:nil)
|
|
11
|
+
required(:name).filled(:string)
|
|
12
|
+
required(:active).filled(:bool?)
|
|
13
|
+
required(:sub_class).filled(:bool?)
|
|
14
|
+
optional(:fully_qualified_name).maybe(:string)
|
|
15
|
+
optional(:parent).maybe(:hash, Types::Reference)
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
module LedgerSync
|
|
2
|
+
module Adaptors
|
|
3
|
+
module QuickBooksOnline
|
|
4
|
+
module LedgerClass
|
|
5
|
+
module Operations
|
|
6
|
+
class Find < QuickBooksOnline::Operation::Find
|
|
7
|
+
class Contract < LedgerSync::Adaptors::Contract
|
|
8
|
+
params do
|
|
9
|
+
required(:external_id).maybe(:string)
|
|
10
|
+
required(:ledger_id).filled(:string)
|
|
11
|
+
optional(:name).maybe(:string)
|
|
12
|
+
optional(:active).maybe(:bool?)
|
|
13
|
+
optional(:sub_class).maybe(:bool?)
|
|
14
|
+
optional(:fully_qualified_name).maybe(:string)
|
|
15
|
+
optional(:parent).maybe(:hash, Types::Reference)
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module LedgerSync
|
|
4
|
+
module Adaptors
|
|
5
|
+
module QuickBooksOnline
|
|
6
|
+
module LedgerClass
|
|
7
|
+
module Operations
|
|
8
|
+
class Update < QuickBooksOnline::Operation::FullUpdate
|
|
9
|
+
class Contract < LedgerSync::Adaptors::Contract
|
|
10
|
+
params do
|
|
11
|
+
required(:external_id).maybe(:string)
|
|
12
|
+
required(:ledger_id).filled(:string)
|
|
13
|
+
required(:name).filled(:string)
|
|
14
|
+
required(:active).filled(:bool?)
|
|
15
|
+
required(:sub_class).filled(:bool?)
|
|
16
|
+
optional(:fully_qualified_name).maybe(:string)
|
|
17
|
+
optional(:parent).maybe(:hash, Types::Reference)
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module LedgerSync
|
|
4
|
+
module Adaptors
|
|
5
|
+
module QuickBooksOnline
|
|
6
|
+
module LedgerClass
|
|
7
|
+
class Searcher < LedgerSync::Adaptors::QuickBooksOnline::Searcher
|
|
8
|
+
def query_string
|
|
9
|
+
"Name LIKE '%#{query}%'"
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -79,12 +79,15 @@ module LedgerSync
|
|
|
79
79
|
QuickBooksOnline.const_get("#{resource_class.name.split('LedgerSync::')[1..-1].join('LedgerSync::')}::LedgerSerializer")
|
|
80
80
|
end
|
|
81
81
|
|
|
82
|
-
def self.quickbooks_online_resource_type
|
|
82
|
+
def self.quickbooks_online_resource_type
|
|
83
83
|
@quickbooks_online_resource_type ||= begin
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
84
|
+
qbo_type = Adaptor.ledger_resource_type_for(
|
|
85
|
+
resource_class: inferred_resource_class
|
|
86
|
+
)
|
|
87
|
+
type_hash = QuickBooksOnline::LedgerSerializer
|
|
88
|
+
.quickbooks_online_resource_types_hash
|
|
89
|
+
.try(:fetch, qbo_type, nil)
|
|
90
|
+
raise "Cannot define type in #{name}. Type already exists: #{qbo_type}. Defined previously by #{quickbooks_online_resource_types_hash[qbo_type][:serializer_class].name}" if type_hash.present? && (type_hash[:serializer_class] != serializer_class || type_hash[:resource_class] != inferred_resource_class)
|
|
88
91
|
|
|
89
92
|
QuickBooksOnline::LedgerSerializer.class_eval do
|
|
90
93
|
@quickbooks_online_resource_types_hash ||= {}
|
data/lib/ledger_sync/adaptors/quickbooks_online/ledger_serializer_type/entity_reference_type.rb
CHANGED
|
@@ -12,15 +12,7 @@ module LedgerSync
|
|
|
12
12
|
return if value.empty?
|
|
13
13
|
|
|
14
14
|
value = LedgerSync::Util::HashHelpers.deep_stringify_keys(value)
|
|
15
|
-
resource_class =
|
|
16
|
-
quickbooks_online_type_hash = QuickBooksOnline::LedgerSerializer.quickbooks_online_resource_types_hash.fetch(value['type'].downcase, nil)
|
|
17
|
-
if quickbooks_online_type_hash.present?
|
|
18
|
-
quickbooks_online_type_hash.try(:fetch, :resource_class, nil)
|
|
19
|
-
else
|
|
20
|
-
LedgerSync.resources[value['type'].downcase.to_sym]
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
|
|
15
|
+
resource_class = Adaptor.resource_from_ledger_type(type: value['type'])
|
|
24
16
|
raise "Unknown QuickBooks Online resource type: #{value['type']}" if resource_class.blank?
|
|
25
17
|
|
|
26
18
|
ret = resource_class.new(
|
|
@@ -39,11 +31,9 @@ module LedgerSync
|
|
|
39
31
|
'value' => value.ledger_id
|
|
40
32
|
}
|
|
41
33
|
ret['name'] = value.display_name if value.respond_to?(:display_name)
|
|
42
|
-
ret['type'] =
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
).quickbooks_online_resource_type
|
|
46
|
-
)
|
|
34
|
+
ret['type'] = Adaptor.ledger_resource_type_for(
|
|
35
|
+
resource_class: value.class
|
|
36
|
+
).classify
|
|
47
37
|
ret
|
|
48
38
|
end
|
|
49
39
|
|
data/lib/ledger_sync/adaptors/quickbooks_online/ledger_serializer_type/transaction_reference_type.rb
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module LedgerSync
|
|
4
|
+
module Adaptors
|
|
5
|
+
module QuickBooksOnline
|
|
6
|
+
module LedgerSerializerType
|
|
7
|
+
class TransactionReferenceType < Adaptors::LedgerSerializerType::ValueType
|
|
8
|
+
def convert_from_ledger(value:)
|
|
9
|
+
return if value.nil?
|
|
10
|
+
|
|
11
|
+
raise "Unknown value type. Array expected. Given: #{value.class.name}" unless value.is_a?(Array)
|
|
12
|
+
return if value.empty?
|
|
13
|
+
|
|
14
|
+
value.map do |item|
|
|
15
|
+
resource_class = Adaptor.resource_from_ledger_type(type: item['TxnType'])
|
|
16
|
+
|
|
17
|
+
raise "Unknown QuickBooks Online resource type: #{item['TxnType']}" if resource_class.blank?
|
|
18
|
+
|
|
19
|
+
resource_class.new(
|
|
20
|
+
ledger_id: item['TxnId']
|
|
21
|
+
)
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def convert_from_local(value:)
|
|
26
|
+
return if value.nil?
|
|
27
|
+
raise "List expected. Given: #{value.class.name}" unless value.is_a?(Array)
|
|
28
|
+
raise "Resources expected. Given: #{value.map { |i| i.class.name }.join(', ')}" unless value.all?(LedgerSync::Resource)
|
|
29
|
+
|
|
30
|
+
value.map do |resource|
|
|
31
|
+
{
|
|
32
|
+
'TxnId' => resource.ledger_id,
|
|
33
|
+
'TxnType' => Adaptor.ledger_resource_type_for(
|
|
34
|
+
resource_class: resource.class
|
|
35
|
+
).classify
|
|
36
|
+
}
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
private
|
|
41
|
+
|
|
42
|
+
def string_helpers
|
|
43
|
+
@string_helpers ||= LedgerSync::Util::StringHelpers
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module LedgerSync
|
|
4
|
+
module Adaptors
|
|
5
|
+
module QuickBooksOnline
|
|
6
|
+
class OAuthClient
|
|
7
|
+
AUTHORIZE_URL = 'https://appcenter.intuit.com/connect/oauth2'
|
|
8
|
+
SITE_URL = 'https://appcenter.intuit.com/connect/oauth2'
|
|
9
|
+
TOKEN_URL = 'https://oauth.platform.intuit.com/oauth2/v1/tokens/bearer'
|
|
10
|
+
|
|
11
|
+
class RedirectURIParser
|
|
12
|
+
attr_reader :uri
|
|
13
|
+
|
|
14
|
+
def initialize(uri:)
|
|
15
|
+
@uri = uri
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def code
|
|
19
|
+
@code ||= query.fetch('code').first
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def parsed_uri
|
|
23
|
+
@parsed_uri = URI.parse(uri)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def query
|
|
27
|
+
@query ||= CGI.parse(parsed_uri.query)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def realm_id
|
|
31
|
+
@realm_id ||= query.fetch('realmId').first
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def redirect_uri
|
|
35
|
+
@redirect_uri ||= begin
|
|
36
|
+
use_uri = parsed_uri.dup
|
|
37
|
+
use_uri.fragment = nil
|
|
38
|
+
use_uri.query = nil
|
|
39
|
+
ret = use_uri.to_s
|
|
40
|
+
ret = ret[0..-2] if ret.end_with?('/')
|
|
41
|
+
ret
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
attr_reader :client_id,
|
|
47
|
+
:client_secret
|
|
48
|
+
|
|
49
|
+
def initialize(client_id:, client_secret:)
|
|
50
|
+
@client_id = client_id
|
|
51
|
+
@client_secret = client_secret
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def authorization_url(redirect_uri:)
|
|
55
|
+
client.auth_code.authorize_url(
|
|
56
|
+
redirect_uri: redirect_uri,
|
|
57
|
+
response_type: 'code',
|
|
58
|
+
state: SecureRandom.hex(12),
|
|
59
|
+
scope: 'com.intuit.quickbooks.accounting'
|
|
60
|
+
)
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def auth_code
|
|
64
|
+
client.auth_code
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def client
|
|
68
|
+
@client ||= OAuth2::Client.new(
|
|
69
|
+
client_id,
|
|
70
|
+
client_secret,
|
|
71
|
+
authorize_url: AUTHORIZE_URL,
|
|
72
|
+
site: SITE_URL,
|
|
73
|
+
token_url: TOKEN_URL
|
|
74
|
+
)
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def get_token(code:, redirect_uri:)
|
|
78
|
+
auth_code.get_token(
|
|
79
|
+
code,
|
|
80
|
+
redirect_uri: redirect_uri
|
|
81
|
+
)
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def self.new_from_env
|
|
85
|
+
new(
|
|
86
|
+
client_id: ENV.fetch('QUICKBOOKS_ONLINE_CLIENT_ID'),
|
|
87
|
+
client_secret: ENV.fetch('QUICKBOOKS_ONLINE_CLIENT_SECRET')
|
|
88
|
+
)
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
end
|
|
@@ -7,16 +7,51 @@ module LedgerSync
|
|
|
7
7
|
module Mixin
|
|
8
8
|
def self.included(base)
|
|
9
9
|
base.include Adaptors::Operation::Mixin
|
|
10
|
+
base.include InstanceMethods # To ensure these override parent methods
|
|
10
11
|
end
|
|
11
12
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
module InstanceMethods
|
|
14
|
+
def deserialized_resource(response:)
|
|
15
|
+
ledger_serializer.deserialize(
|
|
16
|
+
hash: response.body.dig(
|
|
17
|
+
quickbooks_online_resource_type.to_s.classify
|
|
18
|
+
)
|
|
19
|
+
)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def ledger_resource_path
|
|
23
|
+
@ledger_resource_path ||= "#{ledger_resource_type_for_path}/#{resource.ledger_id}"
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def ledger_resource_type_for_path
|
|
27
|
+
quickbooks_online_resource_type.tr('_', '')
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def result(response:)
|
|
31
|
+
if response.success?
|
|
32
|
+
success(
|
|
33
|
+
resource: deserialized_resource(response: response),
|
|
34
|
+
response: response
|
|
35
|
+
)
|
|
36
|
+
else
|
|
37
|
+
failure(
|
|
38
|
+
Error::OperationError.new(
|
|
39
|
+
operation: self,
|
|
40
|
+
response: response
|
|
41
|
+
)
|
|
42
|
+
)
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def perform
|
|
47
|
+
super
|
|
48
|
+
rescue LedgerSync::Error::OperationError, OAuth2::Error => e
|
|
49
|
+
failure(e)
|
|
50
|
+
end
|
|
17
51
|
|
|
18
|
-
|
|
19
|
-
|
|
52
|
+
def quickbooks_online_resource_type
|
|
53
|
+
@quickbooks_online_resource_type ||= ledger_serializer.class.quickbooks_online_resource_type
|
|
54
|
+
end
|
|
20
55
|
end
|
|
21
56
|
end
|
|
22
57
|
end
|