Class: LedgerSync::NetSuite::Searcher
- Inherits:
-
Ledgers::Searcher
- Object
- Ledgers::Searcher
- LedgerSync::NetSuite::Searcher
show all
- Includes:
- Ledgers::Mixins::OffsetAndLimitPaginationSearcherMixin
- Defined in:
- lib/ledger_sync/netsuite/searcher.rb
Instance Method Summary
collapse
Instance Method Details
#query_attributes ⇒ Object
8
9
10
|
# File 'lib/ledger_sync/netsuite/searcher.rb', line 8
def query_attributes
@query_attributes ||= searcher_deserializer_class.attributes.values.map(&:hash_attribute)
end
|
#query_string ⇒ Object
12
13
14
15
16
|
# File 'lib/ledger_sync/netsuite/searcher.rb', line 12
def query_string
ret = "SELECT #{query_attributes.join(', ')} FROM #{query_table}"
ret += " WHERE #{query}" if query.present?
ret
end
|
#query_table ⇒ Object
18
19
20
|
# File 'lib/ledger_sync/netsuite/searcher.rb', line 18
def query_table
@query_table ||= client.class.ledger_resource_type_for(resource_class: self.class.inferred_resource_class)
end
|
#request_url ⇒ Object
22
23
24
|
# File 'lib/ledger_sync/netsuite/searcher.rb', line 22
def request_url
client.api_base_url.gsub('/record/v1', '') + "/query/v1/suiteql?limit=#{limit}&offset=#{offset}"
end
|
#resources ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/ledger_sync/netsuite/searcher.rb', line 26
def resources
resource_class = self.class.inferred_resource_class
@resources ||= begin
@request = client
.post(
body: { q: query_string.to_s },
request_url: request_url
)
case request.status
when 200
request.body
.fetch('items')
.map do |c|
searcher_deserializer_class.new.deserialize(hash: c, resource: resource_class.new)
end
when 404
[]
when 400
if request.body['title'].include?(
'Invalid search query Search error occurred: Record ‘subsidiary’ was not found'
)
raise LedgerSync::NetSuite::Error::SubsidiariesNotEnabled
end
end
end
end
|
#searcher_deserializer_class ⇒ Object
55
56
57
|
# File 'lib/ledger_sync/netsuite/searcher.rb', line 55
def searcher_deserializer_class
@searcher_deserializer_class ||= self.class.inferred_serialization_class(type: 'SearcherDeserializer')
end
|