lib/ledger_sync/adaptors/netsuite/searcher.rb in ledger_sync-1.3.4 vs lib/ledger_sync/adaptors/netsuite/searcher.rb in ledger_sync-1.3.5
- old
+ new
@@ -4,26 +4,48 @@
module Adaptors
module NetSuite
class Searcher < Adaptors::Searcher
include Mixins::OffsetAndLimitPaginationSearcherMixin
+ def query_attributes
+ @query_attributes ||= searcher_ledger_deserializer_class.attributes.map(&:ledger_attribute)
+ end
+
+ def query_string
+ "SELECT #{query_attributes.join(', ')} FROM #{query_table}"
+ end
+
+ def query_table
+ @query_table ||= self.class.inferred_resource_class.resource_type
+ end
+
def resources
resource_class = self.class.inferred_resource_class
@resources ||= begin
@request = adaptor
- .get(
- path: "/#{adaptor.class.ledger_resource_type_for(resource_class: resource_class)}?limit=#{limit}&offset=#{offset}"
- )
+ .post(
+ body: { q: query_string.to_s },
+ request_url: adaptor.api_base_url.gsub('/record/v1', '') + "/query/v1/suiteql?limit=#{limit}&offset=#{offset}"
+ )
- request.body
- .fetch('items')
- .map do |c|
- ledger_deserializer_class.new(
+ case request.status
+ when 200
+ request.body
+ .fetch('items')
+ .map do |c|
+ searcher_ledger_deserializer_class.new(
resource: resource_class.new
).deserialize(hash: c)
end
+ when 404
+ []
+ end
end
+ end
+
+ def searcher_ledger_deserializer_class
+ @searcher_ledger_deserializer_class ||= self.class.inferred_searcher_ledger_deserializer_class
end
private
def default_offset