ledger_sync 1.0.10 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (115) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +36 -20
  3. data/README.md +105 -66
  4. data/ledger_sync.gemspec +1 -0
  5. data/lib/ledger_sync.rb +23 -4
  6. data/lib/ledger_sync/adaptors/operation.rb +28 -28
  7. data/lib/ledger_sync/adaptors/quickbooks_online/account/mapping.rb +325 -0
  8. data/lib/ledger_sync/adaptors/quickbooks_online/account/operations/create.rb +54 -0
  9. data/lib/ledger_sync/adaptors/quickbooks_online/account/operations/find.rb +38 -0
  10. data/lib/ledger_sync/adaptors/quickbooks_online/account/operations/update.rb +61 -0
  11. data/lib/ledger_sync/adaptors/quickbooks_online/account/searcher.rb +67 -0
  12. data/lib/ledger_sync/adaptors/quickbooks_online/adaptor.rb +18 -16
  13. data/lib/ledger_sync/adaptors/quickbooks_online/bill/operations/create.rb +65 -0
  14. data/lib/ledger_sync/adaptors/quickbooks_online/bill/operations/find.rb +37 -0
  15. data/lib/ledger_sync/adaptors/quickbooks_online/bill/operations/update.rb +69 -0
  16. data/lib/ledger_sync/adaptors/quickbooks_online/bill/searcher.rb +28 -0
  17. data/lib/ledger_sync/adaptors/quickbooks_online/customer/operations/create.rb +6 -6
  18. data/lib/ledger_sync/adaptors/quickbooks_online/customer/operations/find.rb +1 -3
  19. data/lib/ledger_sync/adaptors/quickbooks_online/customer/operations/update.rb +6 -9
  20. data/lib/ledger_sync/adaptors/quickbooks_online/customer/searcher.rb +2 -38
  21. data/lib/ledger_sync/adaptors/quickbooks_online/deposit/operations/create.rb +61 -0
  22. data/lib/ledger_sync/adaptors/quickbooks_online/deposit/operations/find.rb +36 -0
  23. data/lib/ledger_sync/adaptors/quickbooks_online/deposit/operations/update.rb +65 -0
  24. data/lib/ledger_sync/adaptors/quickbooks_online/deposit/searcher.rb +28 -0
  25. data/lib/ledger_sync/adaptors/quickbooks_online/expense/mapping.rb +15 -0
  26. data/lib/ledger_sync/adaptors/quickbooks_online/expense/operations/create.rb +68 -0
  27. data/lib/ledger_sync/adaptors/quickbooks_online/expense/operations/find.rb +39 -0
  28. data/lib/ledger_sync/adaptors/quickbooks_online/expense/operations/update.rb +72 -0
  29. data/lib/ledger_sync/adaptors/quickbooks_online/expense/searcher.rb +28 -0
  30. data/lib/ledger_sync/adaptors/quickbooks_online/journal_entry/mapping.rb +14 -0
  31. data/lib/ledger_sync/adaptors/quickbooks_online/journal_entry/operations/create.rb +56 -0
  32. data/lib/ledger_sync/adaptors/quickbooks_online/journal_entry/operations/find.rb +34 -0
  33. data/lib/ledger_sync/adaptors/quickbooks_online/journal_entry/operations/update.rb +60 -0
  34. data/lib/ledger_sync/adaptors/quickbooks_online/journal_entry/searcher.rb +28 -0
  35. data/lib/ledger_sync/adaptors/quickbooks_online/operation.rb +30 -0
  36. data/lib/ledger_sync/adaptors/quickbooks_online/payment/operations/create.rb +8 -22
  37. data/lib/ledger_sync/adaptors/quickbooks_online/payment/operations/find.rb +0 -2
  38. data/lib/ledger_sync/adaptors/quickbooks_online/payment/operations/update.rb +6 -22
  39. data/lib/ledger_sync/adaptors/quickbooks_online/searcher.rb +45 -0
  40. data/lib/ledger_sync/adaptors/quickbooks_online/transfer/operations/create.rb +52 -0
  41. data/lib/ledger_sync/adaptors/quickbooks_online/transfer/operations/find.rb +36 -0
  42. data/lib/ledger_sync/adaptors/quickbooks_online/transfer/operations/update.rb +57 -0
  43. data/lib/ledger_sync/adaptors/quickbooks_online/vendor/operations/create.rb +46 -0
  44. data/lib/ledger_sync/adaptors/quickbooks_online/vendor/operations/find.rb +36 -0
  45. data/lib/ledger_sync/adaptors/quickbooks_online/vendor/operations/update.rb +51 -0
  46. data/lib/ledger_sync/adaptors/quickbooks_online/vendor/searcher.rb +64 -0
  47. data/lib/ledger_sync/adaptors/searcher.rb +3 -1
  48. data/lib/ledger_sync/adaptors/test/account/operations/create.rb +53 -0
  49. data/lib/ledger_sync/adaptors/test/account/operations/find.rb +38 -0
  50. data/lib/ledger_sync/adaptors/test/account/operations/invalid.rb +25 -0
  51. data/lib/ledger_sync/adaptors/test/account/operations/update.rb +50 -0
  52. data/lib/ledger_sync/adaptors/test/account/operations/valid.rb +31 -0
  53. data/lib/ledger_sync/adaptors/test/account/searcher.rb +40 -0
  54. data/lib/ledger_sync/adaptors/test/adaptor.rb +4 -4
  55. data/lib/ledger_sync/adaptors/test/customer/operations/create.rb +4 -6
  56. data/lib/ledger_sync/adaptors/test/customer/operations/find.rb +0 -2
  57. data/lib/ledger_sync/adaptors/test/customer/operations/update.rb +4 -6
  58. data/lib/ledger_sync/adaptors/test/customer/searcher.rb +2 -2
  59. data/lib/ledger_sync/adaptors/test/expense/operations/create.rb +54 -0
  60. data/lib/ledger_sync/adaptors/test/expense/operations/find.rb +39 -0
  61. data/lib/ledger_sync/adaptors/test/expense/operations/update.rb +57 -0
  62. data/lib/ledger_sync/adaptors/test/payment/operations/create.rb +4 -20
  63. data/lib/ledger_sync/adaptors/test/payment/operations/find.rb +0 -2
  64. data/lib/ledger_sync/adaptors/test/payment/operations/update.rb +4 -20
  65. data/lib/ledger_sync/adaptors/test/transfer/operations/create.rb +45 -0
  66. data/lib/ledger_sync/adaptors/test/transfer/operations/find.rb +36 -0
  67. data/lib/ledger_sync/adaptors/test/transfer/operations/update.rb +48 -0
  68. data/lib/ledger_sync/adaptors/test/vendor/operations/create.rb +47 -0
  69. data/lib/ledger_sync/adaptors/test/vendor/operations/find.rb +34 -0
  70. data/lib/ledger_sync/adaptors/test/vendor/operations/invalid.rb +21 -0
  71. data/lib/ledger_sync/adaptors/test/vendor/operations/update.rb +44 -0
  72. data/lib/ledger_sync/adaptors/test/vendor/operations/valid.rb +27 -0
  73. data/lib/ledger_sync/adaptors/test/vendor/searcher.rb +41 -0
  74. data/lib/ledger_sync/error/resource_errors.rb +24 -0
  75. data/lib/ledger_sync/resource.rb +24 -64
  76. data/lib/ledger_sync/resource_attribute.rb +50 -0
  77. data/lib/ledger_sync/resource_attribute/dirty_mixin.rb +49 -0
  78. data/lib/ledger_sync/resource_attribute/mixin.rb +90 -0
  79. data/lib/ledger_sync/resource_attribute/reference.rb +9 -0
  80. data/lib/ledger_sync/resource_attribute/reference/many.rb +34 -0
  81. data/lib/ledger_sync/resource_attribute/reference/one.rb +33 -0
  82. data/lib/ledger_sync/resource_attribute_set.rb +58 -0
  83. data/lib/ledger_sync/resources/account.rb +14 -0
  84. data/lib/ledger_sync/resources/bill.rb +17 -0
  85. data/lib/ledger_sync/resources/bill_line_item.rb +11 -0
  86. data/lib/ledger_sync/resources/customer.rb +5 -4
  87. data/lib/ledger_sync/resources/deposit.rb +16 -0
  88. data/lib/ledger_sync/resources/deposit_line_item.rb +11 -0
  89. data/lib/ledger_sync/resources/expense.rb +19 -0
  90. data/lib/ledger_sync/resources/expense_line_item.rb +11 -0
  91. data/lib/ledger_sync/resources/journal_entry.rb +13 -0
  92. data/lib/ledger_sync/resources/journal_entry_line_item.rb +12 -0
  93. data/lib/ledger_sync/resources/payment.rb +5 -3
  94. data/lib/ledger_sync/resources/transfer.rb +15 -0
  95. data/lib/ledger_sync/resources/vendor.rb +12 -0
  96. data/lib/ledger_sync/result.rb +0 -24
  97. data/lib/ledger_sync/type/boolean.rb +17 -0
  98. data/lib/ledger_sync/type/date.rb +17 -0
  99. data/lib/ledger_sync/type/float.rb +17 -0
  100. data/lib/ledger_sync/type/integer.rb +17 -0
  101. data/lib/ledger_sync/type/reference_many.rb +27 -0
  102. data/lib/ledger_sync/type/reference_one.rb +26 -0
  103. data/lib/ledger_sync/type/string.rb +17 -0
  104. data/lib/ledger_sync/type/value.rb +12 -0
  105. data/lib/ledger_sync/type/value_mixin.rb +19 -0
  106. data/lib/ledger_sync/util/hash_helpers.rb +16 -1
  107. data/lib/ledger_sync/util/resources_builder.rb +36 -9
  108. data/lib/ledger_sync/version.rb +1 -1
  109. metadata +92 -7
  110. data/lib/ledger_sync/adaptors/quickbooks_online/customer/operations/upsert.rb +0 -42
  111. data/lib/ledger_sync/adaptors/quickbooks_online/payment/operations/upsert.rb +0 -53
  112. data/lib/ledger_sync/adaptors/test/customer/operations/upsert.rb +0 -42
  113. data/lib/ledger_sync/adaptors/test/payment/operations/upsert.rb +0 -53
  114. data/lib/ledger_sync/sync.rb +0 -108
  115. data/lib/ledger_sync/util/coordinator.rb +0 -72
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bd00a20c0fc0e5fa31901cbc8470e7081e629fefab4bf451408f05fdca1879c0
4
- data.tar.gz: 6302b8e87ccbf4716b31e63a68add132a80145b7758834feb89215b6210dd770
3
+ metadata.gz: 9bf08ab386468485d8e81f3e40d43ca41664d69e4a09d1e70f658e047f82295d
4
+ data.tar.gz: 69a554102281aae008333eeea328691bcc242417152e3fe6e2ddfca726a7cb7c
5
5
  SHA512:
6
- metadata.gz: 58aa1ea5129d57709a808a95ec0da2a193e3d87430c75bb72036c9e12b2b84779a7a2a2dcd82656612c3d962479baa4d17122a9eb42caff7dfd2ee0ae884c998
7
- data.tar.gz: 7919f3da5948ca70bb04fa51b0e1eea3d16ba0f81cbc20d9a94bac5aaf58fe6aa70b1d1b6bb5151bb8002db12e451c5b96d2d638b7a784d863d471cd719d5ef3
6
+ metadata.gz: ac04c1f2fc9fc9fb06443ad61a3f28e3ca102f1bd70d0c8c693549f2a9e75d83b4ad4fc10e5ed476b31038cd0190b6a077f9b3fefa02d629a15746a23e4e6647
7
+ data.tar.gz: 7b282b14b77360effae62f6b3f4c36c3f067a0d29f5bd721686c80460784943304a42c01cae1336aaf0dd6fc7803f39e63868ea38fce900150385f3b43ff969c
@@ -1,7 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ledger_sync (1.0.10)
4
+ ledger_sync (1.1.1)
5
+ activemodel
5
6
  colorize
6
7
  coveralls
7
8
  dry-schema
@@ -18,8 +19,16 @@ PATH
18
19
  GEM
19
20
  remote: https://rubygems.org/
20
21
  specs:
21
- addressable (2.6.0)
22
- public_suffix (>= 2.0.2, < 4.0)
22
+ activemodel (6.0.0)
23
+ activesupport (= 6.0.0)
24
+ activesupport (6.0.0)
25
+ concurrent-ruby (~> 1.0, >= 1.0.2)
26
+ i18n (>= 0.7, < 2)
27
+ minitest (~> 5.1)
28
+ tzinfo (~> 1.1)
29
+ zeitwerk (~> 2.1, >= 2.1.8)
30
+ addressable (2.7.0)
31
+ public_suffix (>= 2.0.2, < 5.0)
23
32
  ast (2.4.0)
24
33
  awesome_print (1.8.0)
25
34
  bump (0.8.0)
@@ -42,38 +51,38 @@ GEM
42
51
  dry-container (0.7.2)
43
52
  concurrent-ruby (~> 1.0)
44
53
  dry-configurable (~> 0.1, >= 0.1.3)
45
- dry-core (0.4.8)
54
+ dry-core (0.4.9)
46
55
  concurrent-ruby (~> 1.0)
47
56
  dry-equalizer (0.2.2)
48
- dry-inflector (0.1.2)
57
+ dry-inflector (0.2.0)
49
58
  dry-initializer (3.0.1)
50
- dry-logic (1.0.2)
59
+ dry-logic (1.0.3)
51
60
  concurrent-ruby (~> 1.0)
52
61
  dry-core (~> 0.2)
53
62
  dry-equalizer (~> 0.2)
54
- dry-schema (1.3.1)
63
+ dry-schema (1.4.1)
55
64
  concurrent-ruby (~> 1.0)
56
65
  dry-configurable (~> 0.8, >= 0.8.3)
57
66
  dry-core (~> 0.4)
58
67
  dry-equalizer (~> 0.2)
59
68
  dry-initializer (~> 3.0)
60
69
  dry-logic (~> 1.0)
61
- dry-types (~> 1.0)
62
- dry-types (1.1.1)
70
+ dry-types (~> 1.2)
71
+ dry-types (1.2.0)
63
72
  concurrent-ruby (~> 1.0)
64
73
  dry-container (~> 0.3)
65
74
  dry-core (~> 0.4, >= 0.4.4)
66
75
  dry-equalizer (~> 0.2, >= 0.2.2)
67
76
  dry-inflector (~> 0.1, >= 0.1.2)
68
77
  dry-logic (~> 1.0, >= 1.0.2)
69
- dry-validation (1.2.1)
78
+ dry-validation (1.3.1)
70
79
  concurrent-ruby (~> 1.0)
71
80
  dry-container (~> 0.7, >= 0.7.1)
72
81
  dry-core (~> 0.4)
73
82
  dry-equalizer (~> 0.2)
74
83
  dry-initializer (~> 3.0)
75
84
  dry-schema (~> 1.0, >= 1.3.1)
76
- faraday (0.15.4)
85
+ faraday (0.17.0)
77
86
  multipart-post (>= 1.2, < 3)
78
87
  faraday-detailed_logger (2.1.3)
79
88
  faraday (~> 0.8)
@@ -82,25 +91,28 @@ GEM
82
91
  fingerprintable (1.2.1)
83
92
  colorize
84
93
  hashdiff (1.0.0)
94
+ i18n (1.7.0)
95
+ concurrent-ruby (~> 1.0)
85
96
  jaro_winkler (1.5.3)
86
97
  json (2.2.0)
87
98
  jwt (2.2.1)
88
99
  mini_portile2 (2.4.0)
89
- multi_json (1.13.1)
100
+ minitest (5.12.2)
101
+ multi_json (1.14.1)
90
102
  multi_xml (0.6.0)
91
103
  multipart-post (2.1.1)
92
- nokogiri (1.10.3)
104
+ nokogiri (1.10.4)
93
105
  mini_portile2 (~> 2.4.0)
94
- oauth2 (1.4.1)
95
- faraday (>= 0.8, < 0.16.0)
106
+ oauth2 (1.4.2)
107
+ faraday (>= 0.8, < 2.0)
96
108
  jwt (>= 1.0, < 3.0)
97
109
  multi_json (~> 1.3)
98
110
  multi_xml (~> 0.5)
99
111
  rack (>= 1.2, < 3)
100
112
  parallel (1.17.0)
101
- parser (2.6.3.0)
113
+ parser (2.6.4.1)
102
114
  ast (~> 2.4.0)
103
- public_suffix (3.1.1)
115
+ public_suffix (4.0.1)
104
116
  rack (2.0.7)
105
117
  rainbow (3.0.0)
106
118
  rake (10.5.0)
@@ -118,7 +130,7 @@ GEM
118
130
  diff-lcs (>= 1.2.0, < 2.0)
119
131
  rspec-support (~> 3.8.0)
120
132
  rspec-support (3.8.2)
121
- rubocop (0.73.0)
133
+ rubocop (0.74.0)
122
134
  jaro_winkler (~> 1.5.1)
123
135
  parallel (~> 1.10)
124
136
  parser (>= 2.6)
@@ -132,18 +144,22 @@ GEM
132
144
  json (>= 1.8, < 3)
133
145
  simplecov-html (~> 0.10.0)
134
146
  simplecov-html (0.10.2)
135
- simply_serializable (1.3.0)
147
+ simply_serializable (1.4.2)
136
148
  fingerprintable (>= 1.2.1)
137
149
  term-ansicolor (1.7.1)
138
150
  tins (~> 1.0)
139
151
  thor (0.20.3)
152
+ thread_safe (0.3.6)
140
153
  tins (1.21.1)
154
+ tzinfo (1.2.5)
155
+ thread_safe (~> 0.1)
141
156
  unicode-display_width (1.6.0)
142
157
  vcr (5.0.0)
143
- webmock (3.6.0)
158
+ webmock (3.7.5)
144
159
  addressable (>= 2.3.6)
145
160
  crack (>= 0.3.2)
146
161
  hashdiff (>= 0.4.0, < 2.0.0)
162
+ zeitwerk (2.2.0)
147
163
 
148
164
  PLATFORMS
149
165
  ruby
data/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
  [![Gem Version](https://badge.fury.io/rb/ledger_sync.svg)](https://badge.fury.io/rb/ledger_sync)
5
5
  [![Coverage Status](https://coveralls.io/repos/github/LedgerSync/ledger_sync/badge.svg?branch=master)](https://coveralls.io/github/LedgerSync/ledger_sync?branch=master)
6
6
 
7
- # Installation
7
+ ## Installation
8
8
 
9
9
  Add this line to your application's Gemfile:
10
10
 
@@ -20,36 +20,69 @@ Or install it yourself as:
20
20
 
21
21
  $ gem install ledger_sync
22
22
 
23
- # Usage
23
+ ## Usage
24
24
 
25
- The easiest entry point into the library is the `Sync` class, which will handle building, validating, and performing all the necessary operations to sync an object. You can of course build and manage these primitives yourself if you require more control. Here is an example of a sync:
25
+ To use LedgerSync, you must create an `Operation`. The operation will be ledger-specific and will require the following:
26
+
27
+ 1. Adaptor
28
+ 2. Resource(s)
29
+
30
+ The code may look like the following:
26
31
 
27
32
  ```ruby
28
- sync = LedgerSync::Sync.new(
29
- adaptor: adaptor, # The adaptor for the ledger you want to use (see below)
30
- method: :upsert,
31
- resources_data: resources_data, # The structured hash of resource data (see below)
32
- resource_external_id: resource_external_id, # The root object ID on which the operation is to be performed
33
- resource_type: resource_type # The root object type on which the operation is to be performed
33
+ # First we create an adaptor, which is our connection to a ledger.
34
+ # Each ledger may require different keys, so check the
35
+ # documentation below for specifics.
36
+ adaptor = LedgerSync::Adaptors::QuickBooksOnline::Adaptor.new(
37
+ access_token: access_token, # assuming this is defined
38
+ client_id: ENV['QUICKBOOKS_ONLINE_CLIENT_ID'],
39
+ client_secret: ENV['QUICKBOOKS_ONLINE_CLIENT_SECRET'],
40
+ realm_id: ENV['QUICKBOOKS_ONLINE_REALM_ID'],
41
+ refresh_token: refresh_token, # assuming this is defined
34
42
  )
35
43
 
36
- sync.operations # Returns the ordered list of operations to be performed
44
+ # Create a resource on which to operate. Some resources have
45
+ # relationships with other resources. You can use
46
+ # `Util::ResourcesBuilder` to create resources and relationships from
47
+ # a structured hash.
48
+ resource = LedgerSync::Customer.new(
49
+ name: 'Sample Customer',
50
+ email: 'test@example.com'
51
+ )
37
52
 
38
- sync.perform # Returns a SyncResult (either ::Success or ::Failure)
39
- ```
53
+ # Create the operation we want to perform.
54
+ operation = LedgerSync::Adaptors::QuickBooksOnline::Customer::Operations::Create.new(
55
+ adaptor: adaptor,
56
+ resource: resource
57
+ )
40
58
 
41
- **NOTE: Even when not performing the sync (`sync.perform`) and just retrieving the operations (`sync.operations`), the library will make API requests to the ledger in order to determine if a `create` or `update` is necessary for each object involved.**
59
+ result = operation.perform # Returns a LedgerSync::OperationResult
60
+
61
+ if result.success?
62
+ resource = result.operation.resource
63
+ # Do something with resource
64
+ else # result.failure?
65
+ raise result.error
66
+ end
67
+
68
+ # Because QuickBooks Online uses Oauth 2, you must always be sure to
69
+ # save the access_token, refresh_token, and expirations as they can
70
+ # change with any API call.
71
+ result.operation.adaptor.ledger_attributes_to_save.each do |key, value|
72
+ # save values
73
+ end
74
+ ```
42
75
 
43
- # How it Works
76
+ ## How it Works
44
77
 
45
- ## The Library Structure
78
+ ### The Library Structure
46
79
 
47
80
  This library consists of two important layers:
48
81
 
49
82
  1. Resources
50
83
  2. Adaptors
51
84
 
52
- ### Resources
85
+ #### Resources
53
86
 
54
87
  Resources are named ruby objects (e.g. `Customer`, `Payment`, etc.) with strict attributes (e.g. `name`, `amount`, etc.). They are a layer between your application and an adaptor. They can be validated using an adaptor. You can create and use the resources, and an adaptor will update resources as needed based on the intention and outcome of that operation.
55
88
 
@@ -59,7 +92,7 @@ Resources have defined attributes. Attributes are explicitly defined. An error
59
92
 
60
93
  A subset of these `attributes` may be a `reference`, which is simply a special type of attribute that references another resource. You can retrieve the references of a resource by calling `LedgerSync::Customer.references`.
61
94
 
62
- ## Adaptors
95
+ ### Adaptors
63
96
 
64
97
  Adaptors are ledger-specific ruby objects that contain all the logic to authenticate to a ledger, perform ledger-specific operations, and validate resources based on the requirements of the ledger. Adaptors contain a number of useful objects:
65
98
 
@@ -67,31 +100,57 @@ Adaptors are ledger-specific ruby objects that contain all the logic to authenti
67
100
  - operations
68
101
  - searchers
69
102
 
70
- ### Adaptor
103
+ #### Adaptor
71
104
 
72
105
  The adaptor handles authentication and requests to the ledger. Each adaptors initializer will vary based on the needs of that ledger.
73
106
 
74
- ### Operation
107
+ #### Operation
75
108
 
76
- Each adaptor defines operations that can be performed on specific resources (e.g. `Customer::Update`, `Payment::Create`). The operation defines three key things:
109
+ Each adaptor defines operations that can be performed on specific resources (e.g. `Customer::Operations::Update`, `Payment::Operations::Create`). The operation defines two key things:
77
110
 
78
111
  - a `Contract` class which is used to validate the resource using the `dry-validation` gem
79
- - a `build` instance method, which handles any pre-processing to be done before the operation is performed (e.g. converting an `Upsert` into a `Create` or `Update`)
80
112
  - a `perform` instance method, which handles the actual API requests and response/error handling.
81
113
 
82
114
  Note: Adaptors may support different operations for each resource type.
83
115
 
84
- ### Searcher
116
+ #### Searcher
117
+
118
+ Searchers are used to search objects in the ledger. A searcher takes an `adaptor`, `query` string and optional `pagination` hash. For example, to search customer's by name:
119
+
120
+ ```ruby
121
+ searcher = LedgerSync::Adaptors::QuickBooksOnline::Customer::Searcher.new(
122
+ adaptor: adaptor # assuming this is defined,
123
+ query: 'test'
124
+ )
125
+
126
+ result = searcher.search # returns a LedgerSync::SearchResult
127
+
128
+ if result.success?
129
+ resources = result.resources
130
+ # Do something with found resources
131
+ else # result.failure?
132
+ raise result.error
133
+ end
85
134
 
86
- Searchers are a classes that make it easy to search objects in the ledger. A searcher takes an `adaptor`, `query` string and optional `pagination` hash.
135
+ # Different ledgers may use different pagination strategies. In order
136
+ # to get the next and previous set of results, you can use the following:
137
+ next_searcher = searcher.next_searcher
138
+ previous_searcher = searcher.previous_searcher
139
+ ```
140
+
141
+ ## QuickBooks Online
87
142
 
88
- # Tips and More!
143
+ ### Errors
144
+
145
+ https://developer.intuit.com/app/developer/qbo/docs/develop/troubleshooting/error-codes
89
146
 
90
- ## Keywords
147
+ ## Tips and More!
91
148
 
92
- LedgerSync heavily uses ruby keywords so as to make it clear what values are being passed and which attributes are required. When this README says something like "the `fun_function` function takes the argument `foo`" that translates to `fun_function(foo: :some_value)`.
149
+ ### Keyword Arguments
93
150
 
94
- ## Fingerprints
151
+ LedgerSync heavily uses ruby keyword arguments so as to make it clear what values are being passed and which attributes are required. When this README says something like "the `fun_function` function takes the argument `foo`" that translates to `fun_function(foo: :some_value)`.
152
+
153
+ ### Fingerprints
95
154
 
96
155
  Most objects in LedgerSync can be fingerprinted by calling the instance method `fingerprint`. For example:
97
156
 
@@ -105,7 +164,7 @@ puts LedgerSync::Customer.new.fingerprint == LedgerSync::Payment.new.fingerprint
105
164
 
106
165
  Fingerprints are used to compare objects. This method is used in de-duping objects, as it only considers the data inside and not the instance itself (as shown above).
107
166
 
108
- ## Serialization
167
+ ### Serialization
109
168
 
110
169
  Most objects in LedgerSync can be serialized by calling the instance method `serialize`. For example:
111
170
 
@@ -150,7 +209,7 @@ puts LedgerSync::Payment.new(
150
209
  }
151
210
  ```
152
211
 
153
- The serialization of any object follows the same struction. There is a `:root` key that holds the ID of the root object. There is also an `:objects` hash that contains all of the objects for this serialization. As you can see, unique nested objects listed in the `:objects` hash and referenced using a "reference object", in this case:
212
+ The serialization of any object follows the same structure. There is a `:root` key that holds the ID of the root object. There is also an `:objects` hash that contains all of the objects for this serialization. As you can see, unique nested objects listed in the `:objects` hash and referenced using a "reference object", in this case:
154
213
 
155
214
  ```ruby
156
215
  {
@@ -159,32 +218,27 @@ The serialization of any object follows the same struction. There is a `:root`
159
218
  }
160
219
  ```
161
220
 
162
- # Testing
221
+ ## Testing
163
222
 
164
- LedgerSync offers a test adaptor `LedgerSync::Adaptors::Test` that you can easily use and stub without requiring API requests. For example:
223
+ LedgerSync offers a test adaptor `LedgerSync::Adaptors::Test::Adaptor` that you can easily use and stub without requiring API requests. For example:
165
224
 
166
225
  ```ruby
167
- resources_data = {
168
- {
169
- customer: {
170
- 'cus_1': {
171
- name: 'Jane Doe'
172
- }
173
- }
174
- }
175
- }
176
- sync = LedgerSync::Sync.new(
177
- adaptor: LedgerSync::Adaptors::Test.new,
178
- method: :upsert,
179
- resources_data: resources_data,
180
- resource_external_id: 'cus_1',
181
- resource_type: :customer
226
+
227
+ operation = LedgerSync::Adaptors::Test::Customer::Operations::Create.new(
228
+ adaptor: LedgerSync::Adaptors::Test::Adaptor.new,
229
+ resource: LedgerSync::Customer.new(name: 'Test Customer')
182
230
  )
183
231
 
184
- expect(sync.perform).to be_a(LedgerSync::SyncResult::Success)
232
+ expect(operation).to be_valid
233
+
234
+ result = operation.perform
235
+ expect(result).to be_a(LedgerSync::OperationResult::Success)
236
+ expect(result).to be_success
237
+
238
+ expect { operation.perform }.to raise_error(PerformedOperationError)
185
239
  ```
186
240
 
187
- # Development
241
+ ## Development
188
242
 
189
243
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
190
244
 
@@ -192,29 +246,14 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
192
246
 
193
247
  Run `bundle console` to start and interactive console with the library already loaded.
194
248
 
195
- ### Adding an Adaptor
196
-
197
- ## Errors
198
-
199
- https://developer.intuit.com/app/developer/qbo/docs/develop/troubleshooting/error-codes
200
-
201
- #### Directory Structure
202
-
203
- /quickbooks_online/
204
- adaptor.rb
205
- operations/
206
- customer/
207
- operation.rb
208
-
209
-
210
- ## Contributing
249
+ ### Contributing
211
250
 
212
251
  Bug reports and pull requests are welcome on GitHub at https://github.com/LedgerSync/ledger_sync. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
213
252
 
214
- ## License
253
+ ### License
215
254
 
216
255
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
217
256
 
218
- ## Code of Conduct
257
+ ### Code of Conduct
219
258
 
220
259
  Everyone interacting in the LedgerSync project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/LedgerSync/ledger_sync/blob/master/CODE_OF_CONDUCT.md).
@@ -36,6 +36,7 @@ Gem::Specification.new do |spec|
36
36
  spec.add_development_dependency('rubocop', '>= 0')
37
37
  spec.add_development_dependency('vcr', '>= 0')
38
38
  spec.add_development_dependency('webmock', '>= 0')
39
+ spec.add_runtime_dependency('activemodel', '>= 0')
39
40
  spec.add_runtime_dependency('colorize', '>= 0')
40
41
  spec.add_runtime_dependency('coveralls')
41
42
  spec.add_runtime_dependency('dry-schema')
@@ -9,6 +9,7 @@ require 'uri'
9
9
  require 'colorize'
10
10
  require 'fingerprintable'
11
11
  require 'simply_serializable'
12
+ require 'active_model'
12
13
 
13
14
  # Version
14
15
  require 'ledger_sync/version'
@@ -29,7 +30,6 @@ require 'ledger_sync/util/hash_helpers'
29
30
  require 'ledger_sync/util/resources_builder'
30
31
  require 'ledger_sync/adaptor_configuration'
31
32
  require 'ledger_sync/adaptor_configuration_store'
32
- require 'ledger_sync/util/coordinator'
33
33
  require 'ledger_sync/util/performer'
34
34
  require 'ledger_sync/util/validator'
35
35
  require 'ledger_sync/util/string_helpers'
@@ -39,11 +39,19 @@ require 'ledger_sync/adaptors/contract'
39
39
 
40
40
  # Resources (resources are registerd below)
41
41
  require 'ledger_sync/resource' # Template class
42
+ require 'ledger_sync/resources/account'
42
43
  require 'ledger_sync/resources/customer'
44
+ require 'ledger_sync/resources/vendor'
43
45
  require 'ledger_sync/resources/payment'
44
-
45
- # Synchronizer
46
- require 'ledger_sync/sync'
46
+ require 'ledger_sync/resources/expense_line_item'
47
+ require 'ledger_sync/resources/expense'
48
+ require 'ledger_sync/resources/deposit_line_item'
49
+ require 'ledger_sync/resources/deposit'
50
+ require 'ledger_sync/resources/transfer'
51
+ require 'ledger_sync/resources/bill_line_item'
52
+ require 'ledger_sync/resources/bill'
53
+ require 'ledger_sync/resources/journal_entry_line_item'
54
+ require 'ledger_sync/resources/journal_entry'
47
55
 
48
56
  module LedgerSync
49
57
  @log_level = nil
@@ -106,5 +114,16 @@ end
106
114
  Gem.find_files('ledger_sync/adaptors/**/config.rb').each { |path| require path }
107
115
 
108
116
  # Register Resources
117
+ LedgerSync.register_resource(resource: LedgerSync::Account)
109
118
  LedgerSync.register_resource(resource: LedgerSync::Customer)
119
+ LedgerSync.register_resource(resource: LedgerSync::Vendor)
110
120
  LedgerSync.register_resource(resource: LedgerSync::Payment)
121
+ LedgerSync.register_resource(resource: LedgerSync::ExpenseLineItem)
122
+ LedgerSync.register_resource(resource: LedgerSync::Expense)
123
+ LedgerSync.register_resource(resource: LedgerSync::DepositLineItem)
124
+ LedgerSync.register_resource(resource: LedgerSync::Deposit)
125
+ LedgerSync.register_resource(resource: LedgerSync::Transfer)
126
+ LedgerSync.register_resource(resource: LedgerSync::BillLineItem)
127
+ LedgerSync.register_resource(resource: LedgerSync::Bill)
128
+ LedgerSync.register_resource(resource: LedgerSync::JournalEntryLineItem)
129
+ LedgerSync.register_resource(resource: LedgerSync::JournalEntry)