ruby-lokalise-api 8.0.0.rc1 → 8.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -0
- data/lib/ruby_lokalise_api/base_client.rb +2 -0
- data/lib/ruby_lokalise_api/client.rb +0 -2
- data/lib/ruby_lokalise_api/concerns/attrs_loadable.rb +1 -0
- data/lib/ruby_lokalise_api/connection.rb +12 -8
- data/lib/ruby_lokalise_api/endpoints/base_endpoint.rb +8 -15
- data/lib/ruby_lokalise_api/oauth2/auth.rb +15 -0
- data/lib/ruby_lokalise_api/oauth2_client.rb +0 -2
- data/lib/ruby_lokalise_api/request.rb +1 -1
- data/lib/ruby_lokalise_api/utils/classes.rb +4 -0
- data/lib/ruby_lokalise_api/utils/keys.rb +4 -0
- data/lib/ruby_lokalise_api/utils/loaders.rb +3 -0
- data/lib/ruby_lokalise_api/version.rb +1 -1
- data/ruby-lokalise-api.gemspec +1 -1
- metadata +7 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b9dd635ba92d1885a962876708929e92b3d4cf27da08281d37d001090b26059e
|
4
|
+
data.tar.gz: 4360d59c199a2f166fc1ea0a7d6cbe767ff9fef1ad4915c7ea432fe96a5520a6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d5dc497254da7a8b9d887f449880a37c5d3ab71054a23d07aac90cdedb27896103b3ed907fda102c0785da068bc50dccce1b8f1723a0a71c78bb9c6896347fb7
|
7
|
+
data.tar.gz: de6153458925151cfd3ee5640d8dbea226877ba89698faf2e6320776340e5dafd37bb62e8297f04377e50918fdaa40c698020aa0f098466a488410f2fb3ffba3
|
data/README.md
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
![Gem](https://img.shields.io/gem/v/ruby-lokalise-api)
|
4
4
|
![CI](https://github.com/lokalise/ruby-lokalise-api/actions/workflows/ci.yml/badge.svg)
|
5
|
+
[![Coverage Status](https://coveralls.io/repos/github/lokalise/ruby-lokalise-api/badge.svg?branch=master)](https://coveralls.io/github/lokalise/ruby-lokalise-api?branch=master)
|
5
6
|
![Downloads total](https://img.shields.io/gem/dt/ruby-lokalise-api)
|
6
7
|
|
7
8
|
Official opinionated Ruby interface for the [Lokalise API](https://developers.lokalise.com/reference/lokalise-rest-api) that represents returned data as Ruby objects.
|
@@ -4,6 +4,8 @@ module RubyLokaliseApi
|
|
4
4
|
# This class contains the base client. Inherited by Client (regular API client)
|
5
5
|
# and OAuth2Client (used for OAuth-2 based authentication)
|
6
6
|
class BaseClient
|
7
|
+
include RubyLokaliseApi::Rest
|
8
|
+
|
7
9
|
attr_reader :token, :token_header
|
8
10
|
attr_accessor :timeout, :open_timeout
|
9
11
|
|
@@ -3,10 +3,9 @@
|
|
3
3
|
module RubyLokaliseApi
|
4
4
|
# Module to setup connection using Faraday
|
5
5
|
module Connection
|
6
|
-
|
7
6
|
# Creates a new Faraday object with specified params
|
8
|
-
def connection(endpoint)
|
9
|
-
Faraday.new(options(endpoint), request_params_for(endpoint.client)) do |faraday|
|
7
|
+
def connection(endpoint, params = {})
|
8
|
+
Faraday.new(options(endpoint, params), request_params_for(endpoint.client)) do |faraday|
|
10
9
|
faraday.adapter Faraday.default_adapter
|
11
10
|
faraday.request(:gzip)
|
12
11
|
end
|
@@ -14,16 +13,21 @@ module RubyLokaliseApi
|
|
14
13
|
|
15
14
|
private
|
16
15
|
|
17
|
-
def options(endpoint)
|
18
|
-
|
16
|
+
def options(endpoint, params)
|
17
|
+
req_params = __base_options(endpoint)
|
19
18
|
client = endpoint.client
|
20
19
|
|
21
20
|
if client.respond_to?(:token) && client.respond_to?(:token_header)
|
22
|
-
|
21
|
+
req_params[:headers][client.token_header] = client.token
|
23
22
|
end
|
24
|
-
params[:headers][:accept_encoding] = 'gzip,deflate,br'
|
25
23
|
|
26
|
-
|
24
|
+
# Sending content-type is needed only when the body is actually present
|
25
|
+
# Trying to send this header in other cases seems to result in error 500
|
26
|
+
req_params[:headers]['Content-type'] = 'application/json' if !params[:get_request] && endpoint.req_params
|
27
|
+
|
28
|
+
req_params[:headers][:accept_encoding] = 'gzip,deflate,br'
|
29
|
+
|
30
|
+
req_params
|
27
31
|
end
|
28
32
|
|
29
33
|
def __base_options(endpoint)
|
@@ -10,6 +10,7 @@ module RubyLokaliseApi
|
|
10
10
|
|
11
11
|
BASE_URL = ''
|
12
12
|
PARTIAL_URI_TEMPLATE = '{/segments*}'
|
13
|
+
HTTP_METHODS = %i[get post put delete patch].freeze
|
13
14
|
|
14
15
|
def initialize(client, params = {})
|
15
16
|
@query_params = params[:query].to_array
|
@@ -34,24 +35,16 @@ module RubyLokaliseApi
|
|
34
35
|
base_url + uri
|
35
36
|
end
|
36
37
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
return true if HTTP_METHODS_REGEXP.match?(method.to_s)
|
43
|
-
|
44
|
-
super
|
45
|
-
end
|
46
|
-
|
47
|
-
def method_missing(method, *_args)
|
48
|
-
if method.to_s =~ HTTP_METHODS_REGEXP
|
49
|
-
send Regexp.last_match(1), self
|
50
|
-
else
|
51
|
-
super
|
38
|
+
# Creates methods like `do_post`, `do_get` that proxy calls to the
|
39
|
+
# corresponding methods in the `Request` module
|
40
|
+
HTTP_METHODS.each do |method_postfix|
|
41
|
+
define_method "do_#{method_postfix}" do
|
42
|
+
send method_postfix, self
|
52
43
|
end
|
53
44
|
end
|
54
45
|
|
46
|
+
private
|
47
|
+
|
55
48
|
def base_query(*_args); end
|
56
49
|
|
57
50
|
def partial_uri(*_args)
|
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
module RubyLokaliseApi
|
4
4
|
module OAuth2
|
5
|
+
# This class defines OAuth2 flow
|
5
6
|
class Auth
|
6
7
|
attr_reader :client_id, :client_secret, :timeout, :open_timeout
|
7
8
|
|
@@ -14,10 +15,17 @@ module RubyLokaliseApi
|
|
14
15
|
@open_timeout = params[:open_timeout]
|
15
16
|
end
|
16
17
|
|
18
|
+
# Returns OAuth2 endpoint URI
|
17
19
|
def oauth2_endpoint
|
18
20
|
self.class.const_get(:OAUTH2_ENDPOINT)
|
19
21
|
end
|
20
22
|
|
23
|
+
# Builds an OAuth2 link that customers have to visit
|
24
|
+
# in order to obtain a special code
|
25
|
+
# @return [String]
|
26
|
+
# @param scope [Array, String]
|
27
|
+
# @param redirect_uri [String]
|
28
|
+
# @param state [String]
|
21
29
|
def auth(scope:, redirect_uri: nil, state: nil)
|
22
30
|
get_params = {
|
23
31
|
client_id: client_id,
|
@@ -29,6 +37,10 @@ module RubyLokaliseApi
|
|
29
37
|
oauth2_endpoint.new(self, query: 'auth', get: get_params).full_uri
|
30
38
|
end
|
31
39
|
|
40
|
+
# Requests OAuth2 access token. Requires OAuth2 code obtained
|
41
|
+
# using the `.auth` method
|
42
|
+
# @return [RubyLokaliseApi::Resources::OAuth2Token]
|
43
|
+
# @param code [String]
|
32
44
|
def token(code)
|
33
45
|
endpoint = oauth2_endpoint.new(
|
34
46
|
self,
|
@@ -42,6 +54,9 @@ module RubyLokaliseApi
|
|
42
54
|
RubyLokaliseApi::Resources::OAuth2Token.new endpoint.do_post
|
43
55
|
end
|
44
56
|
|
57
|
+
# Refreshes expired OAuth2 access token.
|
58
|
+
# @return [RubyLokaliseApi::Resources::OAuth2RefreshedToken]
|
59
|
+
# @param refresh_token [String]
|
45
60
|
def refresh(refresh_token)
|
46
61
|
endpoint = oauth2_endpoint.new(
|
47
62
|
self,
|
@@ -9,7 +9,7 @@ module RubyLokaliseApi
|
|
9
9
|
# Sends a GET request
|
10
10
|
def get(endpoint)
|
11
11
|
respond_with(
|
12
|
-
connection(endpoint).get(prepare(endpoint.uri), endpoint.req_params),
|
12
|
+
connection(endpoint, get_request: true).get(prepare(endpoint.uri), endpoint.req_params),
|
13
13
|
endpoint
|
14
14
|
)
|
15
15
|
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module RubyLokaliseApi
|
4
|
+
# Basic utilitiy methods
|
4
5
|
module Utils
|
5
6
|
module Classes
|
6
7
|
refine Object do
|
@@ -9,10 +10,13 @@ module RubyLokaliseApi
|
|
9
10
|
name.split('::').last
|
10
11
|
end
|
11
12
|
|
13
|
+
# Converts object to array unless it is already an array
|
12
14
|
def to_array
|
13
15
|
is_a?(Array) ? self : [self]
|
14
16
|
end
|
15
17
|
|
18
|
+
# Converts object to array and then places this array
|
19
|
+
# inside hash under the provided key
|
16
20
|
def to_array_obj(key)
|
17
21
|
return self if is_a?(Hash) && (key?(key) || key?(key.to_s))
|
18
22
|
|
@@ -5,6 +5,8 @@ module RubyLokaliseApi
|
|
5
5
|
module Keys
|
6
6
|
using RubyLokaliseApi::Utils::Strings
|
7
7
|
|
8
|
+
# Reads DATA_KEY for resources. DATA_KEY specifies the name of the key
|
9
|
+
# in the API response that contains the actual data
|
8
10
|
def data_key_for(klass:)
|
9
11
|
key = if Module.const_defined? "RubyLokaliseApi::Resources::#{klass}::DATA_KEY"
|
10
12
|
Module.const_get "RubyLokaliseApi::Resources::#{klass}::DATA_KEY"
|
@@ -15,6 +17,8 @@ module RubyLokaliseApi
|
|
15
17
|
key.snakecase
|
16
18
|
end
|
17
19
|
|
20
|
+
# Reads DATA_KEY for collections. DATA_KEY specifies the name of the key
|
21
|
+
# in the API response that contains the actual data
|
18
22
|
def collection_key_for(klass:)
|
19
23
|
key = if Module.const_defined?("RubyLokaliseApi::Collections::#{klass}::DATA_KEY")
|
20
24
|
Module.const_get("RubyLokaliseApi::Collections::#{klass}::DATA_KEY")
|
@@ -5,16 +5,19 @@ module RubyLokaliseApi
|
|
5
5
|
module Loaders
|
6
6
|
private
|
7
7
|
|
8
|
+
# Instantiates an endpoint
|
8
9
|
def endpoint(name:, client: self, params: {})
|
9
10
|
klass = RubyLokaliseApi.const_get "Endpoints::#{name}Endpoint"
|
10
11
|
klass.new client, params
|
11
12
|
end
|
12
13
|
|
14
|
+
# Instantiates a resource
|
13
15
|
def resource(name, data)
|
14
16
|
klass = RubyLokaliseApi.const_get "Resources::#{name}"
|
15
17
|
klass.new data
|
16
18
|
end
|
17
19
|
|
20
|
+
# Instantiates a collection
|
18
21
|
def collection(name, data)
|
19
22
|
klass = RubyLokaliseApi.const_get "Collections::#{name}"
|
20
23
|
klass.new data
|
data/ruby-lokalise-api.gemspec
CHANGED
@@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
|
|
23
23
|
|
24
24
|
spec.add_dependency 'addressable', '~> 2.5'
|
25
25
|
spec.add_dependency 'faraday', '~> 2.0'
|
26
|
-
spec.add_dependency 'faraday-gzip', '
|
26
|
+
spec.add_dependency 'faraday-gzip', '~> 2.0'
|
27
27
|
spec.add_dependency 'json', '~> 2'
|
28
28
|
spec.add_dependency 'zeitwerk', '~> 2.4'
|
29
29
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-lokalise-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 8.0.
|
4
|
+
version: 8.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ilya Krukowski
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-08-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: addressable
|
@@ -42,20 +42,14 @@ dependencies:
|
|
42
42
|
name: faraday-gzip
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '0.1'
|
48
|
-
- - "<"
|
45
|
+
- - "~>"
|
49
46
|
- !ruby/object:Gem::Version
|
50
47
|
version: '2.0'
|
51
48
|
type: :runtime
|
52
49
|
prerelease: false
|
53
50
|
version_requirements: !ruby/object:Gem::Requirement
|
54
51
|
requirements:
|
55
|
-
- - "
|
56
|
-
- !ruby/object:Gem::Version
|
57
|
-
version: '0.1'
|
58
|
-
- - "<"
|
52
|
+
- - "~>"
|
59
53
|
- !ruby/object:Gem::Version
|
60
54
|
version: '2.0'
|
61
55
|
- !ruby/object:Gem::Dependency
|
@@ -399,11 +393,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
399
393
|
version: '2.7'
|
400
394
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
401
395
|
requirements:
|
402
|
-
- - "
|
396
|
+
- - ">="
|
403
397
|
- !ruby/object:Gem::Version
|
404
|
-
version:
|
398
|
+
version: '0'
|
405
399
|
requirements: []
|
406
|
-
rubygems_version: 3.4.
|
400
|
+
rubygems_version: 3.4.18
|
407
401
|
signing_key:
|
408
402
|
specification_version: 4
|
409
403
|
summary: Ruby interface to the Lokalise API
|