Skip to content

Commit

Permalink
Fix deepl integration
Browse files Browse the repository at this point in the history
  • Loading branch information
chrztoph committed Dec 8, 2024
1 parent e7415e1 commit c51abea
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 9 deletions.
7 changes: 1 addition & 6 deletions app/lib/deepl/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,6 @@ def initialize(organization = nil)
else
@api_token = ENV.fetch('DEEPL_API_TOKEN', nil)
@api_endpoint = @api_token.ends_with?(':fx') ? DEEPL_FREE_API : DEEPL_PRO_API

response = self.usage
if response.nil?
raise DeeplInvalidTokenException
end
end
end

Expand All @@ -57,7 +52,7 @@ def set_api_credentials(api_token, api_endpoint)
# }
def usage
if Rails.env.test?
if @api_endpoint == DEEPL_FREE_API && @api_token == '<valid_free_token>'
if @api_endpoint == DEEPL_FREE_API && @api_token == '<valid_free_token>:fx'
{ "character_count": 1337, "character_limit": 500_000 }
elsif @api_endpoint == DEEPL_PRO_API && @api_token == '<valid_pro_token>'
{ "character_count": 180_118, "character_limit": 1_250_000 }
Expand Down
4 changes: 2 additions & 2 deletions spec/requests/api/v1/machine_translations_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
@target_language.country_code = 'US'
@target_language.save!

ENV['DEEPL_API_TOKEN'] = '<valid_free_token>'
ENV['DEEPL_API_TOKEN'] = '<valid_free_token>:fx'
end
end

Expand Down Expand Up @@ -61,7 +61,7 @@
end

it 'has status code 200 if super admin with free token' do
ENV['DEEPL_API_TOKEN'] = '<valid_free_token>'
ENV['DEEPL_API_TOKEN'] = '<valid_free_token>:fx'

get '/api/v1/machine_translations_usage', headers: @auth_params_superadmin
expect(response).to have_http_status(:ok)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def test_allows_to_update_settings_with_permissions(role)
it 'updates settings with valid free token' do
put "/api/v1/organizations/#{@organization.id}/machine_translation",
params: {
deepl_api_token: '<valid_free_token>'
deepl_api_token: '<valid_free_token>:fx'
},
headers: @auth_params
expect(response).to have_http_status(:ok)
Expand Down

0 comments on commit c51abea

Please sign in to comment.