Skip to content

Commit

Permalink
Version 7.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
bodrovis committed Jan 11, 2023
1 parent 24f7933 commit 07cd1a9
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 25 deletions.
11 changes: 10 additions & 1 deletion docs/additional_info/changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
# Changelog

## 7.1.1 (03-Jan-2022)
## 7.2.0 (11-Jan-2023)

* Updated the `jwt` method. It is now mandatory to provide the project ID to request JWT for:

```ruby
resp = @client.jwt("123.abcd")
resp.jwt # => 'eyJ0eXAiOi...`
```

## 7.1.1 (03-Jan-2023)

* Update dependencies and tests
* Update test matrix
Expand Down
11 changes: 7 additions & 4 deletions docs/api/jwt.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,19 @@

## Get OTA JWT

[Doc](https://developers.lokalise.com/reference/get-ota-jwt)
[Doc](https://developers.lokalise.com/reference/create-service-jwt)

```ruby
@client.jwt # Output:
## A JWT resource
@client.jwt(project_id, params = {}) # Input:
## project_id (string, required)
## params (hash)
# Output:
## A JWT resource
```

For example:

```ruby
resp = @client.jwt
resp = @client.jwt("123.abcd")
resp.jwt # => 'eyJ0eXAiOi...`
```
6 changes: 5 additions & 1 deletion lib/ruby_lokalise_api/resources/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,11 @@ def produce_resource(model_class, response)
data_key_singular = data_key_for model_class: model_class
if content.key? data_key_singular
data = content.delete data_key_singular
content.merge! data
if data.is_a?(Hash)
content.merge! data
else
content[data_key_singular] = data
end
end

new response
Expand Down
4 changes: 2 additions & 2 deletions lib/ruby_lokalise_api/resources/jwt.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ module RubyLokaliseApi
module Resources
class Jwt < Base
class << self
def endpoint(*_args)
path_from 'jwt-tokens': 'ota'
def endpoint(project_id, *_args)
path_from projects: project_id, tokens: ''
end
end
end
Expand Down
6 changes: 3 additions & 3 deletions lib/ruby_lokalise_api/rest/jwt.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ module Rest
module Jwt
# Returns a JWT that can be used to work with OTA
#
# @see https://developers.lokalise.com/reference/get-ota-jwt
# @see https://developers.lokalise.com/reference/create-service-jwt
# @return [RubyLokaliseApi::Resources::Jwt]
def jwt
c_r RubyLokaliseApi::Resources::Jwt, :find, nil, {}
def jwt(project_id, params = {service: :ota})
c_r RubyLokaliseApi::Resources::Jwt, :create, project_id, params
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/ruby_lokalise_api/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module RubyLokaliseApi
VERSION = '7.1.1'
VERSION = '7.2.0'
end
22 changes: 11 additions & 11 deletions spec/fixtures/vcr_cassettes/jwt.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions spec/lib/ruby_lokalise_api/client/jwt_spec.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
# frozen_string_literal: true

RSpec.describe RubyLokaliseApi::Client do
let(:project_id) { '2273827860c1e2473eb195.11207948' }

specify '#jwt' do
resp = VCR.use_cassette('jwt') do
test_client.jwt
test_client.jwt project_id
end

expect(resp).to be_an_instance_of(RubyLokaliseApi::Resources::Jwt)
expect(resp.jwt).to include('eyJ0eXAiOi')
expect(resp.jwt).to include('eyJ0eXAiOiJKV1QiLCJ')
end
end

0 comments on commit 07cd1a9

Please sign in to comment.