ruby-lokalise-api 8.0.0 → 8.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 95932448d2e531abc5dc2f30a4b7f1052fa9ba7b37a80e57a46117ac7102c453
4
- data.tar.gz: d5101a2713268265021177c3bcb1eaa1adcfaaa2afe605d87747d55a5c4a6ec0
3
+ metadata.gz: b9dd635ba92d1885a962876708929e92b3d4cf27da08281d37d001090b26059e
4
+ data.tar.gz: 4360d59c199a2f166fc1ea0a7d6cbe767ff9fef1ad4915c7ea432fe96a5520a6
5
5
  SHA512:
6
- metadata.gz: 64d290aa2c9844f3e8db8099968104845f7f7b7a52c96843b7f400124819031c3021acec02a318004079548b2666e3253cae845d447825cb5acf04d7cee43234
7
- data.tar.gz: f2790492035aa26cd353372008fe8b4d41cecd47382700ec339e57d443cb5e637be24dc299ea7a1c9898f5c2446722a5709e79e684c081b1ee730d595788fb5e
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,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 = '8.0.1'
5
5
  end
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: 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-07-21 00:00:00.000000000 Z
11
+ date: 2023-08-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -397,7 +397,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
397
397
  - !ruby/object:Gem::Version
398
398
  version: '0'
399
399
  requirements: []
400
- rubygems_version: 3.4.17
400
+ rubygems_version: 3.4.18
401
401
  signing_key:
402
402
  specification_version: 4
403
403
  summary: Ruby interface to the Lokalise API