ledger_sync-netsuite 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (140) hide show
  1. checksums.yaml +7 -0
  2. data/.env.test +14 -0
  3. data/.github/workflows/gem-workflow.yml +63 -0
  4. data/.gitignore +20 -0
  5. data/.overcommit.yml +29 -0
  6. data/.rubocop.yml +78 -0
  7. data/.rubocop_todo.yml +25 -0
  8. data/Gemfile +8 -0
  9. data/Gemfile.lock +203 -0
  10. data/README.md +19 -0
  11. data/Rakefile +8 -0
  12. data/bin/console +15 -0
  13. data/bin/setup +8 -0
  14. data/ledger_sync-netsuite.gemspec +44 -0
  15. data/lib/ledger_sync/netsuite.rb +13 -0
  16. data/lib/ledger_sync/netsuite/account/deserializer.rb +21 -0
  17. data/lib/ledger_sync/netsuite/account/operations/create.rb +26 -0
  18. data/lib/ledger_sync/netsuite/account/operations/find.rb +26 -0
  19. data/lib/ledger_sync/netsuite/account/searcher.rb +10 -0
  20. data/lib/ledger_sync/netsuite/account/searcher_deserializer.rb +27 -0
  21. data/lib/ledger_sync/netsuite/account/serializer.rb +19 -0
  22. data/lib/ledger_sync/netsuite/check/deserializer.rb +27 -0
  23. data/lib/ledger_sync/netsuite/check/operations/create.rb +25 -0
  24. data/lib/ledger_sync/netsuite/check/operations/delete.rb +25 -0
  25. data/lib/ledger_sync/netsuite/check/operations/find.rb +25 -0
  26. data/lib/ledger_sync/netsuite/check/operations/update.rb +25 -0
  27. data/lib/ledger_sync/netsuite/check/searcher.rb +13 -0
  28. data/lib/ledger_sync/netsuite/check/searcher_deserializer.rb +14 -0
  29. data/lib/ledger_sync/netsuite/check/serializer.rb +49 -0
  30. data/lib/ledger_sync/netsuite/check_line_item/deserializer.rb +16 -0
  31. data/lib/ledger_sync/netsuite/check_line_item/serializer.rb +24 -0
  32. data/lib/ledger_sync/netsuite/client.rb +186 -0
  33. data/lib/ledger_sync/netsuite/config.rb +12 -0
  34. data/lib/ledger_sync/netsuite/currency/deserializer.rb +21 -0
  35. data/lib/ledger_sync/netsuite/currency/operations/create.rb +23 -0
  36. data/lib/ledger_sync/netsuite/currency/operations/delete.rb +21 -0
  37. data/lib/ledger_sync/netsuite/currency/operations/find.rb +25 -0
  38. data/lib/ledger_sync/netsuite/currency/operations/update.rb +21 -0
  39. data/lib/ledger_sync/netsuite/currency/serializer.rb +19 -0
  40. data/lib/ledger_sync/netsuite/customer/deserializer.rb +20 -0
  41. data/lib/ledger_sync/netsuite/customer/operations/create.rb +24 -0
  42. data/lib/ledger_sync/netsuite/customer/operations/delete.rb +24 -0
  43. data/lib/ledger_sync/netsuite/customer/operations/find.rb +24 -0
  44. data/lib/ledger_sync/netsuite/customer/operations/update.rb +24 -0
  45. data/lib/ledger_sync/netsuite/customer/searcher.rb +10 -0
  46. data/lib/ledger_sync/netsuite/customer/searcher_deserializer.rb +16 -0
  47. data/lib/ledger_sync/netsuite/customer/serializer.rb +27 -0
  48. data/lib/ledger_sync/netsuite/customer_deposit/deserializer.rb +18 -0
  49. data/lib/ledger_sync/netsuite/customer_deposit/operations/create.rb +22 -0
  50. data/lib/ledger_sync/netsuite/customer_deposit/operations/delete.rb +22 -0
  51. data/lib/ledger_sync/netsuite/customer_deposit/operations/find.rb +22 -0
  52. data/lib/ledger_sync/netsuite/customer_deposit/operations/update.rb +22 -0
  53. data/lib/ledger_sync/netsuite/customer_deposit/searcher.rb +10 -0
  54. data/lib/ledger_sync/netsuite/customer_deposit/searcher_deserializer.rb +14 -0
  55. data/lib/ledger_sync/netsuite/customer_deposit/serializer.rb +23 -0
  56. data/lib/ledger_sync/netsuite/dashboard_url_helper.rb +26 -0
  57. data/lib/ledger_sync/netsuite/department/deserializer.rb +13 -0
  58. data/lib/ledger_sync/netsuite/department/operations/create.rb +23 -0
  59. data/lib/ledger_sync/netsuite/department/operations/delete.rb +23 -0
  60. data/lib/ledger_sync/netsuite/department/operations/find.rb +23 -0
  61. data/lib/ledger_sync/netsuite/department/operations/update.rb +23 -0
  62. data/lib/ledger_sync/netsuite/department/searcher.rb +10 -0
  63. data/lib/ledger_sync/netsuite/department/searcher_deserializer.rb +17 -0
  64. data/lib/ledger_sync/netsuite/department/serializer.rb +11 -0
  65. data/lib/ledger_sync/netsuite/deserializer.rb +16 -0
  66. data/lib/ledger_sync/netsuite/error.rb +17 -0
  67. data/lib/ledger_sync/netsuite/journal_entry/deserializer.rb +29 -0
  68. data/lib/ledger_sync/netsuite/journal_entry/operations/create.rb +24 -0
  69. data/lib/ledger_sync/netsuite/journal_entry/operations/delete.rb +24 -0
  70. data/lib/ledger_sync/netsuite/journal_entry/operations/find.rb +24 -0
  71. data/lib/ledger_sync/netsuite/journal_entry/operations/update.rb +28 -0
  72. data/lib/ledger_sync/netsuite/journal_entry/serializer.rb +34 -0
  73. data/lib/ledger_sync/netsuite/journal_entry_line_item/deserializer.rb +18 -0
  74. data/lib/ledger_sync/netsuite/journal_entry_line_item/serializer.rb +18 -0
  75. data/lib/ledger_sync/netsuite/ledger_class/deserializer.rb +13 -0
  76. data/lib/ledger_sync/netsuite/ledger_class/operations/create.rb +23 -0
  77. data/lib/ledger_sync/netsuite/ledger_class/operations/delete.rb +23 -0
  78. data/lib/ledger_sync/netsuite/ledger_class/operations/find.rb +23 -0
  79. data/lib/ledger_sync/netsuite/ledger_class/operations/update.rb +23 -0
  80. data/lib/ledger_sync/netsuite/ledger_class/searcher.rb +10 -0
  81. data/lib/ledger_sync/netsuite/ledger_class/searcher_deserializer.rb +17 -0
  82. data/lib/ledger_sync/netsuite/ledger_class/serializer.rb +11 -0
  83. data/lib/ledger_sync/netsuite/location/deserializer.rb +13 -0
  84. data/lib/ledger_sync/netsuite/location/operations/create.rb +19 -0
  85. data/lib/ledger_sync/netsuite/location/operations/delete.rb +19 -0
  86. data/lib/ledger_sync/netsuite/location/operations/find.rb +19 -0
  87. data/lib/ledger_sync/netsuite/location/operations/update.rb +19 -0
  88. data/lib/ledger_sync/netsuite/location/searcher.rb +10 -0
  89. data/lib/ledger_sync/netsuite/location/serializer.rb +11 -0
  90. data/lib/ledger_sync/netsuite/operation.rb +38 -0
  91. data/lib/ledger_sync/netsuite/operation/create.rb +56 -0
  92. data/lib/ledger_sync/netsuite/operation/delete.rb +47 -0
  93. data/lib/ledger_sync/netsuite/operation/find.rb +68 -0
  94. data/lib/ledger_sync/netsuite/operation/update.rb +59 -0
  95. data/lib/ledger_sync/netsuite/record/http_method.rb +31 -0
  96. data/lib/ledger_sync/netsuite/record/metadata.rb +107 -0
  97. data/lib/ledger_sync/netsuite/record/parameter.rb +18 -0
  98. data/lib/ledger_sync/netsuite/record/property.rb +20 -0
  99. data/lib/ledger_sync/netsuite/reference/serializer.rb +11 -0
  100. data/lib/ledger_sync/netsuite/resource.rb +8 -0
  101. data/lib/ledger_sync/netsuite/resources/account.rb +41 -0
  102. data/lib/ledger_sync/netsuite/resources/check.rb +21 -0
  103. data/lib/ledger_sync/netsuite/resources/check_line_item.rb +13 -0
  104. data/lib/ledger_sync/netsuite/resources/currency.rb +11 -0
  105. data/lib/ledger_sync/netsuite/resources/customer.rb +17 -0
  106. data/lib/ledger_sync/netsuite/resources/customer_deposit.rb +13 -0
  107. data/lib/ledger_sync/netsuite/resources/department.rb +14 -0
  108. data/lib/ledger_sync/netsuite/resources/deposit.rb +26 -0
  109. data/lib/ledger_sync/netsuite/resources/deposit_line_item.rb +23 -0
  110. data/lib/ledger_sync/netsuite/resources/invoice.rb +26 -0
  111. data/lib/ledger_sync/netsuite/resources/invoice_line_item.rb +19 -0
  112. data/lib/ledger_sync/netsuite/resources/item.rb +9 -0
  113. data/lib/ledger_sync/netsuite/resources/journal_entry.rb +24 -0
  114. data/lib/ledger_sync/netsuite/resources/journal_entry_line_item.rb +22 -0
  115. data/lib/ledger_sync/netsuite/resources/ledger_class.rb +14 -0
  116. data/lib/ledger_sync/netsuite/resources/location.rb +9 -0
  117. data/lib/ledger_sync/netsuite/resources/subsidiary.rb +10 -0
  118. data/lib/ledger_sync/netsuite/resources/vendor.rb +21 -0
  119. data/lib/ledger_sync/netsuite/searcher.rb +64 -0
  120. data/lib/ledger_sync/netsuite/serializer.rb +11 -0
  121. data/lib/ledger_sync/netsuite/subsidiary/deserializer.rb +15 -0
  122. data/lib/ledger_sync/netsuite/subsidiary/searcher.rb +10 -0
  123. data/lib/ledger_sync/netsuite/subsidiary/searcher_deserializer.rb +13 -0
  124. data/lib/ledger_sync/netsuite/subsidiary/serializer.rb +13 -0
  125. data/lib/ledger_sync/netsuite/token.rb +156 -0
  126. data/lib/ledger_sync/netsuite/type/deserializer_active_type.rb +30 -0
  127. data/lib/ledger_sync/netsuite/type/deserializer_customer_type.rb +33 -0
  128. data/lib/ledger_sync/netsuite/type/deserializer_entity_type.rb +28 -0
  129. data/lib/ledger_sync/netsuite/type/deserializer_subsidiary_type.rb +33 -0
  130. data/lib/ledger_sync/netsuite/vendor/deserializer.rb +28 -0
  131. data/lib/ledger_sync/netsuite/vendor/operations/create.rb +25 -0
  132. data/lib/ledger_sync/netsuite/vendor/operations/delete.rb +25 -0
  133. data/lib/ledger_sync/netsuite/vendor/operations/find.rb +25 -0
  134. data/lib/ledger_sync/netsuite/vendor/operations/update.rb +25 -0
  135. data/lib/ledger_sync/netsuite/vendor/searcher.rb +10 -0
  136. data/lib/ledger_sync/netsuite/vendor/searcher_deserializer.rb +19 -0
  137. data/lib/ledger_sync/netsuite/vendor/serializer.rb +28 -0
  138. data/lib/ledger_sync/netsuite/version.rb +17 -0
  139. data/license.txt +4 -0
  140. metadata +392 -0
@@ -0,0 +1,18 @@
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 NetSuite
8
+ class Record
9
+ class Parameter < Util::ReadOnlyObject
10
+ attribute :description
11
+ attribute :location, source: :in
12
+ attribute :name
13
+ attribute :required
14
+ attribute :schema
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,20 @@
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 NetSuite
8
+ class Record
9
+ class Property < Util::ReadOnlyObject
10
+ attribute :enum, default: nil
11
+ attribute :format, default: nil
12
+ attribute :key
13
+ attribute :nullable, default: false
14
+ attribute :read_only, default: false, source: :readOnly
15
+ attribute :title
16
+ attribute :type
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LedgerSync
4
+ module NetSuite
5
+ class Reference
6
+ class Serializer < NetSuite::Serializer
7
+ attribute :id, resource_attribute: :ledger_id
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LedgerSync
4
+ module NetSuite
5
+ class Resource < LedgerSync::Resource
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'currency'
4
+
5
+ module LedgerSync
6
+ module NetSuite
7
+ class Account < NetSuite::Resource
8
+ TYPES = {
9
+ 'bank' => 'Bank',
10
+ 'other_current_assets' => 'OthCurrAsset',
11
+ 'fixed_asset' => 'FixedAsset',
12
+ 'other_asset' => 'OthAsset',
13
+ 'accounts_receivable' => 'AcctRec',
14
+ 'equity' => 'Equity',
15
+ 'expense' => 'Expense',
16
+ 'other_expense' => 'OthExpense',
17
+ 'cost_of_goods_sold' => 'COGS',
18
+ 'accounts_payable' => 'AcctPay',
19
+ 'credit_card' => 'CredCard',
20
+ 'long_term_liability' => 'LongTermLiab',
21
+ 'other_current_liability' => 'OthCurrLiab',
22
+ 'income' => 'Income',
23
+ 'other_income' => 'OthIncome',
24
+ 'deferred_expense' => 'DeferExpense',
25
+ 'unbilled_recievable' => 'UnbilledRec',
26
+ 'deferred_revenue' => 'DeferRevenue',
27
+ 'non_posting' => 'NonPosting'
28
+ }.freeze
29
+
30
+ attribute :name, type: Type::String
31
+ attribute :classification, type: Type::String
32
+ attribute :account_type, type: Type::StringFromSet.new(values: TYPES.keys)
33
+ attribute :account_sub_type, type: Type::String
34
+ attribute :number, type: Type::String
35
+ attribute :description, type: Type::String
36
+ attribute :active, type: Type::Boolean
37
+
38
+ references_one :currency, to: Currency
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'check_line_item'
4
+ require_relative 'customer'
5
+ require_relative 'vendor'
6
+
7
+ module LedgerSync
8
+ module NetSuite
9
+ class Check < NetSuite::Resource
10
+ attribute :memo, type: Type::String
11
+ attribute :trandate, type: Type::String
12
+
13
+ references_one :account
14
+ references_one :department
15
+ references_one :entity, to: [Customer, Vendor]
16
+ references_one :currency
17
+
18
+ references_many :line_items, to: CheckLineItem
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LedgerSync
4
+ module NetSuite
5
+ class CheckLineItem < NetSuite::Resource
6
+ references_one :account
7
+ references_one :ledger_class
8
+ references_one :department
9
+ attribute :amount, type: Type::Float
10
+ attribute :memo, type: Type::String
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LedgerSync
4
+ module NetSuite
5
+ class Currency < NetSuite::Resource
6
+ attribute :exchange_rate, type: Type::Float
7
+ attribute :name, type: Type::String
8
+ attribute :symbol, type: Type::String
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'subsidiary'
4
+
5
+ module LedgerSync
6
+ module NetSuite
7
+ class Customer < NetSuite::Resource
8
+ attribute :email, type: LedgerSync::Type::String
9
+ attribute :companyName, type: LedgerSync::Type::String
10
+ attribute :firstName, type: LedgerSync::Type::String
11
+ attribute :lastName, type: LedgerSync::Type::String
12
+ attribute :phone, type: LedgerSync::Type::String
13
+
14
+ references_one :subsidiary, to: Subsidiary
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LedgerSync
4
+ module NetSuite
5
+ class CustomerDeposit < NetSuite::Resource
6
+ attribute :payment, type: Type::Float
7
+ attribute :undepFunds, type: Type::Boolean
8
+
9
+ references_one :account, to: Account
10
+ references_one :customer, to: Customer
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LedgerSync
4
+ module NetSuite
5
+ class Department < NetSuite::Resource
6
+ attribute :name, type: Type::String
7
+ attribute :fully_qualified_name, type: Type::String
8
+ attribute :active, type: Type::Boolean
9
+ attribute :sub_department, type: Type::Boolean
10
+
11
+ references_one :parent, to: Department
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'account'
4
+ require_relative 'currency'
5
+ require_relative 'department'
6
+ require_relative 'deposit_line_item'
7
+
8
+ module LedgerSync
9
+ module NetSuite
10
+ class Deposit < NetSuite::Resource
11
+ attribute :memo, type: Type::String
12
+ attribute :transaction_date, type: Type::Date
13
+ attribute :exchange_rate, type: Type::Float
14
+
15
+ references_one :account, to: Account
16
+ references_one :department, to: Department
17
+ references_one :currency, to: Currency
18
+
19
+ references_many :line_items, to: DepositLineItem
20
+
21
+ def name
22
+ "Deposit: #{currency}"
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'account'
4
+ require_relative 'customer'
5
+ require_relative 'ledger_class'
6
+ require_relative 'vendor'
7
+
8
+ module LedgerSync
9
+ module NetSuite
10
+ class DepositLineItem < NetSuite::Resource
11
+ references_one :account, to: Account
12
+ references_one :ledger_class, to: LedgerClass
13
+ attribute :amount, type: Type::Integer
14
+ attribute :description, type: Type::String
15
+
16
+ references_one :entity, to: [Customer, Vendor]
17
+
18
+ def name
19
+ description
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'account'
4
+ require_relative 'currency'
5
+ require_relative 'customer'
6
+ require_relative 'invoice_line_item'
7
+
8
+ module LedgerSync
9
+ module NetSuite
10
+ class Invoice < NetSuite::Resource
11
+ attribute :memo, type: Type::String
12
+ attribute :transaction_date, type: Type::Date
13
+ attribute :deposit, type: Type::Integer
14
+
15
+ references_one :customer, to: Customer
16
+ references_one :account, to: Account
17
+ references_one :currency, to: Currency
18
+
19
+ references_many :line_items, to: InvoiceLineItem
20
+
21
+ def name
22
+ "Invoice: #{transaction_date}"
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'item'
4
+ require_relative 'ledger_class'
5
+
6
+ module LedgerSync
7
+ module NetSuite
8
+ class InvoiceLineItem < NetSuite::Resource
9
+ references_one :item, to: Item
10
+ references_one :ledger_class, to: LedgerClass
11
+ attribute :amount, type: Type::Integer
12
+ attribute :description, type: Type::String
13
+
14
+ def name
15
+ description
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LedgerSync
4
+ module NetSuite
5
+ class Item < NetSuite::Resource
6
+ attribute :name, type: Type::String
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'currency'
4
+ require_relative 'subsidiary'
5
+ require_relative 'journal_entry_line_item'
6
+
7
+ module LedgerSync
8
+ module NetSuite
9
+ class JournalEntry < NetSuite::Resource
10
+ attribute :memo, type: Type::String
11
+ attribute :trandate, type: Type::Date
12
+ attribute :tranId, type: Type::String
13
+
14
+ references_one :currency, to: Currency
15
+ references_one :subsidiary, to: Subsidiary
16
+
17
+ references_many :line_items, to: JournalEntryLineItem
18
+
19
+ def name
20
+ "JournalEntry: #{transaction_date}"
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'account'
4
+ require_relative 'department'
5
+ require_relative 'ledger_class'
6
+
7
+ module LedgerSync
8
+ module NetSuite
9
+ class JournalEntryLineItem < NetSuite::Resource
10
+ references_one :account, to: Account
11
+ attribute :line, type: Type::Integer
12
+ attribute :credit, type: Type::Float
13
+ attribute :debit, type: Type::Float
14
+ attribute :entitytype, type: Type::String
15
+ attribute :memo, type: Type::String
16
+
17
+ def name
18
+ description
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LedgerSync
4
+ module NetSuite
5
+ class LedgerClass < NetSuite::Resource
6
+ attribute :name, type: Type::String
7
+ attribute :fully_qualified_name, type: Type::String
8
+ attribute :active, type: Type::Boolean
9
+ attribute :sub_class, type: Type::Boolean
10
+
11
+ references_one :parent, to: LedgerClass
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LedgerSync
4
+ module NetSuite
5
+ class Location < NetSuite::Resource
6
+ attribute :name, type: Type::String
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LedgerSync
4
+ module NetSuite
5
+ class Subsidiary < NetSuite::Resource
6
+ attribute :name, type: LedgerSync::Type::String
7
+ attribute :state, type: LedgerSync::Type::String
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'subsidiary'
4
+
5
+ module LedgerSync
6
+ module NetSuite
7
+ class Vendor < NetSuite::Resource
8
+ attribute :company_name, type: Type::String
9
+ attribute :email, type: Type::String
10
+ attribute :display_name, type: Type::String
11
+ attribute :first_name, type: Type::String
12
+ attribute :last_name, type: Type::String
13
+ attribute :phone_number, type: Type::String
14
+ references_one :subsidiary, to: Subsidiary
15
+
16
+ def name
17
+ display_name.to_s
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,64 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LedgerSync
4
+ module NetSuite
5
+ class Searcher < Ledgers::Searcher
6
+ include LedgerSync::Ledgers::Mixins::OffsetAndLimitPaginationSearcherMixin
7
+
8
+ def query_attributes
9
+ @query_attributes ||= searcher_deserializer_class.attributes.values.map(&:hash_attribute)
10
+ end
11
+
12
+ def query_string
13
+ "SELECT #{query_attributes.join(', ')} FROM #{query_table}"
14
+ end
15
+
16
+ def query_table
17
+ @query_table ||= client.class.ledger_resource_type_for(resource_class: self.class.inferred_resource_class)
18
+ end
19
+
20
+ def request_url
21
+ client.api_base_url.gsub('/record/v1', '') + "/query/v1/suiteql?limit=#{limit}&offset=#{offset}"
22
+ end
23
+
24
+ def resources
25
+ resource_class = self.class.inferred_resource_class
26
+
27
+ @resources ||= begin
28
+ @request = client
29
+ .post(
30
+ body: { q: query_string.to_s },
31
+ request_url: request_url
32
+ )
33
+
34
+ case request.status
35
+ when 200
36
+ request.body
37
+ .fetch('items')
38
+ .map do |c|
39
+ searcher_deserializer_class.new.deserialize(hash: c, resource: resource_class.new)
40
+ end
41
+ when 404
42
+ []
43
+ when 400
44
+ if request.body['title'].include?(
45
+ 'Invalid search query Search error occurred: Record ‘subsidiary’ was not found'
46
+ )
47
+ raise LedgerSync::NetSuite::Error::SubsidiariesNotEnabled
48
+ end
49
+ end
50
+ end
51
+ end
52
+
53
+ def searcher_deserializer_class
54
+ @searcher_deserializer_class ||= self.class.inferred_serialization_class(type: 'SearcherDeserializer')
55
+ end
56
+
57
+ private
58
+
59
+ def default_offset
60
+ 0
61
+ end
62
+ end
63
+ end
64
+ end