Current section

10 Versions

Jump to

Compare versions

9 files changed
+232 additions
-187 deletions
  @@ -15,88 +15,90 @@ Add it to your dependencies:
15 15 ```elixir
16 16 # mix.exs
17 17 def deps do
18 - [{:ex_anti_gate, "~> 0.2"}]
18 + [{:ex_anti_gate, "~> 0.3"}]
19 19 end
20 20 ```
21 21
22 22 end fetch it with `mix deps.get`.
23 23
24 - ## Configuration
25 - The Antigate client has to be configured. At least `api_key` MUST be set, otherwise the client
26 - is shutting down with a notice.
24 + ## Configuration
25 + The Antigate client has to be configured. At least `api_key` MUST be set, otherwise the client
26 + is shutting down with a notice. It's possible to set it in config file or via environment variable
27 + `EX_ANTI_GATE_API_KEY`. Note: in case of both (system and config) options exist at the same time
28 + the environment variable value will be used.
27 29
28 - Default options look like this:
30 + Default options look like this:
29 31
30 - config :ex_anti_gate,
31 - autostart: true, # Start ExAntiGate process on application start
32 - http_client: HTTPoison, # http client - change for testing proposes only
32 + config :ex_anti_gate,
33 + autostart: true, # Start ExAntiGate process on application start
34 + http_client: HTTPoison, # http client - change for testing proposes only
33 35
34 - # ############################# task options #####################################
36 + # ############################# task options #####################################
35 37
36 - api_key: nil,
37 - api_host: "https://api.anti-captcha.com",
38 - language_pool: "en", # "en" (default) - english queue,
39 - # "rn" - Russian, Ukrainian, Belorussian, Kazakh language group
40 - result_request_interval: 10_000, # result request first attemt interval, in milliseconds
41 - result_retry_interval: 2_000, # delay between captcha status checks, in milliseconds
42 - no_slot_retry_interval: 5_000, # delay between retries to catch a free slot to proceed captcha, in milliseconds
43 - no_slot_max_retries: 0, # number of retries to catch a free slot,
44 - # 0 - until (max_timeout - result_request_inteval) milliseconds gone
45 - max_timeout: 120_000, # captcha recognition maximum timeout;
46 - # the result value must be read during this period
47 - phrase: false, # does captcha have one or more spaces
48 - case: false, # captcha is case sensetive
49 - numeric: 0, # 0 - any symbols
50 - # 1 - captcha has digits only
51 - # 2 - captcha has any symbols EXCEPT digits
52 - math: false, # captcha is a math equation and it's necessary to solve it and enter result
53 - min_length: 0, # 0 - has no limits
54 - # > 0 - an integer sets minimum captcha length
55 - max_length: 0, # 0 - has no limits
56 - # > 0 - an integer sets maximum captcha length
57 - push: false # do not reply to the sender by default (wait for a result request)
38 + api_key: nil,
39 + api_host: "https://api.anti-captcha.com",
40 + language_pool: "en", # "en" (default) - english queue,
41 + # "rn" - Russian, Ukrainian, Belorussian, Kazakh language group
42 + result_request_interval: 10_000, # result request first attemt interval, in milliseconds
43 + result_retry_interval: 2_000, # delay between captcha status checks, in milliseconds
44 + no_slot_retry_interval: 5_000, # delay between retries to catch a free slot to proceed captcha, in milliseconds
45 + no_slot_max_retries: 0, # number of retries to catch a free slot,
46 + # 0 - until (max_timeout - result_request_inteval) milliseconds gone
47 + max_timeout: 120_000, # captcha recognition maximum timeout;
48 + # the result value must be read during this period
49 + phrase: false, # does captcha have one or more spaces
50 + case: false, # captcha is case sensetive
51 + numeric: 0, # 0 - any symbols
52 + # 1 - captcha has digits only
53 + # 2 - captcha has any symbols EXCEPT digits
54 + math: false, # captcha is a math equation and it's necessary to solve it and enter result
55 + min_length: 0, # 0 - has no limits
56 + # > 0 - an integer sets minimum captcha length
57 + max_length: 0, # 0 - has no limits
58 + # > 0 - an integer sets maximum captcha length
59 + push: false # do not reply to the sender by default (wait for a result request)
58 60
59 - ## Using
60 - It is possible to use it in standard and push mode.
61 + ## Using
62 + It is possible to use it in standard and push mode.
61 63
62 - In standard mode you send a task request with `ExAntiGate.solve_text_task/2` function and then can
63 - request current result with `ExAntiGate.get_task_result/1` or a full task stack with `ExAntiGate.get_task/1`.
64 - `get_task_result/1` is preferable.
64 + In standard mode you send a task request with `ExAntiGate.solve_text_task/2` function and then can
65 + request current result with `ExAntiGate.get_task_result/1` or a full task stack with `ExAntiGate.get_task/1`.
66 + `get_task_result/1` is preferable.
65 67
66 - In push mode you should wait for two kind of tuples:
67 - * `{:ex_anti_gate_result, {:ready, task_uuid :: String.t(), result :: any}}` in case of successfull task or
68 - * `{:ex_anti_gate_result, {:error, task_uuid :: String.t(), error_id :: integer, error_code :: String.t(), error_description :: String.t()}}` - in
69 - case of any errors.
68 + In push mode you should wait for two kind of tuples:
69 + * `{:ex_anti_gate_result, {:ready, task_uuid :: String.t(), result :: any}}` in case of successfull task or
70 + * `{:ex_anti_gate_result, {:error, task_uuid :: String.t(), error_id :: integer, error_code :: String.t(), error_description :: String.t()}}` - in
71 + case of any errors.
70 72
71 - For example:
73 + For example:
72 74
73 75 ```elixir
74 - defmodule MyCaptchaDispatcher do
75 - use GenServer
76 + defmodule MyCaptchaDispatcher do
77 + use GenServer
76 78
77 - # ...
79 + # ...
78 80
79 - # Server API
80 -
81 - def handle_info({:ex_anti_gate_result, {:ready, task_uuid, %{text: text} = _result}}, state) do
82 - # deal with captcha text
83 - end
84 -
85 - def handle_info({:ex_anti_gate_result, {:error, task_uuid, error_id, error_code, error_description}}, state) do
86 - # deal with error
87 - end
81 + # Server API
88 82
83 + def handle_info({:ex_anti_gate_result, {:ready, task_uuid, %{text: text} = _result}}, state) do
84 + # deal with captcha text
89 85 end
90 - ```
91 - Please beware that in push mode task data disappear right after message is sent without any kind of delivery check and
92 - in standard mode task data disappear after `max_timeout` amount of time.
93 86
94 - ## Errors
95 - You can find most errors description in the [Antigate documentation](https://anticaptcha.atlassian.net/wiki/display/API/Errors).
96 - A number of errors came from this client implementation and have negative codes:
97 -
98 - `error_id`: -1, `error_code`: "ERROR_UNKNOWN_ERROR", `error_description`: will be taken from the error source
99 -
100 - `error_id`: -2, `error_code`: "ERROR_API_TIMEOUT", `error_description`: "Maximum timeout reached, task interrupted."
101 -
102 - `error_id`: -3, `error_code`: "ERROR_NO_SLOT_MAX_RETRIES", `error_description`: "Maximum attempts to catch free slot reached, task interrupted."
87 + def handle_info({:ex_anti_gate_result, {:error, task_uuid, error_id, error_code, error_description}}, state) do
88 + # deal with error
89 + end
90 +
91 + end
92 + ```
93 + Please beware that in push mode task data disappear right after message is sent without any kind of delivery check and
94 + in standard mode task data disappear after `max_timeout` amount of time.
95 +
96 + ## Errors
97 + You can find most errors description in the [Antigate documentation](https://anticaptcha.atlassian.net/wiki/display/API/Errors).
98 + A number of errors came from this client implementation and have negative codes:
99 +
100 + `error_id`: -1, `error_code`: "ERROR_UNKNOWN_ERROR", `error_description`: will be taken from the error source
101 +
102 + `error_id`: -2, `error_code`: "ERROR_API_TIMEOUT", `error_description`: "Maximum timeout reached, task interrupted."
103 +
104 + `error_id`: -3, `error_code`: "ERROR_NO_SLOT_MAX_RETRIES", `error_description`: "Maximum attempts to catch free slot reached, task interrupted."
  @@ -1,69 +0,0 @@
1 - # This file is responsible for configuring your application
2 - # and its dependencies with the aid of the Mix.Config module.
3 - use Mix.Config
4 -
5 - # This configuration is loaded before any dependency and is restricted
6 - # to this project. If another project depends on this project, this
7 - # file won't be loaded nor affect the parent project. For this reason,
8 - # if you want to provide default values for your application for
9 - # 3rd-party users, it should be done in your "mix.exs" file.
10 -
11 - # You can configure for your application as:
12 - #
13 - # config :ex_anti_gate, key: :value
14 - #
15 - # And access this configuration in your application as:
16 - #
17 - # Application.get_env(:ex_anti_gate, :key)
18 - #
19 - # Or configure a 3rd-party app:
20 - #
21 - # config :logger, level: :info
22 - #
23 - config :logger,
24 - level: :info
25 -
26 - config :ex_anti_gate,
27 - autostart: true, # Start ExAntiGate process on application start
28 - http_client: HTTPoison, # http client - change for testing proposes only
29 -
30 - # ############################# task options #####################################
31 -
32 - api_key: nil,
33 - api_host: "https://api.anti-captcha.com",
34 - language_pool: "en", # "en" (default) - english queue,
35 - # "rn" - Russian, Ukrainian, Belorussian, Kazakh language group
36 - result_request_interval: 10_000, # result request first attemt interval, in milliseconds
37 - result_retry_interval: 2_000, # delay between captcha status checks, in milliseconds
38 - no_slot_retry_interval: 5_000, # delay between retries to catch a free slot to proceed captcha, in milliseconds
39 - no_slot_max_retries: 0, # number of retries to catch a free slot,
40 - # 0 - until (max_timeout - result_request_inteval) milliseconds gone
41 - max_timeout: 120_000, # captcha recognition maximum timeout;
42 - # the result value must be read during this period
43 - phrase: false, # does captcha have one or more spaces
44 - case: false, # captcha is case sensetive
45 - numeric: 0, # 0 - any symbols
46 - # 1 - captcha has digits only
47 - # 2 - captcha has any symbols EXCEPT digits
48 - math: false, # captcha is a math equation and it's necessary to solve it and enter result
49 - min_length: 0, # 0 - has no limits
50 - # > 0 - an integer sets minimum captcha length
51 - max_length: 0, # 0 - has no limits
52 - # > 0 - an integer sets maximum captcha length
53 - push: false # do not reply to the sender by default (wait for a result request)
54 -
55 - if Mix.env == :dev do
56 - config :mix_test_watch,
57 - tasks: [
58 - "test",
59 - "dogma",
60 - ]
61 - end
62 -
63 - # It is also possible to import configuration files, relative to this
64 - # directory. For example, you can emulate configuration per environment
65 - # by uncommenting the line below and defining dev.exs, test.exs and such.
66 - # Configuration from the imported file will override the ones defined
67 - # here (which is why it is important to import them last).
68 - #
69 - # import_config "#{Mix.env}.exs"
  @@ -4,9 +4,9 @@
4 4 <<"Elixir AntiGate.com (anti-captcha.com) captcha solving service API client">>}.
5 5 {<<"elixir">>,<<"~> 1.4">>}.
6 6 {<<"files">>,
7 - [<<"lib/ex_anti_gate.ex">>,<<"lib/ex_anti_gate/app.ex">>,
8 - <<"lib/ex_anti_gate/supervisor.ex">>,<<"config/config.exs">>,<<"mix.exs">>,
9 - <<"README.md">>,<<"LICENSE">>]}.
7 + [<<"lib/ex_anti_gate.ex">>,<<"lib/ex_anti_gate/application.ex">>,
8 + <<"lib/ex_anti_gate/config.ex">>,<<"mix.exs">>,<<"README.md">>,
9 + <<"LICENSE">>]}.
10 10 {<<"licenses">>,[<<"MIT">>]}.
11 11 {<<"links">>,[{<<"GitHub">>,<<"https://github.com/vheathen/ex_anti_gate">>}]}.
12 12 {<<"maintainers">>,[<<"Vladimir Drobyshevskiy">>]}.
  @@ -24,4 +24,4 @@
24 24 {<<"name">>,<<"poison">>},
25 25 {<<"optional">>,false},
26 26 {<<"requirement">>,<<"~> 2.0">>}]]}.
27 - {<<"version">>,<<"0.2.2">>}.
27 + {<<"version">>,<<"0.3.0">>}.
  @@ -10,7 +10,9 @@ defmodule ExAntiGate do
10 10
11 11 ## Configuration
12 12 The Antigate client has to be configured. At least `api_key` MUST be set, otherwise the client
13 - is shutting down with a notice.
13 + is shutting down with a notice. It's possible to set it in config file or via environment variable
14 + `EX_ANTI_GATE_API_KEY`. Note: in case of both (system and config) options exist at the same time
15 + the environment variable value will be used.
14 16
15 17 Default options look like this:
16 18
  @@ -101,13 +103,14 @@ defmodule ExAntiGate do
101 103 require Logger
102 104 import Ecto.UUID, only: [generate: 0]
103 105
106 + alias ExAntiGate.Config
107 +
104 108 # #########################################################
105 109 # Client API
106 110 # #########################################################
107 111
108 112 @doc """
109 113 Starts the antigate client linked process
110 - Can be used if `:autostart` config option set to `false`
111 114 """
112 115 def start_link(initial_state \\ %{}) do
113 116 GenServer.start_link(__MODULE__, initial_state, name: __MODULE__)
  @@ -115,10 +118,9 @@ defmodule ExAntiGate do
115 118
116 119 @doc """
117 120 Starts the antigate client process
118 - Can be used if `:autostart` config option set to `false`
119 121 """
120 122 def start(initial_state \\ %{}) do
121 - GenServer.start_link(__MODULE__, initial_state, name: __MODULE__)
123 + GenServer.start(__MODULE__, initial_state, name: __MODULE__)
122 124 end
123 125
124 126 @doc """
  @@ -396,8 +398,7 @@ defmodule ExAntiGate do
396 398 end
397 399
398 400 defp merge_options(options) do
399 - :ex_anti_gate
400 - |> Application.get_all_env()
401 + Config.get_all_env()
401 402 |> Enum.concat(options)
402 403 |> Enum.into(%{})
403 404 |> Map.delete(:included_applications)
  @@ -1,24 +0,0 @@
1 - defmodule ExAntiGate.App do
2 - @moduledoc false
3 -
4 - use Application
5 - require Logger
6 -
7 - def start(_type, _args) do
8 - unless is_nil(System.get_env("EX_ANTI_GATE_API_KEY")) do
9 - Application.put_env(:ex_anti_gate, :api_key, System.get_env("EX_ANTI_GATE_API_KEY"))
10 - end
11 -
12 - if is_nil(Application.get_env(:ex_anti_gate, :api_key)) do
13 - Logger.error "ExAntiGate: api_key must to be set. Please check documetation."
14 - Process.exit(self(), :kill)
15 - end
16 -
17 - if Application.get_env(:ex_anti_gate, :autostart) do
18 - # Start the supervision tree
19 - ExAntiGate.Supervisor.start_link
20 - end
21 -
22 - end
23 -
24 - end
Loading more files…