Ruby interface for the Lokalise APIv2 that represents returned data as Ruby objects.
View the Project on GitHub lokalise/ruby-lokalise-api
PermissionTemplates
endpoint:permission_templates = test_client.permission_templates team_id
template = permission_templates[0]
template.id # => 1
template.role # => "Manager"
template.permissions # => ['branches_main_modify', ...]
template.description # => 'Manage project settings ...'
template.tag # => 'Full access'
template.tagColor # => 'green'
template.tagInfo # => ''
template.doesEnableAllReadOnlyLanguages # => true
role_id
attribute to the user group object. For example:group = test_client.team_user_group team_id, group_id
group.role_id # => 5
role_id
attribute to the contributor object. For example:contributor = test_client.contributor project_id, user_id
contributor.role_id # => 5
cursor_pagination_params = {
pagination: 'cursor',
cursor: 'eyIxIjozMTk3ODIzNzJ9', # The starting cursor. Optional, string
limit: 2 # The number of items to fetch. Optional, default is 100
}
keys = @client.keys '123abcdef.01', cursor_pagination_params
keys.next_cursor? # => true
keys.next_cursor # => 'eyIxIjozMTk3ODIzNzV9'
# Request keys from the next cursor (returns `nil` if the next cursor is not available):
keys_next_cursor = keys.load_next_cursor
content-type
header in certain casesIn this version SDK has been fully rewritten to make it more robust, better tested, and even more comfortable to work with. While most of the methods have similar signatures, there are a few major changes.
Breaking changes:
translation_statuses
has been renamed to custom_translation_statuses
translation_status
has been renamed to custom_translation_status
create_translation_status
has been renamed to create_custom_translation_status
update_translation_status
has been renamed to update_custom_translation_status
destroy_translation_status
has been renamed to destroy_custom_translation_status
translation_status_colors
has been renamed to custom_translation_status_colors
language
has been renamed to project_language
create_languages
has been renamed to create_project_languages
update_language
has been renamed to update_project_language
destroy_language
has been renamed to destroy_project_language
destroy_all
has been removed from Keys
collectionjwt
has been renamed to create_jwt
:token = @client.create_jwt project_id, service: :ota
token.jwt # => '123abcd'
raw_data
method has been removed. All resources respond to the methods named after the corresponding attributes and also support []
notation. Therefore both versions should work:branch = @client.branch project_id, branch_id
branch.name # => 'my-branch'
branch[:name] # => 'my-branch'
Updates:
update
, destroy
, and reload_data
.params = {
lang_name: 'Updated custom language',
plural_forms: %w[one many]
}
language = @client.project_language project_id, language_id
updated_language = language.update params
updated_language.lang_name # => 'Updated custom language'
merge_branch
, restore_snapshot
, and so on. Please browse documentation for a specific endpoint to learn about new features.project = @client.project project_id
restored_project = project.restore_snapshot snapshot_id
restored_project.name # => 'Project copy'
destroy
now return objects, not hashes. However, these objects also respond to the []
method to preserve backwards compatibility.response = @client.destroy_screenshot project_id, screen_id
response.screenshot_deleted # => true
response[:screenshot_deleted] # => true
jwt
method. It is now mandatory to provide the project ID to request JWT for:resp = @client.jwt("123.abcd")
resp.jwt # => 'eyJ0eXAiOi...`
Jwt
endpoint. You can now request JWT easily (please note that these tokens are used only to work with OTA):resp = @client.jwt
resp.jwt # => 'eyJ0eXAiOi...`
#token
and #refresh
methods (used to request OAuth 2 access and refresh tokens) now return proper Ruby objects:RubyLokaliseApi.auth_client('client_id', 'client_secret')
# Previously:
token = auth_client.token 'oauth2_code' # this method used to return a hash
token['access_token']
token['refresh_token']
refresh = auth_client.refresh 'refresh_token' # this method used to return a hash
token['access_token']
token['expires_in']
# NOW:
token = auth_client.token 'oauth2_code' # this is an instance of the Token class
token.access_token
token.refresh_token
refresh = auth_client.refresh 'refresh_token' # this is an instance of the Refresh class
token.access_token
token.expires_in
auth_client = RubyLokaliseApi.auth_client('id', 'secret', timeout: 5, open_timeout: 10)
New feature: added ability to access resources’ attributes with the []
notation. In other words, previously you could only write:
branch.branch_id
branch.name
Now you can also write:
branch[:branch_id]
branch['name']
This feature was introduced so that all resources can play nicely with methods like pluck
.
Lokalise
main module to RubyLokaliseApi
and changed the way you require the gem. You can use find-replace to fix all occurences. For example, if previously you wrote:require 'ruby-lokalise-api'
@client = Lokalise.client 'YOUR_TOKEN_HERE'
Now you should say:
require 'ruby_lokalise_api'
@client = RubyLokaliseApi.client 'YOUR_TOKEN_HERE'
enable_compression
option. Compression is now enabled for all requests (however the API might still send uncompressed data if the body is small) and the response will be decompressed automatically.auth_client = RubyLokaliseApi.auth_client 'OAUTH2_CLIENT_ID', 'OAUTH2_CLIENT_SECRET'
# Generate authentication URL:
url = auth_client.auth scope: %w[read_projects write_tasks]
# Generate a new token:
response = auth_client.token 'secret code'
access_token = response['access_token']
refresh_token = response['refresh_token']
# Refresh an expired token:
response = auth_client.refresh('YOUR_REFRESH_TOKEN')['access_token']
# Use the access token to perform requests on the user's behalf:
@client = RubyLokaliseApi.oauth2_client access_token
@client.projects # list user's projects
client
(issues with multithreading)Segments
endpointTeamUserBillingDetails
endpoint.oauth_client
method for the Lokalise
module. This method must be used when you’re initializing a new API client with a token obtained via OAuth 2 flow, not by copy-pasting the token from the “Personal profile” section on Lokalise website. So in this case instead of saying RubyLokaliseApi.client
, you should do the following:@client = RubyLokaliseApi.oauth_client("TOKEN_OBTAINED_VIA_OAUTH2", params)
params
are the same as for the .client
method..reset_oauth_client!
method for the Lokalise
module to reset the currently set oauth_client
.RubyLokaliseApi.reset_oauth_client! # effectively sets the `@oauth_client` to `nil`
:enable_compression
option to true
:client = RubyLokaliseApi.client('YOUR_TOKEN', enable_compression: true)
task_id
attribute for the Translation
modelpayment_method
and dry_run
attributes to Order
auto_close_items
attribute for the Task
endpointContributor
and Key
queue
parameter doesn’t have any effect anymore. Therefore, removed all code and docs related to sync uploading.queued_process = @client.upload_file project_id,
data: 'Base-64 encoded data... ZnI6DQogI...',
filename: 'my_file.yml',
lang_iso: 'en'
queued_process.status # => 'queued'
# ...after some time...
queued_process = queued_process.reload_data
queued_process.status # => 'finished'
QueuedProcess
endpointreload_data
method which fetches new data from the API@client.regenerate_webhook_secret(project_id, webhook_id)
webhook.regenerate_secret
https://api.lokalise.com/api2/
instead of https://api.lokalise.co/api2/
branch.merge params
client.merge_branch project_id, branch_id, params
Branch
endpointWebhook
endpoint (thanks to @snkashis for help!):timeout
and :open_timeout
options for the client to customize request timeoutsTranslationStatus
endpointTeamUserGroup
endpointOrder
, TranslationProvider
, and PaymentCard
endpointsDELETE
requests with bodies. It seems like Faraday team decided to abandon the idea of writing delete request one-liners, so we’ll stick with another approach#delete
interface methods to #destroy
next_page?
, last_page?
, prev_page?
, first_page?
, next_page
, prev_page
)