Skip to content

Commit

Permalink
Merge pull request #13 from hergetto/development
Browse files Browse the repository at this point in the history
[Chore]: Release v0.1.1
  • Loading branch information
dustessavdh authored Aug 22, 2023
2 parents cefe635 + 064ee57 commit be79632
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 12 deletions.
10 changes: 7 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
# Changelog

## v0.1.1 (2023-08-22)

- Automatically determine the tier based on the api key ([#12](https://github.com/hergetto/deepl_ex/pull/12))

## 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))
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,20 @@ 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 <https://hexdocs.pm/deepl_ex>.

## 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.
7 changes: 4 additions & 3 deletions lib/deepl_ex.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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 = Configuration.tier(api_key),
client <- DeepL.client(api_key, tier),
{:ok, %{body: %{"translations" => [%{"text" => translation}]}}} <-
DeepL.translate(client, %{
Expand All @@ -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
10 changes: 9 additions & 1 deletion lib/helpers/configuration.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,13 @@ defmodule DeeplEx.Configuration do
end
end

def tier, do: {:ok, Application.get_env(:deepl_ex, :tier, :free)}
def tier(api_key) do
case String.ends_with?(api_key, ":fx") do
true ->
:free

_ ->
:pro
end
end
end
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit be79632

Please sign in to comment.