Class: RubyLokaliseApi::BaseClient

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_lokalise_api/base_client.rb

Direct Known Subclasses

Client

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(token, params = {}) ⇒ BaseClient

Returns a new instance of BaseClient.



8
9
10
11
12
13
# File 'lib/ruby_lokalise_api/base_client.rb', line 8

def initialize(token, params = {})
  @token = token
  @timeout = params.fetch(:timeout, nil)
  @open_timeout = params.fetch(:open_timeout, nil)
  @token_header = ''
end

Instance Attribute Details

#open_timeoutObject

Returns the value of attribute open_timeout.



6
7
8
# File 'lib/ruby_lokalise_api/base_client.rb', line 6

def open_timeout
  @open_timeout
end

#timeoutObject

Returns the value of attribute timeout.



6
7
8
# File 'lib/ruby_lokalise_api/base_client.rb', line 6

def timeout
  @timeout
end

#tokenObject (readonly)

Returns the value of attribute token.



5
6
7
# File 'lib/ruby_lokalise_api/base_client.rb', line 5

def token
  @token
end

#token_headerObject (readonly)

Returns the value of attribute token_header.



5
6
7
# File 'lib/ruby_lokalise_api/base_client.rb', line 5

def token_header
  @token_header
end

Instance Method Details

#base_urlObject



43
# File 'lib/ruby_lokalise_api/base_client.rb', line 43

def base_url; end

#compression?Boolean

Returns:

  • (Boolean)


45
# File 'lib/ruby_lokalise_api/base_client.rb', line 45

def compression?; end

#construct_request(klass, method, endpoint_ids, params = {}, object_key = nil, initial_ids = nil) ⇒ Object Also known as: c_r

rubocop:disable Metrics/ParameterLists Constructs request to perform the specified action The base path is used for method chaining

Parameters:

  • klass

    The actual class to call the method upon

  • method (Symbol)

    The method to call (:new, :update, :create etc)

  • endpoint_ids (Array, Hash)

    IDs that are used to generate the proper path to the endpoint

  • params (Array, Hash) (defaults to: {})

    Request parameters

  • object_key (String, Symbol) (defaults to: nil)

    Key that should be used to wrap parameters into

  • initial_ids (Array) (defaults to: nil)

    IDs that should be used to generate base endpoint path.



24
25
26
27
28
29
# File 'lib/ruby_lokalise_api/base_client.rb', line 24

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

#format_params(params, object_key) ⇒ Hash

Converts ‘params` to hash with arrays under the `object_key` key. Used in bulk operations

Returns:

  • (Hash)


36
37
38
39
40
41
# File 'lib/ruby_lokalise_api/base_client.rb', line 36

def format_params(params, object_key)
  return params unless object_key

  params = [params] unless params.is_a?(Array)
  {object_key => params}
end