Current section
13 Versions
Jump to
Current section
13 Versions
Compare versions
27
files changed
+1054
additions
-685
deletions
| @@ -0,0 +1,19 @@ | |
| 1 | + [ |
| 2 | + inputs: [ |
| 3 | + ".formatter.exs", |
| 4 | + "mix.exs", |
| 5 | + "{config,lib,test}/**/*.{ex,exs}" |
| 6 | + ], |
| 7 | + locals_without_parens: [ |
| 8 | + adapter: 1, |
| 9 | + middleware: 1, |
| 10 | + middleware: 2 |
| 11 | + ], |
| 12 | + export: [ |
| 13 | + locals_without_parens: [ |
| 14 | + adapter: 1, |
| 15 | + middleware: 1, |
| 16 | + middleware: 2 |
| 17 | + ] |
| 18 | + ] |
| 19 | + ] |
| @@ -56,7 +56,7 @@ module for your API, as shown below: | |
| 56 56 | ```elixir |
| 57 57 | iex(1)> alias Maxwell.Conn |
| 58 58 | iex(2)> Conn.new("http://httpbin.org/drip") |> |
| 59 | - Conn.put_query_string(%{numbytes: 25, duration: 1, delay: 1, code: 200}) |> |
| 59 | + Conn.put_query_string(%{numbytes: 25, duration: 1, delay: 1, code: 200}) |> |
| 60 60 | Maxwell.get |
| 61 61 | {:ok, |
| 62 62 | %Maxwell.Conn{method: :get, opts: [], path: "/drip", |
| @@ -80,7 +80,7 @@ for a list of all functions, and detailed info about how they behave. | |
| 80 80 | 1. Add maxwell to your list of dependencies in `mix.exs`: |
| 81 81 | ```ex |
| 82 82 | def deps do |
| 83 | - [{:maxwell, "~> 2.2.2"}] |
| 83 | + [{:maxwell, "~> 2.3"}] |
| 84 84 | end |
| 85 85 | ``` |
| 86 86 | 2. Ensure maxwell has started before your application: |
| @@ -160,13 +160,13 @@ You may provide your own encoder/decoder by providing the following options: | |
| 160 160 | |
| 161 161 | ```ex |
| 162 162 | # For the EncodeJson module |
| 163 | - middleware Maxwell.Middleware.EncodeJson, |
| 164 | - encode_content_type: "text/javascript", |
| 163 | + middleware Maxwell.Middleware.EncodeJson, |
| 164 | + encode_content_type: "text/javascript", |
| 165 165 | encode_func: &other_json_lib.encode/1] |
| 166 166 | |
| 167 167 | # For the DecodeJson module |
| 168 | - middleware Maxwell.Middleware.DecodeJson, |
| 169 | - decode_content_types: ["yourowntype"], |
| 168 | + middleware Maxwell.Middleware.DecodeJson, |
| 169 | + decode_content_types: ["yourowntype"], |
| 170 170 | decode_func: &other_json_lib.decode/1] |
| 171 171 | |
| 172 172 | # Both sets of options can be provided to the Json module |
| @@ -187,4 +187,3 @@ then provide guidance on implementation if necessary. | |
| 187 187 | ## License |
| 188 188 | |
| 189 189 | See the [LICENSE](https://github.com/zhongwencool/maxwell/blob/master/LICENSE) file for license rights and limitations (MIT). |
| 190 | - |
| @@ -1,24 +1,25 @@ | |
| 1 1 | {<<"app">>,<<"maxwell">>}. |
| 2 2 | {<<"build_tools">>,[<<"mix">>]}. |
| 3 3 | {<<"description">>,<<"Maxwell is an HTTP client adapter.">>}. |
| 4 | - {<<"elixir">>,<<"~> 1.3">>}. |
| 4 | + {<<"elixir">>,<<"~> 1.8">>}. |
| 5 5 | {<<"files">>, |
| 6 | - [<<"lib">>,<<"lib/LICENSE">>,<<"lib/maxwell">>,<<"lib/maxwell.ex">>, |
| 7 | - <<"lib/maxwell/adapter">>,<<"lib/maxwell/adapter/adapter.ex">>, |
| 8 | - <<"lib/maxwell/adapter/hackney.ex">>,<<"lib/maxwell/adapter/httpc.ex">>, |
| 9 | - <<"lib/maxwell/adapter/ibrowse.ex">>,<<"lib/maxwell/adapter/util.ex">>, |
| 10 | - <<"lib/maxwell/builder">>,<<"lib/maxwell/builder.ex">>, |
| 11 | - <<"lib/maxwell/builder/adapter.ex">>, |
| 12 | - <<"lib/maxwell/builder/middleware.ex">>,<<"lib/maxwell/builder/util.ex">>, |
| 13 | - <<"lib/maxwell/conn.ex">>,<<"lib/maxwell/error.ex">>, |
| 14 | - <<"lib/maxwell/middleware">>,<<"lib/maxwell/middleware/baseurl.ex">>, |
| 15 | - <<"lib/maxwell/middleware/fuse.ex">>,<<"lib/maxwell/middleware/header.ex">>, |
| 16 | - <<"lib/maxwell/middleware/header_case.ex">>, |
| 17 | - <<"lib/maxwell/middleware/json.ex">>,<<"lib/maxwell/middleware/logger.ex">>, |
| 6 | + [<<"lib">>,<<"lib/LICENSE">>,<<"lib/maxwell">>,<<"lib/maxwell/middleware">>, |
| 7 | + <<"lib/maxwell/middleware/baseurl.ex">>, |
| 8 | + <<"lib/maxwell/middleware/rels.ex">>,<<"lib/maxwell/middleware/logger.ex">>, |
| 9 | + <<"lib/maxwell/middleware/header.ex">>,<<"lib/maxwell/middleware/fuse.ex">>, |
| 10 | + <<"lib/maxwell/middleware/json.ex">>, |
| 18 11 | <<"lib/maxwell/middleware/middleware.ex">>, |
| 19 | - <<"lib/maxwell/middleware/opts.ex">>,<<"lib/maxwell/middleware/rels.ex">>, |
| 20 | - <<"lib/maxwell/middleware/retry.ex">>,<<"lib/maxwell/multipart.ex">>, |
| 21 | - <<"lib/maxwell/query.ex">>,<<"LICENSE">>,<<"mix.exs">>,<<"README.md">>]}. |
| 12 | + <<"lib/maxwell/middleware/retry.ex">>,<<"lib/maxwell/middleware/opts.ex">>, |
| 13 | + <<"lib/maxwell/middleware/header_case.ex">>,<<"lib/maxwell/multipart.ex">>, |
| 14 | + <<"lib/maxwell/error.ex">>,<<"lib/maxwell/adapter">>, |
| 15 | + <<"lib/maxwell/adapter/adapter.ex">>,<<"lib/maxwell/adapter/util.ex">>, |
| 16 | + <<"lib/maxwell/adapter/ibrowse.ex">>,<<"lib/maxwell/adapter/httpc.ex">>, |
| 17 | + <<"lib/maxwell/adapter/hackney.ex">>,<<"lib/maxwell/query.ex">>, |
| 18 | + <<"lib/maxwell/conn.ex">>,<<"lib/maxwell/builder.ex">>, |
| 19 | + <<"lib/maxwell/builder">>,<<"lib/maxwell/builder/adapter.ex">>, |
| 20 | + <<"lib/maxwell/builder/util.ex">>,<<"lib/maxwell/builder/middleware.ex">>, |
| 21 | + <<"lib/maxwell.ex">>,<<"LICENSE">>,<<"mix.exs">>,<<"README.md">>, |
| 22 | + <<".formatter.exs">>]}. |
| 22 23 | {<<"licenses">>,[<<"MIT">>]}. |
| 23 24 | {<<"links">>,[{<<"GitHub">>,<<"https://github.com/zhongwencool/maxwell">>}]}. |
| 24 25 | {<<"name">>,<<"maxwell">>}. |
| @@ -28,24 +29,24 @@ | |
| 28 29 | {<<"optional">>,false}, |
| 29 30 | {<<"repository">>,<<"hexpm">>}, |
| 30 31 | {<<"requirement">>,<<"~> 1.0.2">>}], |
| 31 | - [{<<"app">>,<<"fuse">>}, |
| 32 | - {<<"name">>,<<"fuse">>}, |
| 33 | - {<<"optional">>,true}, |
| 34 | - {<<"repository">>,<<"hexpm">>}, |
| 35 | - {<<"requirement">>,<<"~> 2.4">>}], |
| 36 32 | [{<<"app">>,<<"poison">>}, |
| 37 33 | {<<"name">>,<<"poison">>}, |
| 38 34 | {<<"optional">>,true}, |
| 39 35 | {<<"repository">>,<<"hexpm">>}, |
| 40 36 | {<<"requirement">>,<<"~> 2.1 or ~> 3.0">>}], |
| 41 | - [{<<"app">>,<<"hackney">>}, |
| 42 | - {<<"name">>,<<"hackney">>}, |
| 43 | - {<<"optional">>,true}, |
| 44 | - {<<"repository">>,<<"hexpm">>}, |
| 45 | - {<<"requirement">>,<<"~> 1.6">>}], |
| 46 37 | [{<<"app">>,<<"ibrowse">>}, |
| 47 38 | {<<"name">>,<<"ibrowse">>}, |
| 48 39 | {<<"optional">>,true}, |
| 49 40 | {<<"repository">>,<<"hexpm">>}, |
| 50 | - {<<"requirement">>,<<"~> 4.2">>}]]}. |
| 51 | - {<<"version">>,<<"2.2.3">>}. |
| 41 | + {<<"requirement">>,<<"~> 4.4">>}], |
| 42 | + [{<<"app">>,<<"hackney">>}, |
| 43 | + {<<"name">>,<<"hackney">>}, |
| 44 | + {<<"optional">>,true}, |
| 45 | + {<<"repository">>,<<"hexpm">>}, |
| 46 | + {<<"requirement">>,<<"~> 1.15">>}], |
| 47 | + [{<<"app">>,<<"fuse">>}, |
| 48 | + {<<"name">>,<<"fuse">>}, |
| 49 | + {<<"optional">>,true}, |
| 50 | + {<<"repository">>,<<"hexpm">>}, |
| 51 | + {<<"requirement">>,<<"~> 2.4">>}]]}. |
| 52 | + {<<"version">>,<<"2.3.0">>}. |
| @@ -1,5 +1,5 @@ | |
| 1 1 | defmodule Maxwell do |
| 2 | - @moduledoc """ |
| 2 | + @moduledoc """ |
| 3 3 | The maxwell specification. |
| 4 4 | |
| 5 5 | There are two kind of usages: basic usage and advanced middleware usage. |
| @@ -45,6 +45,4 @@ defmodule Maxwell do | |
| 45 45 | |
| 46 46 | """ |
| 47 47 | use Maxwell.Builder |
| 48 | - |
| 49 48 | end |
| 50 | - |
| @@ -1,14 +1,15 @@ | |
| 1 1 | defmodule Maxwell.Adapter do |
| 2 | - @moduledoc """ |
| 2 | + @moduledoc """ |
| 3 3 | Define adapter behaviour. |
| 4 4 | |
| 5 5 | ### Examples |
| 6 6 | See `Maxwell.Adapter.Ibrowse`. |
| 7 7 | """ |
| 8 | - @type return_t :: Maxwell.Conn.t | {:error, any, Maxwell.Conn.t} |
| 8 | + @type return_t :: Maxwell.Conn.t() | {:error, any, Maxwell.Conn.t()} |
| 9 9 | |
| 10 | - @callback send_direct(Maxwell.Conn.t) :: return_t |
| 11 | - @callback send_file(Maxwell.Conn.t) :: return_t |
| 10 | + @callback send_direct(Maxwell.Conn.t()) :: return_t |
| 11 | + @callback send_stream(Maxwell.Conn.t()) :: return_t |
| 12 | + @callback send_file(Maxwell.Conn.t()) :: return_t |
| 12 13 | |
| 13 14 | defmacro __using__(_opts) do |
| 14 15 | quote location: :keep do |
| @@ -18,20 +19,13 @@ defmodule Maxwell.Adapter do | |
| 18 19 | alias Maxwell.Adapter.Util |
| 19 20 | |
| 20 21 | @doc false |
| 21 | - @spec call(Conn.t) :: Conn.t | {:error, reason :: any(), Conn.t} |
| 22 | + @spec call(Conn.t()) :: Conn.t() | {:error, reason :: any(), Conn.t()} |
| 22 23 | def call(conn) do |
| 23 | - res = case conn.req_body do |
| 24 | + case conn.req_body do |
| 24 25 | {:multipart, _} -> send_multipart(conn) |
| 25 | - {:file, _} -> send_file(conn) |
| 26 | - %Stream{} -> send_stream(conn) |
| 27 | - _ -> send_direct(conn) |
| 28 | - end |
| 29 | - case res do |
| 30 | - %Conn{} -> res |
| 31 | - {:error, _reason, _conn} -> res |
| 32 | - other -> |
| 33 | - raise "invalid return from #{unquote(__CALLER__.module)}" <> |
| 34 | - " expected Maxwell.Conn.t or {:error, reason}, but got: #{inspect other}" |
| 26 | + {:file, _} -> send_file(conn) |
| 27 | + %Stream{} -> send_stream(conn) |
| 28 | + _ -> send_direct(conn) |
| 35 29 | end |
| 36 30 | end |
| 37 31 | |
| @@ -43,7 +37,8 @@ defmodule Maxwell.Adapter do | |
| 43 37 | Returns `{:ok, %Maxwell.Conn{}}` or `{:error, reason_term, %Maxwell.Conn{}}`. |
| 44 38 | """ |
| 45 39 | def send_direct(conn) do |
| 46 | - raise Maxwell.Error, {__MODULE__, "#{__MODULE__} Adapter doesn't implement send_direct/1", conn} |
| 40 | + raise Maxwell.Error, |
| 41 | + {__MODULE__, "#{__MODULE__} Adapter doesn't implement send_direct/1", conn} |
| 47 42 | end |
| 48 43 | |
| 49 44 | @doc """ |
| @@ -55,7 +50,8 @@ defmodule Maxwell.Adapter do | |
| 55 50 | Returns `{:ok, %Maxwell.Conn{}}` or `{:error, reason_term, %Maxwell.Conn{}}`. |
| 56 51 | """ |
| 57 52 | def send_file(conn) do |
| 58 | - raise Maxwell.Error, {__MODULE__, "#{__MODULE__} Adapter doesn't implement send_file/1", conn} |
| 53 | + raise Maxwell.Error, |
| 54 | + {__MODULE__, "#{__MODULE__} Adapter doesn't implement send_file/1", conn} |
| 59 55 | end |
| 60 56 | |
| 61 57 | @doc """ |
| @@ -67,7 +63,8 @@ defmodule Maxwell.Adapter do | |
| 67 63 | Returns `{:ok, %Maxwell.Conn{}}` or `{:error, reason_term, %Maxwell.Conn{}}`. |
| 68 64 | """ |
| 69 65 | def send_stream(conn) do |
| 70 | - raise Maxwell.Error, {__MODULE__, "#{__MODULE__} Adapter doesn't implement send_stream/1", conn} |
| 66 | + raise Maxwell.Error, |
| 67 | + {__MODULE__, "#{__MODULE__} Adapter doesn't implement send_stream/1", conn} |
| 71 68 | end |
| 72 69 | |
| 73 70 | defp send_multipart(conn) do |
| @@ -76,8 +73,7 @@ defmodule Maxwell.Adapter do | |
| 76 73 | send_direct(%Conn{conn | req_headers: req_headers, req_body: req_body}) |
| 77 74 | end |
| 78 75 | |
| 79 | - defoverridable [send_direct: 1, send_file: 1, send_stream: 1] end |
| 76 | + defoverridable send_direct: 1, send_file: 1, send_stream: 1 |
| 77 | + end |
| 80 78 | end |
| 81 | - |
| 82 79 | end |
| 83 | - |
Loading more files…