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,68 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../operation'
|
4
|
+
|
5
|
+
module LedgerSync
|
6
|
+
module Adaptors
|
7
|
+
module NetSuite
|
8
|
+
module Operation
|
9
|
+
class Update
|
10
|
+
include NetSuite::Operation::Mixin
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def update_in_ledger
|
15
|
+
case response.status
|
16
|
+
when 200..299
|
17
|
+
LedgerSync::Result.Success(response)
|
18
|
+
else
|
19
|
+
failure(
|
20
|
+
Error::OperationError.new(
|
21
|
+
operation: self,
|
22
|
+
response: response
|
23
|
+
)
|
24
|
+
)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def find
|
29
|
+
resource.ledger_id = ledger_id
|
30
|
+
|
31
|
+
self.class.operations_module::Find.new(
|
32
|
+
adaptor: adaptor,
|
33
|
+
resource: resource
|
34
|
+
).perform
|
35
|
+
end
|
36
|
+
|
37
|
+
def ledger_id
|
38
|
+
@ledger_id ||= response.headers['Location'].split('/').last
|
39
|
+
end
|
40
|
+
|
41
|
+
def operate
|
42
|
+
update_in_ledger
|
43
|
+
.and_then { success }
|
44
|
+
end
|
45
|
+
|
46
|
+
def response
|
47
|
+
ledger_hash = ledger_serializer.to_ledger_hash
|
48
|
+
ledger_hash.delete('entityId')
|
49
|
+
|
50
|
+
@response ||= adaptor.patch(
|
51
|
+
body: ledger_hash,
|
52
|
+
path: ledger_serializer.class.api_resource_path(resource: resource)
|
53
|
+
)
|
54
|
+
end
|
55
|
+
|
56
|
+
def success
|
57
|
+
find.and_then do |find_result|
|
58
|
+
super(
|
59
|
+
resource: find_result.resource,
|
60
|
+
response: response
|
61
|
+
)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
#
|
4
|
+
# Parser for OpenAPI 3.0 data for a given record method
|
5
|
+
#
|
6
|
+
module LedgerSync
|
7
|
+
module Adaptors
|
8
|
+
module NetSuite
|
9
|
+
module Record
|
10
|
+
class HTTPMethod
|
11
|
+
attr_reader :method,
|
12
|
+
:parameters,
|
13
|
+
:path,
|
14
|
+
:raw,
|
15
|
+
:summary
|
16
|
+
|
17
|
+
def initialize(method:, parameters:, path:, raw:, summary:)
|
18
|
+
@method = method
|
19
|
+
@parameters = parameters
|
20
|
+
@path = path
|
21
|
+
@raw = raw
|
22
|
+
@summary = summary
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.new_from_hash(data:, method:, path:)
|
26
|
+
new(
|
27
|
+
method: method,
|
28
|
+
parameters: data['parameters'],
|
29
|
+
path: path,
|
30
|
+
raw: data,
|
31
|
+
summary: data['summary']
|
32
|
+
)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module LedgerSync
|
4
|
+
module Adaptors
|
5
|
+
module NetSuite
|
6
|
+
module Record
|
7
|
+
#
|
8
|
+
# Helper class for retrieving record metadata:
|
9
|
+
# - available http_methods
|
10
|
+
# - record properties/attributes
|
11
|
+
#
|
12
|
+
class Metadata
|
13
|
+
BASE_PATH = 'metadata-catalog/record'
|
14
|
+
|
15
|
+
attr_reader :adaptor,
|
16
|
+
:record
|
17
|
+
|
18
|
+
def initialize(adaptor:, record:)
|
19
|
+
@adaptor = adaptor
|
20
|
+
@record = record
|
21
|
+
end
|
22
|
+
|
23
|
+
def http_methods
|
24
|
+
@http_methods ||= begin
|
25
|
+
ret = []
|
26
|
+
|
27
|
+
http_methods_response.body['paths'].each do |path, path_data|
|
28
|
+
path_data.each do |method, method_data|
|
29
|
+
ret << HTTPMethod.new_from_hash(
|
30
|
+
data: method_data,
|
31
|
+
method: method,
|
32
|
+
path: path
|
33
|
+
)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
ret
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def http_methods_response
|
42
|
+
@http_methods_response = begin
|
43
|
+
adaptor.get(
|
44
|
+
headers: {
|
45
|
+
'Accept' => 'application/swagger+json'
|
46
|
+
},
|
47
|
+
path: "#{BASE_PATH}?select=#{record}"
|
48
|
+
)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def properties
|
53
|
+
@properties = properties_response.body['properties'].map do |key, data|
|
54
|
+
Property.new_from_hash(
|
55
|
+
data: data,
|
56
|
+
key: key
|
57
|
+
)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def properties_response
|
62
|
+
@properties_response = begin
|
63
|
+
adaptor.get(
|
64
|
+
headers: {
|
65
|
+
'Accept' => 'application/swagger+json'
|
66
|
+
},
|
67
|
+
path: "#{BASE_PATH}/#{record}"
|
68
|
+
)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
#
|
4
|
+
# Parser for OpenAPI 3.0 data for a given record method
|
5
|
+
#
|
6
|
+
module LedgerSync
|
7
|
+
module Adaptors
|
8
|
+
module NetSuite
|
9
|
+
module Record
|
10
|
+
class Property
|
11
|
+
attr_reader :enum,
|
12
|
+
:format,
|
13
|
+
:key,
|
14
|
+
:title,
|
15
|
+
:type
|
16
|
+
|
17
|
+
def initialize(
|
18
|
+
enum: [],
|
19
|
+
format: nil,
|
20
|
+
key:,
|
21
|
+
title:,
|
22
|
+
type:
|
23
|
+
)
|
24
|
+
|
25
|
+
@enum = enum
|
26
|
+
@format = format
|
27
|
+
@key = key
|
28
|
+
@title = title
|
29
|
+
@type = type
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.new_from_hash(data:, key:)
|
33
|
+
new(
|
34
|
+
enum: data['enum'],
|
35
|
+
format: data['format'],
|
36
|
+
key: key,
|
37
|
+
title: data['title'],
|
38
|
+
type: data['type']
|
39
|
+
)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module LedgerSync
|
4
|
+
module Adaptors
|
5
|
+
module NetSuite
|
6
|
+
class Searcher < Adaptors::Searcher
|
7
|
+
include Mixins::OffsetAndLimitPaginationSearcherMixin
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def default_offset
|
12
|
+
0
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,162 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# ref: https://docs.oracle.com/cloud/latest/netsuitecs_gs/NSATH/NSATH.pdf
|
4
|
+
# ref: Search "The Signature for Web Services and RESTlets" in NetSuite documentation (must have an account)
|
5
|
+
module LedgerSync
|
6
|
+
module Adaptors
|
7
|
+
module NetSuite
|
8
|
+
class Token
|
9
|
+
DEFAULT_SIGNATURE_METHOD = 'HMAC-SHA256'
|
10
|
+
OAUTH_VERSION = '1.0'
|
11
|
+
|
12
|
+
attr_reader :body,
|
13
|
+
:body_json_string,
|
14
|
+
:consumer_key,
|
15
|
+
:consumer_secret,
|
16
|
+
:method,
|
17
|
+
:signature_method,
|
18
|
+
:token_id,
|
19
|
+
:token_secret,
|
20
|
+
:url
|
21
|
+
|
22
|
+
def initialize(body: {}, consumer_key:, consumer_secret:, method:, nonce: nil, signature_method: nil, timestamp: nil, token_id:, token_secret:, url:)
|
23
|
+
@body = body || {}
|
24
|
+
@body_json_string = body.to_json
|
25
|
+
@consumer_key = consumer_key
|
26
|
+
@consumer_secret = consumer_secret
|
27
|
+
@method = method.to_s.upcase
|
28
|
+
@nonce = nonce
|
29
|
+
@signature_method = signature_method || DEFAULT_SIGNATURE_METHOD
|
30
|
+
@timestamp = timestamp
|
31
|
+
@token_id = token_id
|
32
|
+
@token_secret = token_secret
|
33
|
+
@url = url
|
34
|
+
end
|
35
|
+
|
36
|
+
def alphanumerics
|
37
|
+
[*'0'..'9', *'A'..'Z', *'a'..'z']
|
38
|
+
end
|
39
|
+
|
40
|
+
def headers(realm:)
|
41
|
+
@headers ||= begin
|
42
|
+
authorization_parts = [
|
43
|
+
[:realm, realm],
|
44
|
+
[:oauth_consumer_key, escape(consumer_key)],
|
45
|
+
[:oauth_token, escape(token_id)],
|
46
|
+
[:oauth_signature_method, signature_method],
|
47
|
+
[:oauth_timestamp, timestamp],
|
48
|
+
[:oauth_nonce, escape(nonce)],
|
49
|
+
[:oauth_version, OAUTH_VERSION],
|
50
|
+
[:oauth_signature, escape(signature)]
|
51
|
+
]
|
52
|
+
|
53
|
+
ret = {
|
54
|
+
'Authorization' => "OAuth #{authorization_parts.map { |k, v| "#{k}=\"#{v}\"" }.join(',')}"
|
55
|
+
}
|
56
|
+
|
57
|
+
ret
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def nonce
|
62
|
+
@nonce ||= Array.new(20) { alphanumerics.sample }.join
|
63
|
+
end
|
64
|
+
|
65
|
+
def signature
|
66
|
+
@signature ||= compute_digest(signature_data_string)
|
67
|
+
end
|
68
|
+
|
69
|
+
# Ref: https://tools.ietf.org/html/rfc5849#section-3.4.1.3.2
|
70
|
+
def signature_data_string
|
71
|
+
@signature_data_string ||= begin
|
72
|
+
[
|
73
|
+
method,
|
74
|
+
escape(url_without_params),
|
75
|
+
escape(parameters_string)
|
76
|
+
].join('&')
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def signature_key
|
81
|
+
@signature_key ||= [
|
82
|
+
consumer_secret,
|
83
|
+
token_secret
|
84
|
+
].join('&')
|
85
|
+
end
|
86
|
+
|
87
|
+
def timestamp
|
88
|
+
@timestamp ||= Time.now.to_i
|
89
|
+
end
|
90
|
+
|
91
|
+
private
|
92
|
+
|
93
|
+
def body_array
|
94
|
+
@body_array ||= body.to_param.split('&').map { |k| k.split('=').map { |v| unescape(v) } }
|
95
|
+
end
|
96
|
+
|
97
|
+
def compute_digest(str)
|
98
|
+
signer = Util::Signer.new(str: str)
|
99
|
+
|
100
|
+
case signature_method
|
101
|
+
when 'HMAC-SHA1'
|
102
|
+
signer.hmac_sha1(key: signature_key)
|
103
|
+
when 'HMAC-SHA256'
|
104
|
+
signer.hmac_sha256(key: signature_key)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
def escape(val)
|
109
|
+
Util::Signer.escape(str: val.to_s)
|
110
|
+
end
|
111
|
+
|
112
|
+
def oauth_parameters_array
|
113
|
+
{
|
114
|
+
oauth_consumer_key: consumer_key,
|
115
|
+
oauth_nonce: nonce,
|
116
|
+
oauth_signature_method: signature_method,
|
117
|
+
oauth_timestamp: timestamp,
|
118
|
+
oauth_token: token_id,
|
119
|
+
oauth_version: OAUTH_VERSION
|
120
|
+
}.to_a
|
121
|
+
end
|
122
|
+
|
123
|
+
def parameters_string
|
124
|
+
@parameters_string ||= sorted_encoded_parameters
|
125
|
+
.map { |e| "#{e[0]}=#{e[1]}" }
|
126
|
+
.join('&')
|
127
|
+
end
|
128
|
+
|
129
|
+
def sorted_encoded_parameters
|
130
|
+
@sorted_encoded_parameters ||= url_params
|
131
|
+
.to_a
|
132
|
+
.concat(oauth_parameters_array)
|
133
|
+
.map { |k, v| [escape(k), escape(v)] }
|
134
|
+
.sort { |a, b| a <=> b }
|
135
|
+
end
|
136
|
+
|
137
|
+
def unescape(val)
|
138
|
+
Util::Signer.unescape(str: val.to_s)
|
139
|
+
end
|
140
|
+
|
141
|
+
def uri
|
142
|
+
@uri ||= URI(url)
|
143
|
+
end
|
144
|
+
|
145
|
+
def url_params
|
146
|
+
return {} if uri.query.nil?
|
147
|
+
|
148
|
+
@url_params ||= Hash[CGI.parse(uri.query).map { |k, v| [k, v.first] }]
|
149
|
+
end
|
150
|
+
|
151
|
+
def url_without_params
|
152
|
+
@url_without_params ||= begin
|
153
|
+
temp_url = uri.dup
|
154
|
+
temp_url.fragment = nil
|
155
|
+
temp_url.query = nil
|
156
|
+
temp_url.to_s
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module LedgerSync
|
4
|
+
module Adaptors
|
5
|
+
module NetSuite
|
6
|
+
module Vendor
|
7
|
+
class LedgerDeserializer < NetSuite::LedgerSerializer
|
8
|
+
id
|
9
|
+
|
10
|
+
attribute ledger_attribute: :companyName,
|
11
|
+
resource_attribute: :company_name
|
12
|
+
|
13
|
+
attribute ledger_attribute: :email,
|
14
|
+
resource_attribute: :email
|
15
|
+
|
16
|
+
attribute ledger_attribute: :phone,
|
17
|
+
resource_attribute: :phone_number
|
18
|
+
|
19
|
+
attribute ledger_attribute: :firstName,
|
20
|
+
resource_attribute: :first_name
|
21
|
+
|
22
|
+
attribute ledger_attribute: :lastName,
|
23
|
+
resource_attribute: :last_name
|
24
|
+
|
25
|
+
attribute ledger_attribute: :subsidiary,
|
26
|
+
resource_attribute: :subsidiary,
|
27
|
+
type: LedgerSerializerType::SubsidiaryType
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module LedgerSync
|
4
|
+
module Adaptors
|
5
|
+
module NetSuite
|
6
|
+
module Vendor
|
7
|
+
class LedgerSerializer < NetSuite::LedgerSerializer
|
8
|
+
api_resource_type :vendor
|
9
|
+
|
10
|
+
attribute ledger_attribute: :companyName,
|
11
|
+
resource_attribute: :company_name
|
12
|
+
|
13
|
+
attribute ledger_attribute: :entityId,
|
14
|
+
resource_attribute: :external_id
|
15
|
+
|
16
|
+
attribute ledger_attribute: :externalId,
|
17
|
+
resource_attribute: :external_id
|
18
|
+
|
19
|
+
attribute ledger_attribute: :email,
|
20
|
+
resource_attribute: :email
|
21
|
+
|
22
|
+
attribute ledger_attribute: :firstName,
|
23
|
+
resource_attribute: :first_name
|
24
|
+
|
25
|
+
attribute ledger_attribute: :lastName,
|
26
|
+
resource_attribute: :last_name
|
27
|
+
|
28
|
+
attribute ledger_attribute: :subsidiary,
|
29
|
+
resource_attribute: :subsidiary,
|
30
|
+
type: LedgerSerializerType::SubsidiaryType
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|