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.
Files changed (216) hide show
  1. checksums.yaml +4 -4
  2. data/.env.template +25 -0
  3. data/.gitignore +3 -1
  4. data/.rubocop_todo.yml +4 -1
  5. data/.travis.yml +1 -1
  6. data/Gemfile.lock +59 -25
  7. data/README.md +160 -8
  8. data/_config.yml +1 -0
  9. data/bin/qa +3 -0
  10. data/ledger_sync.gemspec +4 -0
  11. data/lib/ledger_sync.rb +40 -30
  12. data/lib/ledger_sync/adaptor_configuration.rb +17 -11
  13. data/lib/ledger_sync/adaptor_configuration_store.rb +13 -9
  14. data/lib/ledger_sync/adaptors/adaptor.rb +9 -1
  15. data/lib/ledger_sync/adaptors/ledger_serializer.rb +3 -6
  16. data/lib/ledger_sync/adaptors/ledger_serializer_attribute_set.rb +1 -1
  17. data/lib/ledger_sync/adaptors/ledger_serializer_type/references_many_type.rb +1 -1
  18. data/lib/ledger_sync/adaptors/mixins/infer_adaptor_class_mixin.rb +24 -0
  19. data/lib/ledger_sync/adaptors/mixins/infer_ledger_serializer_mixin.rb +31 -0
  20. data/lib/ledger_sync/adaptors/mixins/infer_resource_class_mixin.rb +22 -0
  21. data/lib/ledger_sync/adaptors/mixins/offset_and_limit_pagination_searcher_mixin.rb +37 -0
  22. data/lib/ledger_sync/adaptors/netsuite/account/ledger_deserializer.rb +24 -0
  23. data/lib/ledger_sync/adaptors/netsuite/account/ledger_serializer.rb +22 -0
  24. data/lib/ledger_sync/adaptors/netsuite/account/operations/create.rb +28 -0
  25. data/lib/ledger_sync/adaptors/netsuite/account/operations/find.rb +28 -0
  26. data/lib/ledger_sync/adaptors/netsuite/account/searcher.rb +28 -0
  27. data/lib/ledger_sync/adaptors/netsuite/adaptor.rb +145 -0
  28. data/lib/ledger_sync/adaptors/netsuite/config.rb +6 -0
  29. data/lib/ledger_sync/adaptors/netsuite/currency/deledger_serializer.rb +28 -0
  30. data/lib/ledger_sync/adaptors/netsuite/currency/ledger_serializer.rb +25 -0
  31. data/lib/ledger_sync/adaptors/netsuite/currency/operations/create.rb +25 -0
  32. data/lib/ledger_sync/adaptors/netsuite/currency/operations/delete.rb +23 -0
  33. data/lib/ledger_sync/adaptors/netsuite/currency/operations/find.rb +23 -0
  34. data/lib/ledger_sync/adaptors/netsuite/currency/operations/update.rb +23 -0
  35. data/lib/ledger_sync/adaptors/netsuite/customer/ledger_deserializer.rb +27 -0
  36. data/lib/ledger_sync/adaptors/netsuite/customer/ledger_serializer.rb +38 -0
  37. data/lib/ledger_sync/adaptors/netsuite/customer/operations/create.rb +24 -0
  38. data/lib/ledger_sync/adaptors/netsuite/customer/operations/delete.rb +24 -0
  39. data/lib/ledger_sync/adaptors/netsuite/customer/operations/find.rb +24 -0
  40. data/lib/ledger_sync/adaptors/netsuite/customer/operations/update.rb +24 -0
  41. data/lib/ledger_sync/adaptors/netsuite/ledger_serializer.rb +30 -0
  42. data/lib/ledger_sync/adaptors/netsuite/ledger_serializer_type/reference_type.rb +24 -0
  43. data/lib/ledger_sync/adaptors/netsuite/ledger_serializer_type/subsidiary_type.rb +22 -0
  44. data/lib/ledger_sync/adaptors/netsuite/operation.rb +25 -0
  45. data/lib/ledger_sync/adaptors/netsuite/operation/create.rb +65 -0
  46. data/lib/ledger_sync/adaptors/netsuite/operation/delete.rb +49 -0
  47. data/lib/ledger_sync/adaptors/netsuite/operation/find.rb +56 -0
  48. data/lib/ledger_sync/adaptors/netsuite/operation/update.rb +68 -0
  49. data/lib/ledger_sync/adaptors/netsuite/record/http_method.rb +38 -0
  50. data/lib/ledger_sync/adaptors/netsuite/record/metadata.rb +75 -0
  51. data/lib/ledger_sync/adaptors/netsuite/record/property.rb +45 -0
  52. data/lib/ledger_sync/adaptors/netsuite/searcher.rb +17 -0
  53. data/lib/ledger_sync/adaptors/netsuite/token.rb +162 -0
  54. data/lib/ledger_sync/adaptors/netsuite/vendor/ledger_deserializer.rb +32 -0
  55. data/lib/ledger_sync/adaptors/netsuite/vendor/ledger_serializer.rb +35 -0
  56. data/lib/ledger_sync/adaptors/netsuite/vendor/operations/create.rb +27 -0
  57. data/lib/ledger_sync/adaptors/netsuite/vendor/operations/delete.rb +27 -0
  58. data/lib/ledger_sync/adaptors/netsuite/vendor/operations/find.rb +27 -0
  59. data/lib/ledger_sync/adaptors/netsuite/vendor/operations/update.rb +27 -0
  60. data/lib/ledger_sync/adaptors/netsuite_soap/adaptor.rb +92 -0
  61. data/lib/ledger_sync/adaptors/netsuite_soap/config.rb +5 -0
  62. data/lib/ledger_sync/adaptors/netsuite_soap/customer/ledger_serializer.rb +13 -0
  63. data/lib/ledger_sync/adaptors/netsuite_soap/customer/operations/create.rb +64 -0
  64. data/lib/ledger_sync/adaptors/netsuite_soap/customer/operations/find.rb +49 -0
  65. data/lib/ledger_sync/adaptors/netsuite_soap/ledger_serializer.rb +25 -0
  66. data/lib/ledger_sync/adaptors/netsuite_soap/operation.rb +40 -0
  67. data/lib/ledger_sync/adaptors/netsuite_soap/operation/create.rb +29 -0
  68. data/lib/ledger_sync/adaptors/netsuite_soap/operation/find.rb +15 -0
  69. data/lib/ledger_sync/adaptors/netsuite_soap/subsidiary/operations/create.rb +42 -0
  70. data/lib/ledger_sync/adaptors/netsuite_soap/subsidiary/operations/find.rb +38 -0
  71. data/lib/ledger_sync/adaptors/operation.rb +7 -11
  72. data/lib/ledger_sync/adaptors/quickbooks_online/account/searcher.rb +2 -13
  73. data/lib/ledger_sync/adaptors/quickbooks_online/adaptor.rb +158 -109
  74. data/lib/ledger_sync/adaptors/quickbooks_online/bill/searcher.rb +1 -15
  75. data/lib/ledger_sync/adaptors/quickbooks_online/config.rb +3 -2
  76. data/lib/ledger_sync/adaptors/quickbooks_online/customer/operations/create.rb +1 -0
  77. data/lib/ledger_sync/adaptors/quickbooks_online/customer/operations/find.rb +1 -0
  78. data/lib/ledger_sync/adaptors/quickbooks_online/customer/operations/update.rb +1 -0
  79. data/lib/ledger_sync/adaptors/quickbooks_online/customer/searcher.rb +2 -16
  80. data/lib/ledger_sync/adaptors/quickbooks_online/dashboard_url_helper.rb +57 -0
  81. data/lib/ledger_sync/adaptors/quickbooks_online/department/ledger_serializer.rb +38 -0
  82. data/lib/ledger_sync/adaptors/quickbooks_online/department/operations/create.rb +23 -0
  83. data/lib/ledger_sync/adaptors/quickbooks_online/department/operations/find.rb +23 -0
  84. data/lib/ledger_sync/adaptors/quickbooks_online/department/operations/update.rb +25 -0
  85. data/lib/ledger_sync/adaptors/quickbooks_online/department/searcher.rb +17 -0
  86. data/lib/ledger_sync/adaptors/quickbooks_online/deposit/ledger_serializer.rb +3 -0
  87. data/lib/ledger_sync/adaptors/quickbooks_online/deposit/operations/create.rb +1 -0
  88. data/lib/ledger_sync/adaptors/quickbooks_online/deposit/operations/find.rb +1 -0
  89. data/lib/ledger_sync/adaptors/quickbooks_online/deposit/operations/update.rb +1 -0
  90. data/lib/ledger_sync/adaptors/quickbooks_online/deposit/searcher.rb +0 -15
  91. data/lib/ledger_sync/adaptors/quickbooks_online/expense/ledger_serializer.rb +0 -2
  92. data/lib/ledger_sync/adaptors/quickbooks_online/expense/searcher.rb +1 -15
  93. data/lib/ledger_sync/adaptors/quickbooks_online/invoice/ledger_serializer.rb +35 -0
  94. data/lib/ledger_sync/adaptors/quickbooks_online/invoice/operations/create.rb +27 -0
  95. data/lib/ledger_sync/adaptors/quickbooks_online/invoice/operations/find.rb +25 -0
  96. data/lib/ledger_sync/adaptors/quickbooks_online/invoice/operations/update.rb +25 -0
  97. data/lib/ledger_sync/adaptors/quickbooks_online/invoice_sales_line_item/ledger_serializer.rb +30 -0
  98. data/lib/ledger_sync/adaptors/quickbooks_online/item/ledger_serializer.rb +13 -0
  99. data/lib/ledger_sync/adaptors/quickbooks_online/journal_entry/searcher.rb +1 -15
  100. data/lib/ledger_sync/adaptors/quickbooks_online/ledger_class/ledger_serializer.rb +25 -0
  101. data/lib/ledger_sync/adaptors/quickbooks_online/ledger_class/operations/create.rb +23 -0
  102. data/lib/ledger_sync/adaptors/quickbooks_online/ledger_class/operations/find.rb +23 -0
  103. data/lib/ledger_sync/adaptors/quickbooks_online/ledger_class/operations/update.rb +25 -0
  104. data/lib/ledger_sync/adaptors/quickbooks_online/ledger_class/searcher.rb +15 -0
  105. data/lib/ledger_sync/adaptors/quickbooks_online/ledger_serializer.rb +8 -5
  106. data/lib/ledger_sync/adaptors/quickbooks_online/ledger_serializer_type/entity_reference_type.rb +4 -14
  107. data/lib/ledger_sync/adaptors/quickbooks_online/ledger_serializer_type/transaction_reference_type.rb +49 -0
  108. data/lib/ledger_sync/adaptors/quickbooks_online/oauth_client.rb +93 -0
  109. data/lib/ledger_sync/adaptors/quickbooks_online/operation.rb +42 -7
  110. data/lib/ledger_sync/adaptors/quickbooks_online/operation/create.rb +5 -8
  111. data/lib/ledger_sync/adaptors/quickbooks_online/operation/find.rb +9 -9
  112. data/lib/ledger_sync/adaptors/quickbooks_online/operation/full_update.rb +17 -15
  113. data/lib/ledger_sync/adaptors/quickbooks_online/payment/ledger_serializer.rb +25 -0
  114. data/lib/ledger_sync/adaptors/quickbooks_online/payment/operations/create.rb +9 -6
  115. data/lib/ledger_sync/adaptors/quickbooks_online/payment/operations/find.rb +9 -2
  116. data/lib/ledger_sync/adaptors/quickbooks_online/payment/operations/update.rb +8 -1
  117. data/lib/ledger_sync/adaptors/quickbooks_online/payment_line_item/ledger_serializer.rb +19 -0
  118. data/lib/ledger_sync/adaptors/quickbooks_online/request.rb +98 -0
  119. data/lib/ledger_sync/adaptors/quickbooks_online/searcher.rb +29 -13
  120. data/lib/ledger_sync/adaptors/quickbooks_online/util/operation_error_parser.rb +1 -1
  121. data/lib/ledger_sync/adaptors/quickbooks_online/vendor/operations/create.rb +3 -0
  122. data/lib/ledger_sync/adaptors/quickbooks_online/vendor/operations/find.rb +3 -0
  123. data/lib/ledger_sync/adaptors/quickbooks_online/vendor/operations/update.rb +3 -0
  124. data/lib/ledger_sync/adaptors/quickbooks_online/vendor/searcher.rb +5 -54
  125. data/lib/ledger_sync/adaptors/quickbooks_online/webhook.rb +58 -0
  126. data/lib/ledger_sync/adaptors/quickbooks_online/webhook_event.rb +79 -0
  127. data/lib/ledger_sync/adaptors/quickbooks_online/webhook_notification.rb +42 -0
  128. data/lib/ledger_sync/adaptors/request.rb +53 -0
  129. data/lib/ledger_sync/adaptors/response.rb +55 -0
  130. data/lib/ledger_sync/adaptors/searcher.rb +3 -1
  131. data/lib/ledger_sync/adaptors/stripe/adaptor.rb +45 -0
  132. data/lib/ledger_sync/adaptors/stripe/config.rb +6 -0
  133. data/lib/ledger_sync/adaptors/stripe/customer/operations/create.rb +44 -0
  134. data/lib/ledger_sync/adaptors/stripe/customer/operations/delete.rb +35 -0
  135. data/lib/ledger_sync/adaptors/stripe/customer/operations/find.rb +44 -0
  136. data/lib/ledger_sync/adaptors/stripe/customer/operations/update.rb +43 -0
  137. data/lib/ledger_sync/adaptors/stripe/operation.rb +35 -0
  138. data/lib/ledger_sync/adaptors/stripe/operation/create.rb +17 -0
  139. data/lib/ledger_sync/adaptors/stripe/operation/delete.rb +17 -0
  140. data/lib/ledger_sync/adaptors/stripe/operation/find.rb +15 -0
  141. data/lib/ledger_sync/adaptors/stripe/operation/update.rb +17 -0
  142. data/lib/ledger_sync/adaptors/test/config.rb +0 -1
  143. data/lib/ledger_sync/adaptors/test/customer/operations/create.rb +1 -0
  144. data/lib/ledger_sync/adaptors/test/customer/operations/find.rb +1 -0
  145. data/lib/ledger_sync/adaptors/test/customer/operations/invalid.rb +1 -0
  146. data/lib/ledger_sync/adaptors/test/customer/operations/update.rb +1 -0
  147. data/lib/ledger_sync/adaptors/test/customer/operations/valid.rb +1 -0
  148. data/lib/ledger_sync/adaptors/test/payment/operations/create.rb +8 -1
  149. data/lib/ledger_sync/adaptors/test/payment/operations/find.rb +9 -2
  150. data/lib/ledger_sync/adaptors/test/payment/operations/update.rb +9 -5
  151. data/lib/ledger_sync/adaptors/test/vendor/operations/create.rb +5 -0
  152. data/lib/ledger_sync/adaptors/test/vendor/operations/find.rb +3 -0
  153. data/lib/ledger_sync/adaptors/test/vendor/operations/invalid.rb +5 -0
  154. data/lib/ledger_sync/adaptors/test/vendor/operations/update.rb +5 -0
  155. data/lib/ledger_sync/adaptors/test/vendor/operations/valid.rb +5 -0
  156. data/lib/ledger_sync/error/adaptor_errors.rb +18 -5
  157. data/lib/ledger_sync/error/operation_errors.rb +13 -4
  158. data/lib/ledger_sync/resource.rb +6 -0
  159. data/lib/ledger_sync/resource_attribute/dirty_mixin.rb +16 -15
  160. data/lib/ledger_sync/resources/bill.rb +7 -1
  161. data/lib/ledger_sync/resources/bill_line_item.rb +2 -0
  162. data/lib/ledger_sync/resources/currency.rb +9 -0
  163. data/lib/ledger_sync/resources/customer.rb +16 -0
  164. data/lib/ledger_sync/resources/department.rb +14 -0
  165. data/lib/ledger_sync/resources/deposit.rb +7 -0
  166. data/lib/ledger_sync/resources/deposit_line_item.rb +6 -0
  167. data/lib/ledger_sync/resources/expense.rb +5 -0
  168. data/lib/ledger_sync/resources/expense_line_item.rb +2 -0
  169. data/lib/ledger_sync/resources/invoice.rb +23 -0
  170. data/lib/ledger_sync/resources/invoice_sales_line_item.rb +17 -0
  171. data/lib/ledger_sync/resources/item.rb +5 -0
  172. data/lib/ledger_sync/resources/journal_entry.rb +5 -1
  173. data/lib/ledger_sync/resources/journal_entry_line_item.rb +4 -0
  174. data/lib/ledger_sync/resources/ledger_class.rb +14 -0
  175. data/lib/ledger_sync/resources/payment.rb +13 -0
  176. data/lib/ledger_sync/resources/payment_line_item.rb +15 -0
  177. data/lib/ledger_sync/resources/subsidiary.rb +8 -0
  178. data/lib/ledger_sync/resources/transfer.rb +4 -0
  179. data/lib/ledger_sync/resources/vendor.rb +9 -2
  180. data/lib/ledger_sync/type/reference_many.rb +12 -1
  181. data/lib/ledger_sync/type/reference_one.rb +1 -1
  182. data/lib/ledger_sync/util/resonad.rb +18 -0
  183. data/lib/ledger_sync/util/signer.rb +36 -0
  184. data/lib/ledger_sync/util/string_helpers.rb +12 -12
  185. data/lib/ledger_sync/version.rb +1 -1
  186. data/qa/env_spec.rb +5 -0
  187. data/qa/netsuite/account_spec.rb +20 -0
  188. data/qa/netsuite/currency_spec.rb +16 -0
  189. data/qa/netsuite/customer.rb +76 -0
  190. data/qa/netsuite/customer_spec.rb +21 -0
  191. data/qa/netsuite/vendor.rb +76 -0
  192. data/qa/netsuite/vendor_spec.rb +23 -0
  193. data/qa/netsuite_soap/customer_spec.rb +21 -0
  194. data/qa/netsuite_soap/subsidiary_spec.rb +0 -0
  195. data/qa/netsuite_test.rb +42 -0
  196. data/qa/qa_helper.rb +58 -0
  197. data/qa/quickbooks_online/account_spec.rb +14 -0
  198. data/qa/quickbooks_online/customer_spec.rb +13 -0
  199. data/qa/quickbooks_online/expense_spec.rb +31 -0
  200. data/qa/quickbooks_online/vendor_spec.rb +13 -0
  201. data/qa/stripe/customers_spec.rb +15 -0
  202. data/qa/support/adaptor_helpers.rb +99 -0
  203. data/qa/support/adaptor_support_setup.rb +23 -0
  204. data/qa/support/netsuite_helpers.rb +33 -0
  205. data/qa/support/netsuite_shared_examples.rb +30 -0
  206. data/qa/support/netsuite_soap_helpers.rb +33 -0
  207. data/qa/support/netsuite_soap_shared_examples.rb +10 -0
  208. data/qa/support/quickbooks_online_helpers.rb +42 -0
  209. data/qa/support/quickbooks_online_shared_examples.rb +82 -0
  210. data/qa/support/shared_examples.rb +127 -0
  211. data/qa/support/stripe_helpers.rb +22 -0
  212. data/qa/support/stripe_shared_examples.rb +10 -0
  213. data/qa/test.rb +67 -0
  214. data/release.sh +13 -1
  215. metadata +189 -3
  216. 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