20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/squake/products.rb', line 20
def self.get(product_id: nil, locale: DEFAULT_LOCALE, client: Squake::Client.new, request_id: nil)
path = product_id.nil? ? ENDPOINT : "#{ENDPOINT}/#{product_id}"
result = client.call(
path: path,
method: :get,
headers: { 'X-Request-Id' => request_id }.compact,
params: {
locale: locale,
},
)
if result.success?
products = [result.body].flatten.map do |product_data|
Squake::Model::Product.from_api_response(product_data)
end
Return.new(result: products)
else
error = Squake::Errors::APIErrorResult.new(
code: :"api_error_#{result.code}",
detail: result.error_message,
)
Return.new(errors: [error])
end
end
|