-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
198 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# JWT | ||
|
||
## Get OTA JWT | ||
|
||
[Doc](https://developers.lokalise.com/reference/get-ota-jwt) | ||
|
||
```ruby | ||
@client.jwt # Output: | ||
## A JWT resource | ||
``` | ||
|
||
For example: | ||
|
||
```ruby | ||
resp = @client.jwt | ||
resp.jwt # => 'eyJ0eXAiOi...` | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# frozen_string_literal: true | ||
|
||
module RubyLokaliseApi | ||
class BaseClient | ||
attr_reader :token, :token_header | ||
attr_accessor :timeout, :open_timeout | ||
|
||
def initialize(token, params = {}) | ||
@token = token | ||
@timeout = params.fetch(:timeout, nil) | ||
@open_timeout = params.fetch(:open_timeout, nil) | ||
@token_header = '' | ||
end | ||
|
||
# rubocop:disable Metrics/ParameterLists | ||
# Constructs request to perform the specified action | ||
# @param klass The actual class to call the method upon | ||
# @param method [Symbol] The method to call (:new, :update, :create etc) | ||
# @param endpoint_ids [Array, Hash] IDs that are used to generate the proper path to the endpoint | ||
# @param params [Array, Hash] Request parameters | ||
# @param object_key [String, Symbol] Key that should be used to wrap parameters into | ||
# @param initial_ids [Array] IDs that should be used to generate base endpoint path. | ||
# The base path is used for method chaining | ||
def construct_request(klass, method, endpoint_ids, params = {}, object_key = nil, initial_ids = nil) | ||
path = klass.endpoint(*endpoint_ids) | ||
formatted_params = format_params(params, object_key) | ||
formatted_params[:_initial_path] = klass.endpoint(*initial_ids) if initial_ids | ||
klass.send method, self, path, formatted_params | ||
end | ||
# rubocop:enable Metrics/ParameterLists | ||
|
||
# Converts `params` to hash with arrays under the `object_key` key. | ||
# Used in bulk operations | ||
# | ||
# @return [Hash] | ||
def format_params(params, object_key) | ||
return params unless object_key | ||
|
||
params = [params] unless params.is_a?(Array) | ||
{object_key => params} | ||
end | ||
|
||
def base_url; end | ||
|
||
def compression?; end | ||
|
||
alias c_r construct_request | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,8 @@ custom_translation_status: | |
file: | ||
- filename | ||
- key_count | ||
jwt: | ||
- jwt | ||
key: | ||
- key_id | ||
- created_at | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# frozen_string_literal: true | ||
|
||
module RubyLokaliseApi | ||
module Resources | ||
class Jwt < Base | ||
class << self | ||
def endpoint(*_args) | ||
path_from 'jwt-tokens': 'ota' | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# frozen_string_literal: true | ||
|
||
module RubyLokaliseApi | ||
module Rest | ||
module Jwt | ||
# Returns a JWT that can be used to work with OTA | ||
# | ||
# @see https://developers.lokalise.com/reference/get-ota-jwt | ||
# @return [RubyLokaliseApi::Resources::Jwt] | ||
def jwt | ||
c_r RubyLokaliseApi::Resources::Jwt, :find, nil, {} | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
module RubyLokaliseApi | ||
VERSION = '7.0.0' | ||
VERSION = '7.1.0' | ||
end |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# frozen_string_literal: true | ||
|
||
RSpec.describe RubyLokaliseApi::Client do | ||
specify '#jwt' do | ||
resp = VCR.use_cassette('jwt') do | ||
test_client.jwt | ||
end | ||
|
||
expect(resp).to be_an_instance_of(RubyLokaliseApi::Resources::Jwt) | ||
expect(resp.jwt).to include('eyJ0eXAiOi') | ||
end | ||
end |