Current section
Files
Jump to
Current section
Files
lib/quote_api_wrapper.ex
defmodule QuoteApiWrapper do
@moduledoc """
Documentation for QuoteApiWrapper
"""
require Logger
@http_client Application.get_env(:portal_api_wrapper, :quote_http_client)
@quote_api_url Application.get_env(:portal_api_wrapper, :quote_api_url)
@doc """
Request that a bucket be quoted
- `config` is a map with metadata
- `payload` is a map with data (depends on bucket type)
returns one of:
- {:ok, result} where result is a string
- {:error, code: code} response had non 200 code
- {:error, _} request failed, no response
Quote needs:
%{
quoteId: "id_of_bucket",
type: int, #(0 = address, 1 = ip, 2 = zip, 3 = digital canvas)
callbackURI: "string", # (The endpoint that we have to receive quotes)
s3_location: %{
s3_bucket: "string", (S3 Bucket where file is located)
s3_key: "string", (S3 Key where file is located)
},
columns: %{
address_1: int,
city: int,
state: int,
zip: int
}
}
"""
def init_quote(config, payload, token \\ "") do
url = "#{@quote_api_url}/quotes"
body = config
|> Map.merge(payload)
|> Poison.encode!
with {:ok, %{body: body, status_code: 202}} <- @http_client.post(url, body, "Bearer Token") do
{:ok, body}
else
{:ok, %{status_code: code, body: body}} ->
Logger.error("Error: init_quote of #{body} failed with #{code}")
{:error, code: code}
{:error, msg} ->
Logger.error("Error: init_quote failed with #{msg}")
{:error, msg}
end
end
end