ledger_sync 1.1.3 → 1.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
@@ -10,22 +10,23 @@ module LedgerSync
10
10
  end
11
11
 
12
12
  module ClassMethods
13
- def dirty_attribute(*names)
14
- names.each do |name|
15
- class_eval do
16
- attr_reader name
17
- define_attribute_methods name # From ActiveModel
18
- dirty_attributes[name] = {
19
- name: name
20
- }
13
+ # Removed as it was not being used.
14
+ # def dirty_attribute(*names)
15
+ # names.each do |name|
16
+ # class_eval do
17
+ # attr_reader name
18
+ # define_attribute_methods name # From ActiveModel
19
+ # dirty_attributes[name] = {
20
+ # name: name
21
+ # }
21
22
 
22
- define_method("#{name}=") do |val|
23
- send("#{name}_will_change!") unless val == instance_variable_get("@#{name}")
24
- instance_variable_set("@#{name}", val)
25
- end
26
- end
27
- end
28
- end
23
+ # define_method("#{name}=") do |val|
24
+ # send("#{name}_will_change!") unless val == instance_variable_get("@#{name}")
25
+ # instance_variable_set("@#{name}", val)
26
+ # end
27
+ # end
28
+ # end
29
+ # end
29
30
 
30
31
  def dirty_attributes
31
32
  @dirty_attributes ||= {}
@@ -1,3 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'account'
4
+ require_relative 'bill_line_item'
5
+ require_relative 'vendor'
6
+
1
7
  module LedgerSync
2
8
  class Bill < LedgerSync::Resource
3
9
  attribute :currency, type: Type::String
@@ -12,7 +18,7 @@ module LedgerSync
12
18
  references_many :line_items, to: BillLineItem
13
19
 
14
20
  def name
15
- "Bill: #{transaction_date.to_s}"
21
+ "Bill: #{transaction_date}"
16
22
  end
17
23
  end
18
24
  end
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative 'account'
4
+
3
5
  module LedgerSync
4
6
  class BillLineItem < LedgerSync::Resource
5
7
  references_one :account, to: Account
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LedgerSync
4
+ class Currency < LedgerSync::Resource
5
+ attribute :exchange_rate, type: Type::Float
6
+ attribute :name, type: Type::String
7
+ attribute :symbol, type: Type::String
8
+ end
9
+ end
@@ -1,9 +1,25 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative 'subsidiary'
4
+
3
5
  module LedgerSync
4
6
  class Customer < LedgerSync::Resource
5
7
  attribute :email, type: Type::String
6
8
  attribute :name, type: Type::String
7
9
  attribute :phone_number, type: Type::String
10
+
11
+ references_one :subsidiary, to: Subsidiary
12
+
13
+ def first_name
14
+ return '' if name.blank?
15
+
16
+ name.split(' ').first
17
+ end
18
+
19
+ def last_name
20
+ return '' if name.blank?
21
+
22
+ name.split(' ')[1..-1].join(' ')
23
+ end
8
24
  end
9
25
  end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'department'
4
+
5
+ module LedgerSync
6
+ class Department < LedgerSync::Resource
7
+ attribute :name, type: Type::String
8
+ attribute :fully_qualified_name, type: Type::String
9
+ attribute :active, type: Type::Boolean
10
+ attribute :sub_department, type: Type::Boolean
11
+
12
+ references_one :parent, to: Department
13
+ end
14
+ end
@@ -1,3 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'account'
4
+ require_relative 'department'
5
+ require_relative 'deposit_line_item'
6
+
1
7
  module LedgerSync
2
8
  class Deposit < LedgerSync::Resource
3
9
  attribute :currency, type: Type::String
@@ -6,6 +12,7 @@ module LedgerSync
6
12
  attribute :exchange_rate, type: Type::Float
7
13
 
8
14
  references_one :account, to: Account
15
+ references_one :department, to: Department
9
16
 
10
17
  references_many :line_items, to: DepositLineItem
11
18
 
@@ -1,3 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'account'
4
+ require_relative 'customer'
5
+ require_relative 'vendor'
6
+
1
7
  module LedgerSync
2
8
  class DepositLineItem < LedgerSync::Resource
3
9
  references_one :account, to: Account
@@ -1,5 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative 'account'
4
+ require_relative 'customer'
5
+ require_relative 'expense_line_item'
6
+ require_relative 'vendor'
7
+
3
8
  module LedgerSync
4
9
  class Expense < LedgerSync::Resource
5
10
  attribute :currency, type: Type::String
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative 'account'
4
+
3
5
  module LedgerSync
4
6
  class ExpenseLineItem < LedgerSync::Resource
5
7
  references_one :account, to: Account
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'account'
4
+ require_relative 'customer'
5
+ require_relative 'invoice_sales_line_item'
6
+
7
+ module LedgerSync
8
+ class Invoice < LedgerSync::Resource
9
+ attribute :currency, type: Type::String
10
+ attribute :memo, type: Type::String
11
+ attribute :transaction_date, type: Type::Date
12
+ attribute :deposit, type: Type::Integer
13
+
14
+ references_one :customer, to: Customer
15
+ references_one :account, to: Account
16
+
17
+ references_many :line_items, to: InvoiceSalesLineItem
18
+
19
+ def name
20
+ "Invoice: #{transaction_date}"
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'item'
4
+ require_relative 'ledger_class'
5
+
6
+ module LedgerSync
7
+ class InvoiceSalesLineItem < LedgerSync::Resource
8
+ references_one :item, to: Item
9
+ references_one :ledger_class, to: LedgerClass
10
+ attribute :amount, type: Type::Integer
11
+ attribute :description, type: Type::String
12
+
13
+ def name
14
+ description
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,5 @@
1
+ module LedgerSync
2
+ class Item < LedgerSync::Resource
3
+ attribute :name, type: Type::String
4
+ end
5
+ end
@@ -1,3 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'journal_entry_line_item'
4
+
1
5
  module LedgerSync
2
6
  class JournalEntry < LedgerSync::Resource
3
7
  attribute :currency, type: Type::String
@@ -8,7 +12,7 @@ module LedgerSync
8
12
  references_many :line_items, to: JournalEntryLineItem
9
13
 
10
14
  def name
11
- "JournalEntry: #{transaction_date.to_s}"
15
+ "JournalEntry: #{transaction_date}"
12
16
  end
13
17
  end
14
18
  end
@@ -1,3 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'account'
4
+
1
5
  module LedgerSync
2
6
  class JournalEntryLineItem < LedgerSync::Resource
3
7
  references_one :account, to: Account
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'ledger_class'
4
+
5
+ module LedgerSync
6
+ class LedgerClass < LedgerSync::Resource
7
+ attribute :name, type: Type::String
8
+ attribute :fully_qualified_name, type: Type::String
9
+ attribute :active, type: Type::Boolean
10
+ attribute :sub_class, type: Type::Boolean
11
+
12
+ references_one :parent, to: LedgerClass
13
+ end
14
+ end
@@ -1,10 +1,23 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative 'account'
4
+ require_relative 'customer'
5
+ require_relative 'payment_line_item'
6
+
3
7
  module LedgerSync
4
8
  class Payment < LedgerSync::Resource
5
9
  attribute :amount, type: Type::Integer
6
10
  attribute :currency, type: Type::String
11
+ attribute :memo, type: Type::String
12
+ attribute :transaction_date, type: Type::Date
13
+ attribute :exchange_rate, type: Type::Float
14
+ attribute :reference_number, type: Type::String
15
+
7
16
  references_one :customer, to: Customer
17
+ references_one :deposit_account, to: Account
18
+ references_one :account, to: Account
19
+
20
+ references_many :line_items, to: PaymentLineItem
8
21
 
9
22
  def name
10
23
  "Payment: #{amount} #{currency}"
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'invoice'
4
+
5
+ module LedgerSync
6
+ class PaymentLineItem < LedgerSync::Resource
7
+ attribute :amount, type: Type::Integer
8
+
9
+ references_many :ledger_transactions, to: [Invoice]
10
+
11
+ def name
12
+ amount
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LedgerSync
4
+ class Subsidiary < LedgerSync::Resource
5
+ attribute :name, type: Type::String
6
+ attribute :state, type: Type::String
7
+ end
8
+ end
@@ -1,3 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'account'
4
+
1
5
  module LedgerSync
2
6
  class Transfer < LedgerSync::Resource
3
7
  attribute :currency, type: Type::String
@@ -1,12 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'subsidiary'
4
+
1
5
  module LedgerSync
2
6
  class Vendor < LedgerSync::Resource
7
+ attribute :company_name, type: Type::String
3
8
  attribute :email, type: Type::String
9
+ attribute :display_name, type: Type::String
4
10
  attribute :first_name, type: Type::String
5
11
  attribute :last_name, type: Type::String
6
- attribute :display_name, type: Type::String
12
+ attribute :phone_number, type: Type::String
13
+ references_one :subsidiary, to: Subsidiary
7
14
 
8
15
  def name
9
- "#{display_name}"
16
+ display_name.to_s
10
17
  end
11
18
  end
12
19
  end
@@ -25,8 +25,19 @@ module LedgerSync
25
25
 
26
26
  def valid_without_casting?(value:)
27
27
  return false unless value.is_a?(Array)
28
+ return true if (resource_classes & value.map(&:class)).any?
29
+ return true if value.is_a?(Array) && value.empty?
28
30
 
29
- value.reject { |e| e.is_a?(resource_class) }.empty?
31
+ false
32
+ end
33
+ private
34
+
35
+ def resource_classes
36
+ @resource_classes ||= if resource_class.is_a?(Array)
37
+ resource_class
38
+ else
39
+ [resource_class]
40
+ end
30
41
  end
31
42
  end
32
43
  end
@@ -16,7 +16,7 @@ module LedgerSync
16
16
  if resource_class.is_a?(Array)
17
17
  "Attribute #{attribute.name} for #{resource.class.name} should be one of the following: #{resource_class.map(&:name).join(', ')}. Given #{value.class.name}"
18
18
  else
19
- "Attribute #{attribute.name} for #{resource.class.name} should be a #{resource_class.first.name}. Given #{value.class.name}"
19
+ "Attribute #{attribute.name} for #{resource.class.name} should be a #{resource_class.name}. Given #{value.class.name}"
20
20
  end
21
21
  end
22
22
 
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ #
4
+ # Extend the Resonad gem to offer method to raise errors directly
5
+ #
6
+ class Resonad
7
+ class Success
8
+ def raise_if_error
9
+ self
10
+ end
11
+ end
12
+
13
+ class Failure
14
+ def raise_if_error
15
+ raise error
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LedgerSync
4
+ module Util
5
+ class Signer
6
+ HMAC_SHA1_DIGEST = OpenSSL::Digest.new('sha1')
7
+ HMAC_SHA256_DIGEST = OpenSSL::Digest.new('sha256')
8
+
9
+ attr_reader :str
10
+
11
+ def initialize(str:)
12
+ @str = str
13
+ end
14
+
15
+ def hmac_sha1(escape: false, key:)
16
+ ret = Base64.encode64(OpenSSL::HMAC.digest(HMAC_SHA1_DIGEST, key, str)).strip
17
+ ret = self.class.escape(str: ret) if escape
18
+ ret
19
+ end
20
+
21
+ def hmac_sha256(escape: false, key:)
22
+ ret = Base64.encode64(OpenSSL::HMAC.digest(HMAC_SHA256_DIGEST, key, str)).strip
23
+ ret = self.class.escape(str: ret) if escape
24
+ ret
25
+ end
26
+
27
+ def self.escape(str:)
28
+ CGI.escape(str).gsub(/\+/, '%20')
29
+ end
30
+
31
+ def self.unescape(str:)
32
+ CGI.unescape(str.gsub(/%20/, '+'))
33
+ end
34
+ end
35
+ end
36
+ end
@@ -1,17 +1,14 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module LedgerSync
2
4
  module Util
3
5
  module StringHelpers
4
- extend self
6
+ module_function
5
7
 
6
8
  def camelcase(str)
7
- str.to_s.split('/').map { |e| e.split('_').collect(&:capitalize).map(&method(:inflect)).join }.join('::')
9
+ str.to_s.split('/').map { |e| inflect(e.split('_').collect(&:capitalize).join) }.join('::')
8
10
  end
9
11
 
10
- # def underscore!(str)
11
- # str.gsub!(/(.)([A-Z])/, '\1_\2')
12
- # str.downcase!
13
- # end
14
-
15
12
  def underscore!(str)
16
13
  str.gsub!(/::/, '/')
17
14
  str.gsub!(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
@@ -25,12 +22,15 @@ module LedgerSync
25
22
  end
26
23
 
27
24
  def inflect(str)
28
- case str.downcase
29
- when 'quickbooks'
30
- 'QuickBooks'
31
- else
32
- str
25
+ return str unless LedgerSync.respond_to?(:adaptors)
26
+
27
+ LedgerSync.adaptors.inflections.each do |inflection|
28
+ next unless inflection.downcase == str.downcase
29
+
30
+ return inflection
33
31
  end
32
+
33
+ str
34
34
  end
35
35
  end
36
36
  end