From 3178043a7f9e37e366466c474cecb5d71eb051c8 Mon Sep 17 00:00:00 2001 From: JoostdeJager <46704554+JoostdeJager@users.noreply.github.com> Date: Mon, 21 Aug 2023 06:19:39 +1000 Subject: [PATCH 1/5] determine tier --- README.md | 7 ++++--- lib/deepl_ex.ex | 14 ++++++++++++-- lib/helpers/configuration.ex | 2 -- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 43a29b3..77162c5 100644 --- a/README.md +++ b/README.md @@ -18,10 +18,11 @@ end The docs can be found at . ## Configuration -After installing the package, you should add some variables to your config. +After installing the package, the following should be added to your config. ```elixir config :deepl_ex, - api_key: "", # String containing your DeepL api key - tier: :free # Can be :free or :pro + api_key: "" # String containing your DeepL api key ``` + +We determine the tier based on the api key, so you don't need to specify the tier. diff --git a/lib/deepl_ex.ex b/lib/deepl_ex.ex index 061ce6b..6bf7ff6 100644 --- a/lib/deepl_ex.ex +++ b/lib/deepl_ex.ex @@ -38,7 +38,7 @@ defmodule DeeplEx do {:valid_target_language?, true} <- LanguageValidator.valid_target_language?(target_language), {:ok, api_key} = Configuration.api_key(), - {:ok, tier} = Configuration.tier(), + tier = tier(api_key), client <- DeepL.client(api_key, tier), {:ok, %{body: %{"translations" => [%{"text" => translation}]}}} <- DeepL.translate(client, %{ @@ -53,7 +53,17 @@ defmodule DeeplEx do end end - defp error_response({error, _}) when error in [:valid_source_language?, :valid_target_language], + defp tier(api_key) do + case String.ends_with?(api_key, ":fx") do + true -> + :free + + _ -> + :pro + end + end + + defp error_response({error, _}) when error in [:valid_source_language?, :valid_target_language?], do: {:error, :invalid_language_specification} defp error_response(error), do: error diff --git a/lib/helpers/configuration.ex b/lib/helpers/configuration.ex index b5c719f..78da744 100644 --- a/lib/helpers/configuration.ex +++ b/lib/helpers/configuration.ex @@ -9,6 +9,4 @@ defmodule DeeplEx.Configuration do {:ok, api_key} end end - - def tier, do: {:ok, Application.get_env(:deepl_ex, :tier, :free)} end From 174132e36784de51220fb7de6c9471a42f81d077 Mon Sep 17 00:00:00 2001 From: JoostdeJager <46704554+JoostdeJager@users.noreply.github.com> Date: Mon, 21 Aug 2023 06:22:53 +1000 Subject: [PATCH 2/5] move tier function back to configuration --- lib/deepl_ex.ex | 12 +----------- lib/helpers/configuration.ex | 10 ++++++++++ 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/deepl_ex.ex b/lib/deepl_ex.ex index 6bf7ff6..46049f4 100644 --- a/lib/deepl_ex.ex +++ b/lib/deepl_ex.ex @@ -38,7 +38,7 @@ defmodule DeeplEx do {:valid_target_language?, true} <- LanguageValidator.valid_target_language?(target_language), {:ok, api_key} = Configuration.api_key(), - tier = tier(api_key), + tier = Configuration.tier(api_key), client <- DeepL.client(api_key, tier), {:ok, %{body: %{"translations" => [%{"text" => translation}]}}} <- DeepL.translate(client, %{ @@ -53,16 +53,6 @@ defmodule DeeplEx do end end - defp tier(api_key) do - case String.ends_with?(api_key, ":fx") do - true -> - :free - - _ -> - :pro - end - end - defp error_response({error, _}) when error in [:valid_source_language?, :valid_target_language?], do: {:error, :invalid_language_specification} diff --git a/lib/helpers/configuration.ex b/lib/helpers/configuration.ex index 78da744..1ff47f2 100644 --- a/lib/helpers/configuration.ex +++ b/lib/helpers/configuration.ex @@ -9,4 +9,14 @@ defmodule DeeplEx.Configuration do {:ok, api_key} end end + + def tier(api_key) do + case String.ends_with?(api_key, ":fx") do + true -> + :free + + _ -> + :pro + end + end end From 8ee3dd3ce60caafe3c9d102ed7585f4066e93742 Mon Sep 17 00:00:00 2001 From: JoostdeJager Date: Tue, 22 Aug 2023 15:56:31 +1000 Subject: [PATCH 3/5] format and changelog --- CHANGELOG.md | 10 +++++++--- lib/deepl_ex.ex | 5 +++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8f49f44..57870b5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,11 @@ # Changelog +## v0.1.1 (2023-08-17) + +- Automatically determine the tier based on the api key + ## v0.1.0 (2023-08-17) -* Initial release -* Add `translate/3` function ([#2](https://github.com/hergetto/deepl_ex/pull/2)) -* Update license to `Apache-2.0` to match the common licenses found in the Elixir ecosystem ([#3](https://github.com/hergetto/deepl_ex/pull/3)) +- Initial release +- Add `translate/3` function ([#2](https://github.com/hergetto/deepl_ex/pull/2)) +- Update license to `Apache-2.0` to match the common licenses found in the Elixir ecosystem ([#3](https://github.com/hergetto/deepl_ex/pull/3)) diff --git a/lib/deepl_ex.ex b/lib/deepl_ex.ex index 46049f4..7ea7e6b 100644 --- a/lib/deepl_ex.ex +++ b/lib/deepl_ex.ex @@ -53,8 +53,9 @@ defmodule DeeplEx do end end - defp error_response({error, _}) when error in [:valid_source_language?, :valid_target_language?], - do: {:error, :invalid_language_specification} + defp error_response({error, _}) + when error in [:valid_source_language?, :valid_target_language?], + do: {:error, :invalid_language_specification} defp error_response(error), do: error end From 0846bffa23cbe923e6775c2f7fc18b8a9f829640 Mon Sep 17 00:00:00 2001 From: JoostdeJager Date: Tue, 22 Aug 2023 16:05:16 +1000 Subject: [PATCH 4/5] bump version --- README.md | 3 ++- mix.exs | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 77162c5..5e834d4 100644 --- a/README.md +++ b/README.md @@ -10,12 +10,13 @@ by adding `deepl_ex` to your list of dependencies in `mix.exs`: ```elixir def deps do [ - {:deepl_ex, "~> 0.1.0"} + {:deepl_ex, "~> 0.1.1"} ] end ``` The docs can be found at . + ## Configuration After installing the package, the following should be added to your config. diff --git a/mix.exs b/mix.exs index 03423dc..9d13e92 100644 --- a/mix.exs +++ b/mix.exs @@ -1,7 +1,7 @@ defmodule DeeplEx.MixProject do use Mix.Project - @version "0.1.0" + @version "0.1.1" @source_url "https://github.com/hergetto/deepl_ex" def project do From 7b4127eee7232963bac7ab3a481e51742984f956 Mon Sep 17 00:00:00 2001 From: Thijs van der Heijden Date: Tue, 22 Aug 2023 15:14:43 +0200 Subject: [PATCH 5/5] Update CHANGELOG.md Signed-off-by: Thijs van der Heijden --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 57870b5..769b85c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,8 @@ # Changelog -## v0.1.1 (2023-08-17) +## v0.1.1 (2023-08-22) -- Automatically determine the tier based on the api key +- Automatically determine the tier based on the api key ([#12](https://github.com/hergetto/deepl_ex/pull/12)) ## v0.1.0 (2023-08-17)