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: %{ data: %{ 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: 200}} <- @http_client.post(url, body, "Bearer Token") do {:ok, body} else {:ok, %{status_code: code, body: body}} -> {:error, code: code} end end end