-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
74 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
defmodule Crawly.Fetchers.Fetcher do | ||
@moduledoc """ | ||
A behavior module for defining Crawly Fetchers | ||
A fetcher is expected to implement a fetch callback which should take | ||
Crawly.Request, HTTP client options and return Crawly.Response. | ||
""" | ||
|
||
@callback fetch(request, options) :: {:ok, response} | {:error, reason} | ||
when request: Crawly.Request.t(), | ||
response: Crawly.Response.t(), | ||
options: map(), | ||
reason: term() | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
defmodule Crawly.Fetchers.HTTPoisonFetcher do | ||
@moduledoc """ | ||
Implements Crawly.Fetchers.Fetcher behavior based on HTTPoison HTTP client | ||
""" | ||
@behaviour Crawly.Fetchers.Fetcher | ||
|
||
require Logger | ||
|
||
def fetch(request, _client_options) do | ||
HTTPoison.get(request.url, request.headers, request.options) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
defmodule Crawly.Response do | ||
@moduledoc """ | ||
Define Crawly response structure | ||
""" | ||
|
||
defstruct body: nil, | ||
headers: [], | ||
request: nil, | ||
request_url: nil, | ||
status_code: nil | ||
|
||
@type t :: %__MODULE__{ | ||
body: term(), | ||
headers: list(), | ||
request: Crawly.Request.t(), | ||
request_url: Crawly.Request.url(), | ||
status_code: integer() | ||
} | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters