ruby-lokalise-api 8.0.0 → 9.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 95932448d2e531abc5dc2f30a4b7f1052fa9ba7b37a80e57a46117ac7102c453
4
- data.tar.gz: d5101a2713268265021177c3bcb1eaa1adcfaaa2afe605d87747d55a5c4a6ec0
3
+ metadata.gz: 33c8b8383d4e08130e6a27af7bf66d512d4db1546e3b572f9860a67c4c280281
4
+ data.tar.gz: a6a2bdbd9ad4f394a32b725135c1327e64ffa82cddcb2523d4d1f166932d7d73
5
5
  SHA512:
6
- metadata.gz: 64d290aa2c9844f3e8db8099968104845f7f7b7a52c96843b7f400124819031c3021acec02a318004079548b2666e3253cae845d447825cb5acf04d7cee43234
7
- data.tar.gz: f2790492035aa26cd353372008fe8b4d41cecd47382700ec339e57d443cb5e637be24dc299ea7a1c9898f5c2446722a5709e79e684c081b1ee730d595788fb5e
6
+ metadata.gz: 3f68a55a77660fb86e4b4ba138f9092afeaf12462865dbd6fb72efe773593428667348c887b297af44896fcbad4272fd02e19016708b5570c90fb95a3e68b182
7
+ data.tar.gz: e7359331fe700fe781cf16de68cc9d44d143e96eb43cf6ab4b5d250eb3b2be52bb23c738ba9548d7fbe298895fdc688cb0b7c06f2cbda38049ca83e8f7c944a1
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,8 +3,6 @@
3
3
  module RubyLokaliseApi
4
4
  # Regular API client used to perform requests with a basic API token
5
5
  class Client < BaseClient
6
- include RubyLokaliseApi::Rest
7
-
8
6
  def initialize(token, params = {})
9
7
  super(token, params)
10
8
 
@@ -4,8 +4,8 @@ module RubyLokaliseApi
4
4
  # Module to setup connection using Faraday
5
5
  module Connection
6
6
  # Creates a new Faraday object with specified params
7
- def connection(endpoint)
8
- 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|
9
9
  faraday.adapter Faraday.default_adapter
10
10
  faraday.request(:gzip)
11
11
  end
@@ -13,16 +13,21 @@ module RubyLokaliseApi
13
13
 
14
14
  private
15
15
 
16
- def options(endpoint)
17
- params = __base_options(endpoint)
16
+ def options(endpoint, params)
17
+ req_params = __base_options(endpoint)
18
18
  client = endpoint.client
19
19
 
20
20
  if client.respond_to?(:token) && client.respond_to?(:token_header)
21
- params[:headers][client.token_header] = client.token
21
+ req_params[:headers][client.token_header] = client.token
22
22
  end
23
- params[:headers][:accept_encoding] = 'gzip,deflate,br'
24
23
 
25
- params
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
26
31
  end
27
32
 
28
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
- private
38
-
39
- HTTP_METHODS_REGEXP = /\Ado_(get|post|put|delete|patch)\z/.freeze
40
-
41
- def respond_to_missing?(method, _include_all)
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)
@@ -3,8 +3,6 @@
3
3
  module RubyLokaliseApi
4
4
  # Client used to perform API requests with an OAuth2 access token
5
5
  class OAuth2Client < Client
6
- include RubyLokaliseApi::Rest
7
-
8
6
  def initialize(token, params = {})
9
7
  super(token, params)
10
8
  @token_header = 'Authorization'
@@ -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,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RubyLokaliseApi
4
- VERSION = '8.0.0'
4
+ VERSION = '9.0.0'
5
5
  end
@@ -12,7 +12,7 @@ Gem::Specification.new do |spec|
12
12
  spec.homepage = 'https://github.com/lokalise/ruby-lokalise-api'
13
13
  spec.license = 'BSD-3-Clause'
14
14
  spec.platform = Gem::Platform::RUBY
15
- spec.required_ruby_version = '>= 2.7'
15
+ spec.required_ruby_version = '>= 3.0'
16
16
 
17
17
  spec.files = Dir['README.md', 'LICENSE',
18
18
  'CHANGELOG.md', 'lib/**/*.rb', 'lib/ruby_lokalise_api/data/*.yml',
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.0
4
+ version: 9.0.0
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-07-21 00:00:00.000000000 Z
11
+ date: 2023-11-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -390,14 +390,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
390
390
  requirements:
391
391
  - - ">="
392
392
  - !ruby/object:Gem::Version
393
- version: '2.7'
393
+ version: '3.0'
394
394
  required_rubygems_version: !ruby/object:Gem::Requirement
395
395
  requirements:
396
396
  - - ">="
397
397
  - !ruby/object:Gem::Version
398
398
  version: '0'
399
399
  requirements: []
400
- rubygems_version: 3.4.17
400
+ rubygems_version: 3.4.21
401
401
  signing_key:
402
402
  specification_version: 4
403
403
  summary: Ruby interface to the Lokalise API