Skip to content

Commit

Permalink
⚡ Add Curl String to Request.inspect
Browse files Browse the repository at this point in the history
Adds a new section for "Curl String" in the Request's inspect algebra doc.
  • Loading branch information
andrewvy committed Feb 24, 2017
1 parent 2bee9c4 commit 27305d6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
6 changes: 4 additions & 2 deletions lib/httpipe/curl_helpers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ defmodule HTTPipe.CurlHelpers do

@spec convert_full_url(Request.url, Request.params) :: String.t
def convert_full_url(base_url, params) do
{:ok, full_url} = Request.prepare_url(base_url, params)
full_url
case Request.prepare_url(base_url, params) do
{:ok, full_url} -> full_url
{:error, _} -> ""
end
end

@spec convert_method(Request.method) :: String.t
Expand Down
12 changes: 11 additions & 1 deletion lib/httpipe/inspection_helpers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ defmodule HTTPipe.InspectionHelpers do
full_url = inspect_full_url(request.url, request.params, opts)
params = inspect_params(request.params, opts)
body = inspect_body(request.body, opts)
curl_string = inspect_curl_string(request, Map.put_new(opts, :pretty, true))

concat [
format_section_head("Request"),
Expand All @@ -86,7 +87,8 @@ defmodule HTTPipe.InspectionHelpers do
full_url,
headers,
params,
body
body,
curl_string
]
end

Expand Down Expand Up @@ -211,6 +213,14 @@ defmodule HTTPipe.InspectionHelpers do
|> format_nested_with_header("Headers")
end

@spec inspect_curl_string(Request.t, Inspect.Opts.t) :: Inspect.Algebra.t
def inspect_curl_string(request, opts) do
request
|> Request.to_curl()
|> to_doc(opts)
|> format_nested_with_header("Curl String")
end

@spec inspect_status_code(Response.status_code, Inspect.Opts.t) :: Inspect.Algebra.t
def inspect_status_code(status_code, opts) do
status_code
Expand Down

0 comments on commit 27305d6

Please sign in to comment.