ledger_sync 1.0.3 → 1.0.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3eef310e76d4f2c34d27c0ce04c4d2e0444a9a0302aa1cdaa256d0e6fb7d016d
4
- data.tar.gz: a67d7615d9b0baf81030c87710311626e0a49c191e4117b39fadc61efac9f940
3
+ metadata.gz: a8d5a5be8f33aef0b70287973668acd641f71f7e06b20f3d85434bc288fa830e
4
+ data.tar.gz: a615a430f2626f52ac180535acb984b6442f95ecd906334811cc11945cabbb34
5
5
  SHA512:
6
- metadata.gz: fb3cd1f4d5286e5b8aba3c7a3638a7b82b1196994c07ed5ed201e3cfbaf4d191a3ad56f8063ffc301e1dde84bbe12740bfee7a4667fa3e55b58cbc80e96761f8
7
- data.tar.gz: f8ad8bb6f568771db61a0c337ea101cb0663834628404bdb1f2c06dd1e6fc7b4bfaf89b17a526292773bbdb4ce249c09005a4a33e9e5530fdce9cc8ddc53b30a
6
+ metadata.gz: f720526be8256e44a3b662d311f15f0592bf57462e88576fbd0edcb9350ec6e372d837220d6b4776f9b2a88d4e2b3292cd34cda93dfdad3a6c33f35d9b1b0c78
7
+ data.tar.gz: fd581d7964f36989bcf90c0420c875c5881f04d07eedf10a16cd3d392d0a44827b6adef05106f10cb26e5a867b09d9c05d4ab64b285126f0801aa6a6815bf0ca
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ledger_sync (1.0.3)
4
+ ledger_sync (1.0.9)
5
5
  colorize
6
6
  coveralls
7
7
  dry-schema
@@ -59,7 +59,7 @@ GEM
59
59
  dry-initializer (~> 3.0)
60
60
  dry-logic (~> 1.0)
61
61
  dry-types (~> 1.0)
62
- dry-types (1.1.0)
62
+ dry-types (1.1.1)
63
63
  concurrent-ruby (~> 1.0)
64
64
  dry-container (~> 0.3)
65
65
  dry-core (~> 0.4, >= 0.4.4)
@@ -161,4 +161,4 @@ DEPENDENCIES
161
161
  webmock
162
162
 
163
163
  BUNDLED WITH
164
- 1.17.2
164
+ 1.17.3
@@ -21,9 +21,7 @@ require 'ledger_sync/core_ext/resonad'
21
21
 
22
22
  # Errors
23
23
  require 'ledger_sync/error'
24
- require 'ledger_sync/error/adaptor_errors'
25
- require 'ledger_sync/error/operation_errors'
26
- require 'ledger_sync/error/resource_errors'
24
+ Gem.find_files('ledger_sync/error/**/*.rb').each { |path| require path }
27
25
 
28
26
  # Support Classes
29
27
  require 'ledger_sync/util/debug'
@@ -42,10 +40,7 @@ require 'ledger_sync/adaptors/contract'
42
40
  # Resources (resources are registerd below)
43
41
  require 'ledger_sync/resource' # Template class
44
42
  require 'ledger_sync/resources/customer'
45
- require 'ledger_sync/resources/vendor'
46
- require 'ledger_sync/resources/invoice'
47
43
  require 'ledger_sync/resources/payment'
48
- require 'ledger_sync/resources/product'
49
44
 
50
45
  # Synchronizer
51
46
  require 'ledger_sync/sync'
@@ -112,7 +107,4 @@ Gem.find_files('ledger_sync/adaptors/**/config.rb').each { |path| require path }
112
107
 
113
108
  # Register Resources
114
109
  LedgerSync.register_resource(resource: LedgerSync::Customer)
115
- LedgerSync.register_resource(resource: LedgerSync::Vendor)
116
- LedgerSync.register_resource(resource: LedgerSync::Invoice)
117
110
  LedgerSync.register_resource(resource: LedgerSync::Payment)
118
- LedgerSync.register_resource(resource: LedgerSync::Product)
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LedgerSync
4
+ class Error
5
+ class SyncError < Error
6
+ attr_reader :sync
7
+
8
+ def initialize(message:, sync:)
9
+ @sync = sync
10
+ super(message: message)
11
+ end
12
+
13
+ class NotPerformedError < self
14
+ def initialize(message: nil, sync:)
15
+ message ||= 'Sync has not been performed. Call perform before retrieving the result.'
16
+
17
+ super(message: message, sync: sync)
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -44,7 +44,7 @@ module LedgerSync
44
44
  raise 'Missing adaptor' if adaptor.nil?
45
45
  raise 'Missing operation' if operation.nil?
46
46
 
47
- validate
47
+ @result = validate
48
48
  .and_then { performer.perform }
49
49
  .on_success { return SyncResult.Success(sync: self) }
50
50
  .on_failure { return SyncResult.Failure(sync: self) }
@@ -72,10 +72,6 @@ module LedgerSync
72
72
  )
73
73
  end
74
74
 
75
- def operation_results
76
- @operation_results ||= performer.results
77
- end
78
-
79
75
  def performer
80
76
  @performer ||= Util::Performer.new(operations: operations)
81
77
  end
@@ -96,6 +92,12 @@ module LedgerSync
96
92
  )
97
93
  end
98
94
 
95
+ def result
96
+ raise Error::SyncError::NotPerformedError.new(sync: self) unless @perform.present?
97
+
98
+ @result
99
+ end
100
+
99
101
  private
100
102
 
101
103
  def validate
@@ -1,3 +1,3 @@
1
1
  module LedgerSync
2
- VERSION = '1.0.3'.freeze
2
+ VERSION = '1.0.9'.freeze
3
3
  end
data/release.sh CHANGED
@@ -1,8 +1,14 @@
1
1
  #!/bin/bash
2
2
 
3
3
  if output=$(git status --porcelain) && [ -z "$output" ]; then
4
- bump $1 && git push && bundle exec rake build && bundle exec rake release
4
+ bundle exec bump $1 && \
5
+ echo "Pushing to github" && \
6
+ git push && \
7
+ echo "Building gem" && \
8
+ bundle exec rake build && \
9
+ echo "Releasing gem" && \
10
+ bundle exec rake release
5
11
  else
6
- echo 'PLEASE COMMIT ALL CHANGES BEFORE RELEASING.'
12
+ >&2 echo 'PLEASE COMMIT ALL CHANGES BEFORE RELEASING.'
7
13
  exit 1
8
14
  fi
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ledger_sync
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Jackson
@@ -343,18 +343,10 @@ files:
343
343
  - lib/ledger_sync/adaptors/quickbooks_online/customer/operations/update.rb
344
344
  - lib/ledger_sync/adaptors/quickbooks_online/customer/operations/upsert.rb
345
345
  - lib/ledger_sync/adaptors/quickbooks_online/customer/searcher.rb
346
- - lib/ledger_sync/adaptors/quickbooks_online/invoice/operations/create.rb
347
- - lib/ledger_sync/adaptors/quickbooks_online/invoice/operations/find.rb
348
- - lib/ledger_sync/adaptors/quickbooks_online/invoice/operations/update.rb
349
- - lib/ledger_sync/adaptors/quickbooks_online/invoice/operations/upsert.rb
350
346
  - lib/ledger_sync/adaptors/quickbooks_online/payment/operations/create.rb
351
347
  - lib/ledger_sync/adaptors/quickbooks_online/payment/operations/find.rb
352
348
  - lib/ledger_sync/adaptors/quickbooks_online/payment/operations/update.rb
353
349
  - lib/ledger_sync/adaptors/quickbooks_online/payment/operations/upsert.rb
354
- - lib/ledger_sync/adaptors/quickbooks_online/product/operations/create.rb
355
- - lib/ledger_sync/adaptors/quickbooks_online/product/operations/find.rb
356
- - lib/ledger_sync/adaptors/quickbooks_online/product/operations/update.rb
357
- - lib/ledger_sync/adaptors/quickbooks_online/product/operations/upsert.rb
358
350
  - lib/ledger_sync/adaptors/quickbooks_online/util/adaptor_error_parser.rb
359
351
  - lib/ledger_sync/adaptors/quickbooks_online/util/error_matcher.rb
360
352
  - lib/ledger_sync/adaptors/quickbooks_online/util/error_parser.rb
@@ -380,12 +372,10 @@ files:
380
372
  - lib/ledger_sync/error/adaptor_errors.rb
381
373
  - lib/ledger_sync/error/operation_errors.rb
382
374
  - lib/ledger_sync/error/resource_errors.rb
375
+ - lib/ledger_sync/error/sync_errors.rb
383
376
  - lib/ledger_sync/resource.rb
384
377
  - lib/ledger_sync/resources/customer.rb
385
- - lib/ledger_sync/resources/invoice.rb
386
378
  - lib/ledger_sync/resources/payment.rb
387
- - lib/ledger_sync/resources/product.rb
388
- - lib/ledger_sync/resources/vendor.rb
389
379
  - lib/ledger_sync/result.rb
390
380
  - lib/ledger_sync/sync.rb
391
381
  - lib/ledger_sync/util/coordinator.rb
@@ -416,7 +406,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
416
406
  - !ruby/object:Gem::Version
417
407
  version: '0'
418
408
  requirements: []
419
- rubygems_version: 3.0.3
409
+ rubygems_version: 3.0.4
420
410
  signing_key:
421
411
  specification_version: 4
422
412
  summary: Sync common objects to accounting software.
@@ -1,63 +0,0 @@
1
- module LedgerSync
2
- module Adaptors
3
- module QuickBooksOnline
4
- module Invoice
5
- module Operations
6
- class Create < Operation::Create
7
- class Contract < LedgerSync::Adaptors::Contract
8
- params do
9
- required(:ledger_id).maybe(:string)
10
- required(:currency).filled(:string)
11
- required(:customer).filled(Types::Reference)
12
- required(:line_items).maybe(:array)
13
- required(:number).maybe(:integer)
14
- end
15
- end
16
-
17
- private
18
-
19
- def operate
20
- response = adaptor.upsert(
21
- resource: 'invoice',
22
- payload: local_resource_data
23
- )
24
-
25
- resource.ledger_id = response.dig('Id')
26
- success(response: response)
27
- rescue OAuth2::Error => e
28
- failure(e)
29
- end
30
-
31
- def local_resource_data
32
- {
33
- 'CurrencyRef': {
34
- 'value': resource.currency,
35
- },
36
- 'CustomerRef': {
37
- 'value': resource.customer,
38
- },
39
- 'DocNumber': resource.number,
40
- 'Line': resource.line_items.each_with_index.map do |line, i|
41
- {
42
- # 'Id': '1',
43
- 'LineNum': i,
44
- 'Amount': line.fetch(:amount),
45
- 'SalesItemLineDetail': {
46
- 'TaxCodeRef': {
47
- 'value': 'NON'
48
- },
49
- 'ItemRef': {
50
- 'value': line.fetch(:product)
51
- }
52
- },
53
- 'DetailType': 'SalesItemLineDetail'
54
- }
55
- end
56
- }
57
- end
58
- end
59
- end
60
- end
61
- end
62
- end
63
- end
@@ -1,36 +0,0 @@
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
- params do
9
- required(:ledger_id).filled(:string)
10
- required(:currency).maybe(:string)
11
- required(:customer).maybe(Types::Reference)
12
- required(:line_items).maybe(:array)
13
- required(:number).maybe(:integer)
14
- end
15
- end
16
-
17
- private
18
-
19
- def operate
20
- return failure(nil) if resource.ledger_id.nil?
21
-
22
- response = adaptor.find(
23
- resource: 'invoice',
24
- id: resource.ledger_id
25
- )
26
-
27
- success(response: response)
28
- rescue OAuth2::Error => e
29
- failure(e)
30
- end
31
- end
32
- end
33
- end
34
- end
35
- end
36
- end
@@ -1,67 +0,0 @@
1
- module LedgerSync
2
- module Adaptors
3
- module QuickBooksOnline
4
- module Invoice
5
- module Operations
6
- class Update < Operation::Update
7
- class Contract < LedgerSync::Adaptors::Contract
8
- params do
9
- required(:ledger_id).filled(:string)
10
- required(:currency).filled(:string)
11
- required(:customer).filled(Types::Reference)
12
- required(:line_items).maybe(:array)
13
- required(:number).maybe(:integer)
14
- end
15
- end
16
-
17
- private
18
-
19
- def operate
20
- ledger_resource_data = adaptor.find(
21
- resource: 'payment',
22
- id: resource.ledger_id
23
- )
24
-
25
- response = adaptor.upsert(
26
- resource: 'payment',
27
- payload: merge_into(from: local_resource_data, to: ledger_resource_data)
28
- )
29
-
30
- resource.ledger_id = response.dig('Id')
31
- success(response: response)
32
- rescue OAuth2::Error => e
33
- failure(e)
34
- end
35
-
36
- def local_resource_data
37
- {
38
- 'CurrencyRef': {
39
- 'value': resource.currency,
40
- },
41
- 'CustomerRef': {
42
- 'value': resource.customer,
43
- },
44
- 'DocNumber': resource.number,
45
- 'Line': resource.line_items.each_with_index.map do |line, i|
46
- {
47
- 'LineNum': i,
48
- 'Amount': line.fetch(:amount),
49
- 'SalesItemLineDetail': {
50
- 'TaxCodeRef': {
51
- 'value': 'NON'
52
- },
53
- 'ItemRef': {
54
- 'value': line.fetch(:product)
55
- }
56
- },
57
- 'DetailType': 'SalesItemLineDetail'
58
- }
59
- end
60
- }
61
- end
62
- end
63
- end
64
- end
65
- end
66
- end
67
- end
@@ -1,44 +0,0 @@
1
- module LedgerSync
2
- module Adaptors
3
- module QuickBooksOnline
4
- module Invoice
5
- module Operations
6
- class Upsert < Operation::Upsert
7
- class Contract < LedgerSync::Adaptors::Contract
8
- schema do
9
- required(:ledger_id).maybe(:string)
10
- required(:currency).maybe(:string)
11
- required(:customer).maybe(Types::Reference)
12
- required(:line_items).maybe(:array)
13
- required(:number).maybe(:integer)
14
- end
15
- end
16
-
17
- private
18
-
19
- def build
20
- op = if qbo_invoice?
21
- Update.new(adaptor: adaptor, resource: resource)
22
- else
23
- Create.new(adaptor: adaptor, resource: resource)
24
- end
25
-
26
- add_root_operation(op)
27
- end
28
-
29
- def find_result
30
- @find_result ||= Find.new(
31
- adaptor: adaptor,
32
- resource: resource
33
- ).perform
34
- end
35
-
36
- def qbo_invoice?
37
- find_result.success?
38
- end
39
- end
40
- end
41
- end
42
- end
43
- end
44
- end
@@ -1,46 +0,0 @@
1
- module LedgerSync
2
- module Adaptors
3
- module QuickBooksOnline
4
- module Product
5
- module Operations
6
- class Create < Operation::Create
7
- class Contract < LedgerSync::Adaptors::Contract
8
- params do
9
- required(:ledger_id).value(:nil)
10
- required(:ledger_id).value(:nil)
11
- required(:name).filled(:string)
12
- optional(:description).maybe(:string)
13
- end
14
- end
15
-
16
- private
17
-
18
- def operate
19
- response = adaptor.upsert(
20
- resource: 'item',
21
- payload: local_resource_data
22
- )
23
-
24
- resource.ledger_id = response.dig('Id')
25
- success(response: response)
26
- rescue OAuth2::Error => e
27
- failure(e)
28
- end
29
-
30
- def local_resource_data
31
- {
32
- 'Name': resource.name,
33
- 'Description': resource.description,
34
- 'Type': 'Service',
35
- 'IncomeAccountRef': {
36
- 'value': '1',
37
- 'name': 'Services'
38
- }
39
- }
40
- end
41
- end
42
- end
43
- end
44
- end
45
- end
46
- end
@@ -1,34 +0,0 @@
1
- module LedgerSync
2
- module Adaptors
3
- module QuickBooksOnline
4
- module Product
5
- module Operations
6
- class Find < Operation::Find
7
- class Contract < LedgerSync::Adaptors::Contract
8
- params do
9
- required(:ledger_id).filled(:string)
10
- optional(:description).maybe(:string)
11
- optional(:name).maybe(:string)
12
- end
13
- end
14
-
15
- private
16
-
17
- def operate
18
- return failure(nil) if resource.ledger_id.nil?
19
-
20
- response = @adaptor.find(
21
- resource: 'item',
22
- id: resource.ledger_id
23
- )
24
-
25
- success(response: response)
26
- rescue OAuth2::Error => e
27
- failure(e)
28
- end
29
- end
30
- end
31
- end
32
- end
33
- end
34
- end
@@ -1,50 +0,0 @@
1
- module LedgerSync
2
- module Adaptors
3
- module QuickBooksOnline
4
- module Product
5
- module Operations
6
- class Update < Operation::Update
7
- class Contract < LedgerSync::Adaptors::Contract
8
- params do
9
- required(:ledger_id).filled(:string)
10
- required(:name).filled(:string)
11
- optional(:description).maybe(:string)
12
- end
13
- end
14
-
15
- private
16
-
17
- def operate
18
- ledger_resource_data = adaptor.find(
19
- resource: 'item',
20
- id: resource.ledger_id
21
- )
22
-
23
- response = adaptor.upsert(
24
- resource: 'item',
25
- payload: merge_into(from: local_resource_data, to: ledger_resource_data)
26
- )
27
-
28
- resource.ledger_id = response.dig('Id')
29
- success(response: response)
30
- rescue OAuth2::Error => e
31
- failure(e)
32
- end
33
-
34
- def local_resource_data
35
- {
36
- 'Name': @resource.name,
37
- 'Description': @resource.description,
38
- 'Type': 'Service',
39
- 'IncomeAccountRef': {
40
- 'value': '1',
41
- 'name': 'Services'
42
- }
43
- }
44
- end
45
- end
46
- end
47
- end
48
- end
49
- end
50
- end
@@ -1,43 +0,0 @@
1
- module LedgerSync
2
- module Adaptors
3
- module QuickBooksOnline
4
- module Product
5
- module Operations
6
- class Upsert < Operation::Upsert
7
- class Contract < LedgerSync::Adaptors::Contract
8
- params do
9
- required(:ledger_id).maybe(:string)
10
- required(:ledger_id).maybe(:string)
11
- optional(:description).maybe(:string)
12
- required(:name).filled(:string)
13
- end
14
- end
15
-
16
- private
17
-
18
- def build
19
- op = if qbo_item?
20
- Update.new(adaptor: adaptor, resource: resource)
21
- else
22
- Create.new(adaptor: adaptor, resource: resource)
23
- end
24
-
25
- add_root_operation(op)
26
- end
27
-
28
- def find_result
29
- @find_result ||= Find.new(
30
- adaptor: adaptor,
31
- resource: resource
32
- ).perform
33
- end
34
-
35
- def qbo_item?
36
- find_result.success?
37
- end
38
- end
39
- end
40
- end
41
- end
42
- end
43
- end
@@ -1,12 +0,0 @@
1
- module LedgerSync
2
- class Invoice < LedgerSync::Resource
3
- attribute :customer
4
- attribute :number
5
- attribute :line_items
6
- attribute :currency
7
-
8
- def name
9
- "Invoice ##{number}"
10
- end
11
- end
12
- end
@@ -1,6 +0,0 @@
1
- module LedgerSync
2
- class Product < LedgerSync::Resource
3
- attribute :name
4
- attribute :description
5
- end
6
- end
@@ -1,6 +0,0 @@
1
- module LedgerSync
2
- class Vendor < LedgerSync::Resource
3
- attribute :email
4
- attribute :name
5
- end
6
- end