lib/wolf_core/application/integrations/orders_api_operations.rb
module WolfCore
module Integrations
module OrdersApiOperations
include WolfCore::HttpOperations
def fetch_orders!(wolf_token:, tenant:, query:, wolf_platform_url:, error_message:, error_data: nil)
response = fetch_orders(
wolf_token: wolf_token, tenant: tenant, query: query,
wolf_platform_url: wolf_platform_url,
)
validate_http_response(response: response, message: error_message, error_data: error_data)
response_body = response.body
response_body.dig("data", "table")
end
def fetch_orders(wolf_token:, tenant:, query:, wolf_platform_url:)
query ||= {}
query = query.merge({ tenant: tenant })
parsed_http_get(
headers: { 'Authorization' => "Bearer #{wolf_token}" },
url: "#{wolf_platform_url}/api/v2/orders",
query: query,
)
end
def fetch_order!(wolf_token:, order_id:, tenant:, wolf_platform_url:, error_message:)
response = safe_http_get(
headers: { "Authorization" => "Bearer #{wolf_token}" },
url: "#{wolf_platform_url}/api/v2/orders/#{order_id}",
query: { tenant: tenant },
error_message: error_message
)
response_body = response.body
response_body.dig("data", "table", "order")
end
def fetch_order(wolf_token:, order_id:, tenant:, wolf_platform_url:)
parsed_http_get(
headers: { "Authorization" => "Bearer #{wolf_token}" },
url: "#{wolf_platform_url}/api/v2/orders/#{order_id}",
query: { tenant: tenant }
)
end
def create_order!(wolf_token:, order:, tenant:, wolf_platform_url:, error_message:)
safe_http_post(
headers: { "Authorization" => "Bearer #{wolf_token}" },
url: "#{wolf_platform_url}/api/v2/orders",
query: { tenant: tenant },
body: order,
error_message: error_message
)
end
def create_order(wolf_token:, order:, tenant:, wolf_platform_url:)
parsed_http_post(
headers: { "Authorization" => "Bearer #{wolf_token}" },
url: "#{wolf_platform_url}/api/v2/orders",
query: { tenant: tenant },
body: order
)
end
end
end
end