ledger_sync 1.3.4 → 1.3.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +14 -1
- data/.ruby-version +1 -0
- data/.travis.yml +3 -2
- data/Dockerfile +2 -2
- data/Gemfile.lock +11 -11
- data/LICENSE.txt +97 -21
- data/README.md +28 -11
- data/bin/quickbooks_online_oauth_server.rb +101 -0
- data/lib/ledger_sync.rb +8 -0
- data/lib/ledger_sync/adaptor_configuration.rb +4 -4
- data/lib/ledger_sync/adaptor_configuration_store.rb +4 -4
- data/lib/ledger_sync/adaptors/adaptor.rb +4 -6
- data/lib/ledger_sync/adaptors/dashboard_url_helper.rb +23 -0
- data/lib/ledger_sync/adaptors/ledger_serializer_attribute_set.rb +3 -5
- data/lib/ledger_sync/adaptors/mixins/infer_ledger_serializer_mixin.rb +16 -0
- data/lib/ledger_sync/adaptors/netsuite/account/searcher_ledger_deserializer.rb +30 -0
- data/lib/ledger_sync/adaptors/netsuite/adaptor.rb +11 -3
- data/lib/ledger_sync/adaptors/netsuite/customer/searcher.rb +12 -0
- data/lib/ledger_sync/adaptors/netsuite/customer/searcher_ledger_deserializer.rb +23 -0
- data/lib/ledger_sync/adaptors/netsuite/dashboard_url_helper.rb +24 -0
- data/lib/ledger_sync/adaptors/netsuite/department/searcher_ledger_deserializer.rb +21 -0
- data/lib/ledger_sync/adaptors/netsuite/ledger_serializer_type/active_type.rb +26 -0
- data/lib/ledger_sync/adaptors/netsuite/location/ledger_serializer.rb +18 -0
- data/lib/ledger_sync/adaptors/netsuite/location/operations/create.rb +21 -0
- data/lib/ledger_sync/adaptors/netsuite/location/operations/delete.rb +21 -0
- data/lib/ledger_sync/adaptors/netsuite/location/operations/find.rb +21 -0
- data/lib/ledger_sync/adaptors/netsuite/location/operations/update.rb +21 -0
- data/lib/ledger_sync/adaptors/netsuite/location/searcher.rb +12 -0
- data/lib/ledger_sync/adaptors/netsuite/record/http_method.rb +1 -1
- data/lib/ledger_sync/adaptors/netsuite/record/metadata.rb +11 -7
- data/lib/ledger_sync/adaptors/netsuite/searcher.rb +30 -8
- data/lib/ledger_sync/adaptors/netsuite/vendor/searcher.rb +12 -0
- data/lib/ledger_sync/adaptors/netsuite/vendor/searcher_ledger_deserializer.rb +23 -0
- data/lib/ledger_sync/adaptors/operation.rb +7 -3
- data/lib/ledger_sync/adaptors/quickbooks_online/adaptor.rb +7 -2
- data/lib/ledger_sync/adaptors/quickbooks_online/dashboard_url_helper.rb +1 -26
- data/lib/ledger_sync/adaptors/quickbooks_online/department/ledger_serializer.rb +6 -3
- data/lib/ledger_sync/adaptors/quickbooks_online/ledger_serializer.rb +1 -1
- data/lib/ledger_sync/adaptors/quickbooks_online/ledger_serializer_type/department_reference_type.rb +26 -0
- data/lib/ledger_sync/adaptors/quickbooks_online/operation/full_update.rb +0 -1
- data/lib/ledger_sync/adaptors/quickbooks_online/util/adaptor_error_parser.rb +5 -5
- data/lib/ledger_sync/adaptors/quickbooks_online/util/error_matcher.rb +1 -1
- data/lib/ledger_sync/adaptors/quickbooks_online/util/error_parser.rb +1 -1
- data/lib/ledger_sync/adaptors/quickbooks_online/util/operation_error_parser.rb +5 -5
- data/lib/ledger_sync/adaptors/stripe/adaptor.rb +4 -12
- data/lib/ledger_sync/adaptors/stripe/dashboard_url_helper.rb +21 -0
- data/lib/ledger_sync/deserializer.rb +59 -0
- data/lib/ledger_sync/error/adaptor_errors.rb +2 -2
- data/lib/ledger_sync/error/resource_errors.rb +18 -19
- data/lib/ledger_sync/resource.rb +9 -8
- data/lib/ledger_sync/resource_attribute.rb +30 -7
- data/lib/ledger_sync/resource_attribute/mixin.rb +13 -23
- data/lib/ledger_sync/resource_attribute/reference/many.rb +11 -5
- data/lib/ledger_sync/resource_attribute/reference/one.rb +10 -4
- data/lib/ledger_sync/resource_attribute_set.rb +3 -7
- data/lib/ledger_sync/resources/location.rb +7 -0
- data/lib/ledger_sync/serialization/attribute.rb +47 -0
- data/lib/ledger_sync/serialization/attribute_set_mixin.rb +27 -0
- data/lib/ledger_sync/serialization/deserializer_attribute.rb +60 -0
- data/lib/ledger_sync/serialization/deserializer_attribute_set.rb +22 -0
- data/lib/ledger_sync/serialization/deserializer_delegator.rb +17 -0
- data/lib/ledger_sync/serialization/mixin.rb +72 -0
- data/lib/ledger_sync/serialization/serializer_attribute.rb +51 -0
- data/lib/ledger_sync/serialization/serializer_attribute_set.rb +22 -0
- data/lib/ledger_sync/serialization/serializer_delegator.rb +17 -0
- data/lib/ledger_sync/serialization/type/references_many_type.rb +19 -0
- data/lib/ledger_sync/serialization/type/references_one_type.rb +12 -0
- data/lib/ledger_sync/serialization/type/serializer_type.rb +23 -0
- data/lib/ledger_sync/serialization/type/value_type.rb +15 -0
- data/lib/ledger_sync/serializer.rb +46 -0
- data/lib/ledger_sync/type/date.rb +2 -0
- data/lib/ledger_sync/type/id.rb +2 -0
- data/lib/ledger_sync/type/reference_one.rb +8 -4
- data/lib/ledger_sync/type/value_mixin.rb +2 -2
- data/lib/ledger_sync/util/mixins/delegate_iterable_methods_mixin.rb +42 -0
- data/lib/ledger_sync/util/mixins/dupable_mixin.rb +13 -0
- data/lib/ledger_sync/version.rb +1 -1
- metadata +39 -3
@@ -27,8 +27,8 @@ module LedgerSync
|
|
27
27
|
@module_string = module_string || LedgerSync::Util::StringHelpers.camelcase(root_key)
|
28
28
|
end
|
29
29
|
|
30
|
-
def
|
31
|
-
@
|
30
|
+
def adaptor_class
|
31
|
+
@adaptor_class ||= base_module::Adaptor
|
32
32
|
end
|
33
33
|
|
34
34
|
def add_alias(new_alias)
|
@@ -45,13 +45,13 @@ module LedgerSync
|
|
45
45
|
# Delegate #new to the adaptor class enabling faster adaptor initialization
|
46
46
|
# e.g. LedgerSync.adaptors.test.new(...)
|
47
47
|
def new(*args)
|
48
|
-
|
48
|
+
adaptor_class.new(*args)
|
49
49
|
end
|
50
50
|
|
51
51
|
# Delegate #new_from_env to the adaptor class enabling faster adaptor initialization
|
52
52
|
# e.g. LedgerSync.adaptors.test.new_from_env(...)
|
53
53
|
def new_from_env(*args)
|
54
|
-
|
54
|
+
adaptor_class.new_from_env(*args)
|
55
55
|
end
|
56
56
|
|
57
57
|
def test?
|
@@ -8,7 +8,7 @@ module LedgerSync
|
|
8
8
|
@keys = []
|
9
9
|
@configs = {}
|
10
10
|
@inflections = []
|
11
|
-
@
|
11
|
+
@class_configs = {}
|
12
12
|
end
|
13
13
|
|
14
14
|
def add_alias(adaptor_key, existing_config)
|
@@ -21,8 +21,8 @@ module LedgerSync
|
|
21
21
|
_instance_methods_for(adaptor_key: adaptor_key, adaptor_config: existing_config)
|
22
22
|
end
|
23
23
|
|
24
|
-
def
|
25
|
-
@
|
24
|
+
def config_from_class(adaptor_class:)
|
25
|
+
@class_configs.fetch(adaptor_class)
|
26
26
|
end
|
27
27
|
|
28
28
|
def each
|
@@ -42,7 +42,7 @@ module LedgerSync
|
|
42
42
|
@keys << adaptor_key.to_sym
|
43
43
|
|
44
44
|
@configs[adaptor_key] = adaptor_config
|
45
|
-
@
|
45
|
+
@class_configs[adaptor_config.adaptor_class] = adaptor_config
|
46
46
|
|
47
47
|
instance_variable_set(
|
48
48
|
"@#{adaptor_key}",
|
@@ -41,13 +41,11 @@ module LedgerSync
|
|
41
41
|
)
|
42
42
|
end
|
43
43
|
|
44
|
-
def searcher_for
|
45
|
-
|
46
|
-
rescue NameError
|
47
|
-
false
|
44
|
+
def searcher_for(resource_type:, query: '')
|
45
|
+
searcher_class_for(resource_type: resource_type).new(adaptor: self, query: query)
|
48
46
|
end
|
49
47
|
|
50
|
-
def
|
48
|
+
def searcher_class_for(resource_type:)
|
51
49
|
base_module.const_get(LedgerSync::Util::StringHelpers.camelcase(resource_type.to_s))::Searcher
|
52
50
|
end
|
53
51
|
|
@@ -68,7 +66,7 @@ module LedgerSync
|
|
68
66
|
end
|
69
67
|
|
70
68
|
def self.config
|
71
|
-
@config ||= LedgerSync.adaptors.
|
69
|
+
@config ||= LedgerSync.adaptors.config_from_class(adaptor_class: self)
|
72
70
|
end
|
73
71
|
|
74
72
|
# These are attributes that must always be saved after the adaptor is called.
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module LedgerSync
|
4
|
+
module Adaptors
|
5
|
+
class DashboardURLHelper
|
6
|
+
attr_reader :resource,
|
7
|
+
:base_url
|
8
|
+
|
9
|
+
def initialize(resource:, base_url:)
|
10
|
+
@resource = resource
|
11
|
+
@base_url = base_url
|
12
|
+
end
|
13
|
+
|
14
|
+
def url
|
15
|
+
@base_url + resource_path
|
16
|
+
end
|
17
|
+
|
18
|
+
def resource_path
|
19
|
+
raise NotImplementedError
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -3,6 +3,8 @@
|
|
3
3
|
module LedgerSync
|
4
4
|
module Adaptors
|
5
5
|
class LedgerSerializerAttributeSet
|
6
|
+
include Util::Mixins::DelegateIterableMethodsMixin
|
7
|
+
|
6
8
|
attr_reader :attributes,
|
7
9
|
:deserializable_attributes,
|
8
10
|
:id_attribute,
|
@@ -11,11 +13,7 @@ module LedgerSync
|
|
11
13
|
:serializable_attributes,
|
12
14
|
:serializer_class
|
13
15
|
|
14
|
-
|
15
|
-
:each,
|
16
|
-
:include?,
|
17
|
-
:map,
|
18
|
-
to: :attributes
|
16
|
+
delegate_array_methods_to :attributes
|
19
17
|
|
20
18
|
def initialize(serializer_class:)
|
21
19
|
@attributes = []
|
@@ -21,6 +21,22 @@ module LedgerSync
|
|
21
21
|
@inferred_ledger_deserializer_class_name ||= "#{inferred_resource_class.resource_module_str}::LedgerDeserializer"
|
22
22
|
end
|
23
23
|
|
24
|
+
def inferred_searcher_ledger_deserializer_class
|
25
|
+
@inferred_searcher_ledger_deserializer_class ||= begin
|
26
|
+
inferred_adaptor_class.base_module.const_get(
|
27
|
+
inferred_searcher_ledger_deserializer_class_name
|
28
|
+
)
|
29
|
+
rescue NameError
|
30
|
+
inferred_adaptor_class.base_module.const_get(
|
31
|
+
inferred_ledger_serializer_class_name
|
32
|
+
)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def inferred_searcher_ledger_deserializer_class_name
|
37
|
+
@inferred_searcher_ledger_deserializer_class_name ||= "#{inferred_resource_class.resource_module_str}::SearcherLedgerDeserializer"
|
38
|
+
end
|
39
|
+
|
24
40
|
def inferred_ledger_serializer_class
|
25
41
|
@inferred_ledger_serializer_class ||= begin
|
26
42
|
inferred_adaptor_class.base_module.const_get(
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module LedgerSync
|
4
|
+
module Adaptors
|
5
|
+
module NetSuite
|
6
|
+
module Account
|
7
|
+
class SearcherLedgerDeserializer < NetSuite::LedgerSerializer
|
8
|
+
attribute ledger_attribute: :id,
|
9
|
+
resource_attribute: :ledger_id
|
10
|
+
|
11
|
+
attribute ledger_attribute: :accountsearchdisplayname,
|
12
|
+
resource_attribute: :name
|
13
|
+
|
14
|
+
attribute ledger_attribute: :acctnumber,
|
15
|
+
resource_attribute: :number
|
16
|
+
|
17
|
+
attribute ledger_attribute: :accttype,
|
18
|
+
resource_attribute: :account_type
|
19
|
+
|
20
|
+
attribute ledger_attribute: :description,
|
21
|
+
resource_attribute: :description
|
22
|
+
|
23
|
+
attribute ledger_attribute: :isinactive,
|
24
|
+
resource_attribute: :active,
|
25
|
+
type: LedgerSerializerType::ActiveType
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -12,7 +12,8 @@ module LedgerSync
|
|
12
12
|
|
13
13
|
WRITE_HEADERS = {
|
14
14
|
'Accept' => '*/*',
|
15
|
-
'Content-Type' => 'application/json'
|
15
|
+
'Content-Type' => 'application/json',
|
16
|
+
'prefer' => 'transient'
|
16
17
|
}.freeze
|
17
18
|
|
18
19
|
attr_reader :account_id,
|
@@ -100,6 +101,13 @@ module LedgerSync
|
|
100
101
|
)
|
101
102
|
end
|
102
103
|
|
104
|
+
def url_for(resource:)
|
105
|
+
DashboardURLHelper.new(
|
106
|
+
resource: resource,
|
107
|
+
base_url: "https://#{account_id_for_url}.app.netsuite.com"
|
108
|
+
).url
|
109
|
+
end
|
110
|
+
|
103
111
|
private
|
104
112
|
|
105
113
|
def new_token(body:, method:, url:)
|
@@ -114,8 +122,8 @@ module LedgerSync
|
|
114
122
|
)
|
115
123
|
end
|
116
124
|
|
117
|
-
def request(body: nil, headers: {}, method:, path: nil)
|
118
|
-
request_url
|
125
|
+
def request(body: nil, headers: {}, method:, path: nil, request_url: nil)
|
126
|
+
request_url ||= url_from_path(path: path)
|
119
127
|
|
120
128
|
token = new_token(
|
121
129
|
body: body,
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module LedgerSync
|
4
|
+
module Adaptors
|
5
|
+
module NetSuite
|
6
|
+
module Customer
|
7
|
+
class SearcherLedgerDeserializer < NetSuite::LedgerSerializer
|
8
|
+
attribute ledger_attribute: :id,
|
9
|
+
resource_attribute: :ledger_id
|
10
|
+
|
11
|
+
attribute ledger_attribute: :email,
|
12
|
+
resource_attribute: :email
|
13
|
+
|
14
|
+
attribute ledger_attribute: :companyname,
|
15
|
+
resource_attribute: :name
|
16
|
+
|
17
|
+
attribute ledger_attribute: :phone,
|
18
|
+
resource_attribute: :phone_number
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module LedgerSync
|
4
|
+
module Adaptors
|
5
|
+
module NetSuite
|
6
|
+
class DashboardURLHelper < LedgerSync::Adaptors::DashboardURLHelper
|
7
|
+
def resource_path
|
8
|
+
@resource_path = case resource
|
9
|
+
when LedgerSync::Account
|
10
|
+
"/app/accounting/account/account.nl?id=#{resource.ledger_id}"
|
11
|
+
when LedgerSync::Currency
|
12
|
+
"/app/common/multicurrency/currency.nl?id=#{resource.ledger_id}"
|
13
|
+
when LedgerSync::Customer, LedgerSync::Vendor
|
14
|
+
"/app/common/entity/entity.nl?id=#{resource.ledger_id}"
|
15
|
+
when LedgerSync::Department
|
16
|
+
"/app/common/otherlists/departmenttype.nl?id=#{resource.ledger_id}"
|
17
|
+
when LedgerSync::Deposit, LedgerSync::Invoice
|
18
|
+
"/app/accounting/transactions/transaction.nl?id=#{resource.ledger_id}"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module LedgerSync
|
4
|
+
module Adaptors
|
5
|
+
module NetSuite
|
6
|
+
module Department
|
7
|
+
class SearcherLedgerDeserializer < NetSuite::LedgerSerializer
|
8
|
+
attribute ledger_attribute: :id,
|
9
|
+
resource_attribute: :ledger_id
|
10
|
+
|
11
|
+
attribute ledger_attribute: :name,
|
12
|
+
resource_attribute: :name
|
13
|
+
|
14
|
+
attribute ledger_attribute: :isinactive,
|
15
|
+
resource_attribute: :active,
|
16
|
+
type: LedgerSerializerType::ActiveType
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module LedgerSync
|
4
|
+
module Adaptors
|
5
|
+
module NetSuite
|
6
|
+
module LedgerSerializerType
|
7
|
+
class ActiveType < Adaptors::LedgerSerializerType::ValueType
|
8
|
+
def convert_from_ledger(value:)
|
9
|
+
return if value.nil?
|
10
|
+
|
11
|
+
case value
|
12
|
+
when "F"
|
13
|
+
true
|
14
|
+
when "T"
|
15
|
+
false
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def convert_from_local(value:)
|
20
|
+
raise NotImplementedError
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module LedgerSync
|
4
|
+
module Adaptors
|
5
|
+
module NetSuite
|
6
|
+
module Location
|
7
|
+
class LedgerSerializer < NetSuite::LedgerSerializer
|
8
|
+
id
|
9
|
+
|
10
|
+
api_resource_type :location
|
11
|
+
|
12
|
+
attribute ledger_attribute: :name,
|
13
|
+
resource_attribute: :name
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module LedgerSync
|
4
|
+
module Adaptors
|
5
|
+
module NetSuite
|
6
|
+
module Location
|
7
|
+
module Operations
|
8
|
+
class Create < NetSuite::Operation::Create
|
9
|
+
class Contract < LedgerSync::Adaptors::Contract
|
10
|
+
params do
|
11
|
+
required(:external_id).filled(:string)
|
12
|
+
required(:ledger_id).value(:nil)
|
13
|
+
required(:name).filled(:string)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module LedgerSync
|
4
|
+
module Adaptors
|
5
|
+
module NetSuite
|
6
|
+
module Location
|
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(:name).maybe(:string)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module LedgerSync
|
4
|
+
module Adaptors
|
5
|
+
module NetSuite
|
6
|
+
module Location
|
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
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module LedgerSync
|
4
|
+
module Adaptors
|
5
|
+
module NetSuite
|
6
|
+
module Location
|
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(:name).filled(:string)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|