ledger_sync 1.1.3 → 1.3.1
Sign up to get free protection for your applications and to get access to all the features.
- 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,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module LedgerSync
|
4
|
+
module Adaptors
|
5
|
+
module NetSuite
|
6
|
+
module Account
|
7
|
+
class LedgerDeserializer < NetSuite::LedgerSerializer
|
8
|
+
attribute ledger_attribute: :id,
|
9
|
+
resource_attribute: :ledger_id
|
10
|
+
|
11
|
+
attribute ledger_attribute: :acctname,
|
12
|
+
resource_attribute: :name
|
13
|
+
|
14
|
+
|
15
|
+
attribute ledger_attribute: :accttype,
|
16
|
+
resource_attribute: :account_type
|
17
|
+
|
18
|
+
attribute ledger_attribute: :acctnumber,
|
19
|
+
resource_attribute: :number
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module LedgerSync
|
4
|
+
module Adaptors
|
5
|
+
module NetSuite
|
6
|
+
module Account
|
7
|
+
class LedgerSerializer < NetSuite::LedgerSerializer
|
8
|
+
api_resource_type :account
|
9
|
+
|
10
|
+
attribute ledger_attribute: :acctname,
|
11
|
+
resource_attribute: :name
|
12
|
+
|
13
|
+
attribute ledger_attribute: :accttype,
|
14
|
+
resource_attribute: :account_type
|
15
|
+
|
16
|
+
attribute ledger_attribute: :acctnumber,
|
17
|
+
resource_attribute: :number
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module LedgerSync
|
4
|
+
module Adaptors
|
5
|
+
module NetSuite
|
6
|
+
module Account
|
7
|
+
module Operations
|
8
|
+
class Create < NetSuite::Operation::Create
|
9
|
+
class Contract < LedgerSync::Adaptors::Contract
|
10
|
+
params do
|
11
|
+
required(:external_id).maybe(:string)
|
12
|
+
required(:ledger_id).value(:nil)
|
13
|
+
required(:name).filled(:string)
|
14
|
+
required(:classification).maybe(:string)
|
15
|
+
required(:account_type).maybe(:string)
|
16
|
+
required(:account_sub_type).maybe(:string)
|
17
|
+
required(:number).filled(:integer)
|
18
|
+
required(:currency).filled(:string)
|
19
|
+
required(:description).maybe(:string)
|
20
|
+
required(:active).maybe(:bool)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module LedgerSync
|
4
|
+
module Adaptors
|
5
|
+
module NetSuite
|
6
|
+
module Account
|
7
|
+
module Operations
|
8
|
+
class Find < NetSuite::Operation::Find
|
9
|
+
class Contract < LedgerSync::Adaptors::Contract
|
10
|
+
params do
|
11
|
+
required(:external_id).maybe(:string)
|
12
|
+
required(:ledger_id).filled(:string)
|
13
|
+
required(:name).maybe(:string)
|
14
|
+
required(:classification).maybe(:string)
|
15
|
+
required(:account_type).maybe(:string)
|
16
|
+
required(:account_sub_type).maybe(:string)
|
17
|
+
required(:number).maybe(:integer)
|
18
|
+
required(:currency).maybe(:string)
|
19
|
+
required(:description).maybe(:string)
|
20
|
+
required(:active).maybe(:bool)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module LedgerSync
|
4
|
+
module Adaptors
|
5
|
+
module NetSuite
|
6
|
+
module Account
|
7
|
+
class Searcher < Searcher
|
8
|
+
def resources
|
9
|
+
@resources ||= begin
|
10
|
+
@request = adaptor
|
11
|
+
.get(
|
12
|
+
path: "/record/account?limit=#{limit}&offset=#{offset}"
|
13
|
+
)
|
14
|
+
|
15
|
+
request.body
|
16
|
+
.fetch('items')
|
17
|
+
.map do |c|
|
18
|
+
LedgerDeserializer.new(
|
19
|
+
resource: LedgerSync::Account.new
|
20
|
+
).deserialize(hash: c)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,145 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'oauth2'
|
4
|
+
|
5
|
+
module LedgerSync
|
6
|
+
module Adaptors
|
7
|
+
module NetSuite
|
8
|
+
class Adaptor < LedgerSync::Adaptors::Adaptor
|
9
|
+
HEADERS = {
|
10
|
+
# 'Accept' => 'application/schema+json'
|
11
|
+
}.freeze
|
12
|
+
|
13
|
+
WRITE_HEADERS = {
|
14
|
+
'Accept' => '*/*',
|
15
|
+
'Content-Type' => 'application/json'
|
16
|
+
}.freeze
|
17
|
+
|
18
|
+
attr_reader :account_id,
|
19
|
+
:consumer_key,
|
20
|
+
:consumer_secret,
|
21
|
+
:token_id,
|
22
|
+
:token_secret
|
23
|
+
|
24
|
+
def initialize(
|
25
|
+
account_id:,
|
26
|
+
consumer_key:,
|
27
|
+
consumer_secret:,
|
28
|
+
token_id:,
|
29
|
+
token_secret:
|
30
|
+
)
|
31
|
+
@account_id = account_id
|
32
|
+
@consumer_key = consumer_key
|
33
|
+
@consumer_secret = consumer_secret
|
34
|
+
@token_id = token_id
|
35
|
+
@token_secret = token_secret
|
36
|
+
end
|
37
|
+
|
38
|
+
def account_id_for_oauth
|
39
|
+
account_id.split('-sb').join('_SB')
|
40
|
+
end
|
41
|
+
|
42
|
+
def account_id_for_url
|
43
|
+
account_id.split('_SB').join('-sb')
|
44
|
+
end
|
45
|
+
|
46
|
+
def api_base_url
|
47
|
+
@api_base_url ||= "https://#{api_host}/rest/platform/v1"
|
48
|
+
end
|
49
|
+
|
50
|
+
def api_host
|
51
|
+
@api_host ||= "#{account_id_for_url}.suitetalk.api.netsuite.com"
|
52
|
+
end
|
53
|
+
|
54
|
+
def delete(**keywords)
|
55
|
+
request(keywords.merge(method: :delete))
|
56
|
+
end
|
57
|
+
|
58
|
+
def get(**keywords)
|
59
|
+
request(keywords.merge(method: :get))
|
60
|
+
end
|
61
|
+
|
62
|
+
def patch(headers: {}, **keywords)
|
63
|
+
request(
|
64
|
+
keywords.merge(
|
65
|
+
headers: WRITE_HEADERS.merge(headers),
|
66
|
+
method: :patch
|
67
|
+
)
|
68
|
+
)
|
69
|
+
end
|
70
|
+
|
71
|
+
def post(headers: {}, **keywords)
|
72
|
+
request(
|
73
|
+
keywords.merge(
|
74
|
+
headers: WRITE_HEADERS.merge(headers),
|
75
|
+
method: :post
|
76
|
+
)
|
77
|
+
)
|
78
|
+
end
|
79
|
+
|
80
|
+
def self.ledger_attributes_to_save
|
81
|
+
%i[]
|
82
|
+
end
|
83
|
+
|
84
|
+
def self.new_from_env(**override)
|
85
|
+
new(
|
86
|
+
{
|
87
|
+
account_id: ENV.fetch('NETSUITE_ACCOUNT_ID', nil),
|
88
|
+
consumer_key: ENV.fetch('NETSUITE_CONSUMER_KEY', nil),
|
89
|
+
consumer_secret: ENV.fetch('NETSUITE_CONSUMER_SECRET', nil),
|
90
|
+
token_id: ENV.fetch('NETSUITE_TOKEN_ID', nil),
|
91
|
+
token_secret: ENV.fetch('NETSUITE_TOKEN_SECRET', nil)
|
92
|
+
}.merge(override)
|
93
|
+
)
|
94
|
+
end
|
95
|
+
|
96
|
+
private
|
97
|
+
|
98
|
+
def new_token(body:, method:, url:)
|
99
|
+
Token.new(
|
100
|
+
body: body,
|
101
|
+
consumer_key: consumer_key,
|
102
|
+
consumer_secret: consumer_secret,
|
103
|
+
method: method,
|
104
|
+
token_id: token_id,
|
105
|
+
token_secret: token_secret,
|
106
|
+
url: url
|
107
|
+
)
|
108
|
+
end
|
109
|
+
|
110
|
+
def request(body: nil, headers: {}, method:, path: nil)
|
111
|
+
request_url = url_from_path(path: path)
|
112
|
+
token = new_token(
|
113
|
+
body: body,
|
114
|
+
method: method,
|
115
|
+
url: request_url
|
116
|
+
)
|
117
|
+
|
118
|
+
request = Request.new(
|
119
|
+
body: body,
|
120
|
+
headers: headers
|
121
|
+
.merge(HEADERS)
|
122
|
+
.merge(
|
123
|
+
token.headers(
|
124
|
+
realm: account_id_for_oauth
|
125
|
+
)
|
126
|
+
)
|
127
|
+
.merge(
|
128
|
+
'Host' => api_host
|
129
|
+
),
|
130
|
+
method: method,
|
131
|
+
url: request_url
|
132
|
+
)
|
133
|
+
|
134
|
+
request.perform
|
135
|
+
end
|
136
|
+
|
137
|
+
def url_from_path(path:)
|
138
|
+
request_url = api_base_url
|
139
|
+
request_url += '/' unless path.start_with?('/')
|
140
|
+
request_url + path
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module LedgerSync
|
4
|
+
module Adaptors
|
5
|
+
module NetSuite
|
6
|
+
module Currency
|
7
|
+
class LedgerDeserializer < NetSuite::LedgerSerializer
|
8
|
+
api_resource_type :currency
|
9
|
+
|
10
|
+
attribute ledger_attribute: :id,
|
11
|
+
resource_attribute: :ledger_id
|
12
|
+
|
13
|
+
attribute ledger_attribute: :name,
|
14
|
+
resource_attribute: :name
|
15
|
+
|
16
|
+
attribute ledger_attribute: :externalid,
|
17
|
+
resource_attribute: :external_id
|
18
|
+
|
19
|
+
attribute ledger_attribute: :symbol,
|
20
|
+
resource_attribute: :symbol
|
21
|
+
|
22
|
+
attribute ledger_attribute: :exchangerate,
|
23
|
+
resource_attribute: :exchange_rate
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module LedgerSync
|
4
|
+
module Adaptors
|
5
|
+
module NetSuite
|
6
|
+
module Currency
|
7
|
+
class LedgerSerializer < NetSuite::LedgerSerializer
|
8
|
+
api_resource_type :currency
|
9
|
+
|
10
|
+
attribute ledger_attribute: :name,
|
11
|
+
resource_attribute: :name
|
12
|
+
|
13
|
+
attribute ledger_attribute: :externalid,
|
14
|
+
resource_attribute: :external_id
|
15
|
+
|
16
|
+
attribute ledger_attribute: :symbol,
|
17
|
+
resource_attribute: :symbol
|
18
|
+
|
19
|
+
attribute ledger_attribute: :exchangerate,
|
20
|
+
resource_attribute: :exchange_rate
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# require_relative '../../operation/create'
|
4
|
+
|
5
|
+
module LedgerSync
|
6
|
+
module Adaptors
|
7
|
+
module NetSuite
|
8
|
+
module Currency
|
9
|
+
module Operations
|
10
|
+
class Create < NetSuite::Operation::Create
|
11
|
+
class Contract < LedgerSync::Adaptors::Contract
|
12
|
+
params do
|
13
|
+
required(:external_id).maybe(:string)
|
14
|
+
required(:ledger_id).value(:nil)
|
15
|
+
required(:exchange_rate).filled(:float)
|
16
|
+
required(:name).filled(:string)
|
17
|
+
required(:symbol).filled(:string)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module LedgerSync
|
4
|
+
module Adaptors
|
5
|
+
module NetSuite
|
6
|
+
module Currency
|
7
|
+
module Operations
|
8
|
+
class Delete < NetSuite::Operation::Delete
|
9
|
+
class Contract < LedgerSync::Adaptors::Contract
|
10
|
+
params do
|
11
|
+
required(:external_id).maybe(:string)
|
12
|
+
required(:ledger_id).filled(:string)
|
13
|
+
required(:exchange_rate).maybe(:float)
|
14
|
+
required(:name).maybe(:string)
|
15
|
+
required(:symbol).maybe(:string)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module LedgerSync
|
4
|
+
module Adaptors
|
5
|
+
module NetSuite
|
6
|
+
module Currency
|
7
|
+
module Operations
|
8
|
+
class Find < NetSuite::Operation::Find
|
9
|
+
class Contract < LedgerSync::Adaptors::Contract
|
10
|
+
params do
|
11
|
+
required(:external_id).maybe(:string)
|
12
|
+
required(:ledger_id).filled(:string)
|
13
|
+
required(:name).maybe(:string)
|
14
|
+
required(:symbol).maybe(:string)
|
15
|
+
required(:exchange_rate).maybe(:float)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module LedgerSync
|
4
|
+
module Adaptors
|
5
|
+
module NetSuite
|
6
|
+
module Currency
|
7
|
+
module Operations
|
8
|
+
class Update < NetSuite::Operation::Update
|
9
|
+
class Contract < LedgerSync::Adaptors::Contract
|
10
|
+
params do
|
11
|
+
required(:external_id).maybe(:string)
|
12
|
+
required(:ledger_id).filled(:string)
|
13
|
+
required(:exchange_rate).maybe(:float)
|
14
|
+
required(:name).filled(:string)
|
15
|
+
required(:symbol).filled(:string)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|