Class: Desertcart::Searcher
- Inherits:
-
LedgerSync::Ledgers::Searcher
- Object
- LedgerSync::Ledgers::Searcher
- Desertcart::Searcher
show all
- Defined in:
- lib/desertcart/searcher.rb
Instance Method Summary
collapse
Instance Method Details
#deserialized_resource(hash:) ⇒ Object
25
26
27
28
29
30
|
# File 'lib/desertcart/searcher.rb', line 25
def deserialized_resource(hash:)
searcher_deserializer.deserialize(
hash: hash,
resource: resource_class.new
)
end
|
#ledger_namespace_path ⇒ Object
53
54
55
|
# File 'lib/desertcart/searcher.rb', line 53
def ledger_namespace_path
@ledger_namespace_path ||= nil
end
|
#ledger_resource_type ⇒ Object
64
65
66
67
68
|
# File 'lib/desertcart/searcher.rb', line 64
def ledger_resource_type
@ledger_resource_type ||= client.class.ledger_resource_type_for(
resource_class: resource_class
)
end
|
#ledger_resources_path ⇒ Object
57
58
59
60
61
62
|
# File 'lib/desertcart/searcher.rb', line 57
def ledger_resources_path
@ledger_resources_path ||= [
ledger_namespace_path,
ledger_resource_type.pluralize
].compact.join('/')
end
|
#next? ⇒ Boolean
16
17
18
19
20
21
22
23
|
# File 'lib/desertcart/searcher.rb', line 16
def next?
case response.status
when 200
response.body.dig('meta', 'pagination', 'next_page')
else
false
end
end
|
#resource_class ⇒ Object
39
40
41
|
# File 'lib/desertcart/searcher.rb', line 39
def resource_class
@resource_class ||= self.class.inferred_resource_class
end
|
#resources ⇒ Object
5
6
7
8
9
10
11
12
13
14
|
# File 'lib/desertcart/searcher.rb', line 5
def resources
case response.status
when 200
response.body
.fetch(ledger_resource_type.pluralize)
.map { |o| deserialized_resource(hash: o) }
else
[]
end
end
|
#response ⇒ Object
32
33
34
35
36
37
|
# File 'lib/desertcart/searcher.rb', line 32
def response
@response ||= client.read(
path: ledger_resources_path,
params: query
)
end
|
#searcher_deserializer ⇒ Object
49
50
51
|
# File 'lib/desertcart/searcher.rb', line 49
def searcher_deserializer
searcher_deserializer_class.new
end
|
#searcher_deserializer_class ⇒ Object
43
44
45
46
47
|
# File 'lib/desertcart/searcher.rb', line 43
def searcher_deserializer_class
@searcher_deserializer_class ||= self.class.inferred_serialization_class(
type: 'SearcherDeserializer'
)
end
|