Class: DeepL::AdminClient
- Inherits:
-
Object
- Object
- DeepL::AdminClient
- Defined in:
- lib/deepl/admin_client.rb
Overview
Client for the DeepL Admin API, used to manage the developer keys of your organization and to retrieve usage analytics. It owns its configuration and reads no environment variables.
All methods may raise a DeepL::Exceptions::Error or a subclass, for example
DeepL::Exceptions::AuthorizationFailed if the admin key is not accepted.
Instance Method Summary collapse
-
#create_developer_key(label: nil, extra_body_parameters: nil) ⇒ DeepL::Resources::DeveloperKey
Creates a developer key.
-
#deactivate_developer_key(key, extra_body_parameters: nil) ⇒ DeepL::Resources::DeveloperKey
Deactivates a developer key.
-
#get_custom_tag_usage_analytics(start_date, end_date, aggregate_by: nil, page: nil) ⇒ DeepL::Resources::CustomTagUsageReport
Retrieves the usage per custom tag within a date range, with the same limits as
get_usage_analytics. -
#get_usage_analytics(start_date, end_date, group_by: nil) ⇒ DeepL::Resources::AdminUsageReport
Retrieves the usage of the organization within a date range.
-
#initialize(admin_key, server_url: nil, headers: {}, max_retries: 5, timeout: 10, proxy: nil, send_platform_info: true, app_info: nil, http_client_options: nil, logger: nil) ⇒ AdminClient
constructor
A keyword argument given as
niltakes its default, like an omitted one. - #inspect ⇒ Object
-
#list_developer_keys ⇒ Array<DeepL::Resources::DeveloperKey>
Retrieves all developer keys of the organization, including deactivated ones.
-
#rename_developer_key(key, label, extra_body_parameters: nil) ⇒ DeepL::Resources::DeveloperKey
Changes the label of a developer key.
-
#set_developer_key_usage_limits(key, extra_body_parameters: nil, **limits) ⇒ DeepL::Resources::DeveloperKey
Changes the usage limits of a developer key.
Constructor Details
#initialize(admin_key, server_url: nil, headers: {}, max_retries: 5, timeout: 10, proxy: nil, send_platform_info: true, app_info: nil, http_client_options: nil, logger: nil) ⇒ AdminClient
A keyword argument given as nil takes its default, like an omitted one.
45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/deepl/admin_client.rb', line 45 def initialize(admin_key, server_url: nil, headers: {}, max_retries: 5, timeout: 10, # rubocop:disable Metrics/ParameterLists proxy: nil, send_platform_info: true, app_info: nil, http_client_options: nil, logger: nil) @api = Utils::ClientBuilder.build_api( admin_key, key_name: 'admin_key', server_url: server_url, default_server_url: DEEPL_SERVER_URL, headers: headers, max_retries: max_retries, timeout: timeout, proxy: proxy, send_platform_info: send_platform_info, app_info: app_info, http_client_options: , logger: logger ) end |
Instance Method Details
#create_developer_key(label: nil, extra_body_parameters: nil) ⇒ DeepL::Resources::DeveloperKey
Creates a developer key. The API uses "DeepL API Key" as label if none is given.
Creation is retried only after failures that show the request was not processed (HTTP 429 and
transient network failures while connecting, such as DNS resolution errors, refused
connections, unreachable hosts or networks, connection timeouts and resets during the TLS or
proxy handshake), so that a retry cannot create a second key. The raised error has
should_retry? true for these and for a response body cut off mid-read, which is not retried.
116 117 118 |
# File 'lib/deepl/admin_client.rb', line 116 def create_developer_key(label: nil, extra_body_parameters: nil) Requests::Admin::CreateDeveloperKey.new(api, label, extra_body_parameters).request end |
#deactivate_developer_key(key, extra_body_parameters: nil) ⇒ DeepL::Resources::DeveloperKey
Deactivates a developer key. Deactivation is permanent.
136 137 138 |
# File 'lib/deepl/admin_client.rb', line 136 def deactivate_developer_key(key, extra_body_parameters: nil) update_developer_key('deactivate', { key_id: key_id(key) }, extra_body_parameters) end |
#get_custom_tag_usage_analytics(start_date, end_date, aggregate_by: nil, page: nil) ⇒ DeepL::Resources::CustomTagUsageReport
Retrieves the usage per custom tag within a date range, with the same limits as
get_usage_analytics. Results are paginated: pass the next_page of a report as page to
retrieve the following page.
98 99 100 101 |
# File 'lib/deepl/admin_client.rb', line 98 def get_custom_tag_usage_analytics(start_date, end_date, aggregate_by: nil, page: nil) Requests::Admin::CustomTagUsageAnalytics.new(api, start_date, end_date, aggregate_by, page).request end |
#get_usage_analytics(start_date, end_date, group_by: nil) ⇒ DeepL::Resources::AdminUsageReport
Retrieves the usage of the organization within a date range. The API requires the start date to be before the end date (a report covers at least two days) and the range to be at most 366 days.
77 78 79 |
# File 'lib/deepl/admin_client.rb', line 77 def get_usage_analytics(start_date, end_date, group_by: nil) Requests::Admin::UsageAnalytics.new(api, start_date, end_date, group_by).request end |
#inspect ⇒ Object
57 58 59 |
# File 'lib/deepl/admin_client.rb', line 57 def inspect "#<#{self.class.name} server_url=#{configuration.host}>" end |
#list_developer_keys ⇒ Array<DeepL::Resources::DeveloperKey>
Retrieves all developer keys of the organization, including deactivated ones.
124 125 126 |
# File 'lib/deepl/admin_client.rb', line 124 def list_developer_keys Requests::Admin::ListDeveloperKeys.new(api).request end |
#rename_developer_key(key, label, extra_body_parameters: nil) ⇒ DeepL::Resources::DeveloperKey
Changes the label of a developer key.
149 150 151 |
# File 'lib/deepl/admin_client.rb', line 149 def rename_developer_key(key, label, extra_body_parameters: nil) update_developer_key('label', { key_id: key_id(key), label: label }, extra_body_parameters) end |
#set_developer_key_usage_limits(key, extra_body_parameters: nil, **limits) ⇒ DeepL::Resources::DeveloperKey
Changes the usage limits of a developer key. Only the given limits are changed; omitted
limits keep their current value. A nil limit means unlimited and 0 blocks that usage.
admin_client.set_developer_key_usage_limits(key, characters: 0)
admin_client.set_developer_key_usage_limits(key, speech_to_text_milliseconds: nil)
170 171 172 173 174 |
# File 'lib/deepl/admin_client.rb', line 170 def set_developer_key_usage_limits(key, extra_body_parameters: nil, **limits) id = key_id(key) validate_usage_limits!(limits) update_developer_key('limits', limits.merge(key_id: id), extra_body_parameters) end |