lib/ruby_lokalise_api/client.rb in ruby-lokalise-api-7.0.0 vs lib/ruby_lokalise_api/client.rb in ruby-lokalise-api-7.1.0
- old
+ new
@@ -1,14 +1,15 @@
# frozen_string_literal: true
module RubyLokaliseApi
- class Client
+ class Client < BaseClient
include RubyLokaliseApi::Rest::Branches
include RubyLokaliseApi::Rest::Comments
include RubyLokaliseApi::Rest::Contributors
include RubyLokaliseApi::Rest::CustomTranslationStatuses
include RubyLokaliseApi::Rest::Files
+ include RubyLokaliseApi::Rest::Jwt
include RubyLokaliseApi::Rest::Keys
include RubyLokaliseApi::Rest::Languages
include RubyLokaliseApi::Rest::Orders
include RubyLokaliseApi::Rest::PaymentCards
include RubyLokaliseApi::Rest::Projects
@@ -23,54 +24,20 @@
include RubyLokaliseApi::Rest::Teams
include RubyLokaliseApi::Rest::TranslationProviders
include RubyLokaliseApi::Rest::Translations
include RubyLokaliseApi::Rest::Webhooks
- 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)
+ super(token, params)
+
@token_header = 'x-api-token'
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
'https://api.lokalise.com/api2/'
end
def compression?
true
end
-
- alias c_r construct_request
end
end