crawlie v1.0.0 Crawlie.HttpClient.MockClient

Summary

Functions

Implements the Crawlie.HttpClient behaviour

A helper :mock_client_fun returning a :foo error for any passed url

A helper :mock_client_fun returning "<html />" for any passed url

A helper :mock_client_fun returning a success and the passed url

Functions

get(uri, opts)

Implements the Crawlie.HttpClient behaviour.

Example

iex> fun = fn(url) -> {:ok, url <> " body"} end
iex> opts = [mock_client_fun: fun]
iex> uri = URI.parse("http://a.bc/")
iex> {:ok, response} = Crawlie.HttpClient.MockClient.get(uri, opts)
iex> response.status_code
200
iex> response.headers
[]
iex> response.body
"http://a.bc/ body"
return_error(error)

A helper :mock_client_fun returning a :foo error for any passed url.

Example

iex> alias Crawlie.HttpClient.MockClient
iex> fun = MockClient.return_error(:foo)
iex> fun.("http://foo.bar/")
{:error, :foo}
return_html()

A helper :mock_client_fun returning "<html />" for any passed url.

Example

iex> alias Crawlie.HttpClient.MockClient
iex> fun = MockClient.return_html
iex> fun.("http://foo.bar/")
{:ok, "<html />"}
return_url()

A helper :mock_client_fun returning a success and the passed url.

Example

iex> alias Crawlie.HttpClient.MockClient
iex> fun = MockClient.return_url
iex> fun.("http://foo.bar/")
{:ok, "http://foo.bar/"}