Class: RubyLokaliseApi::BaseClient
- Inherits:
-
Object
- Object
- RubyLokaliseApi::BaseClient
- Defined in:
- lib/ruby_lokalise_api/base_client.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#open_timeout ⇒ Object
Returns the value of attribute open_timeout.
-
#timeout ⇒ Object
Returns the value of attribute timeout.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
-
#token_header ⇒ Object
readonly
Returns the value of attribute token_header.
Instance Method Summary collapse
- #base_url ⇒ Object
- #compression? ⇒ Boolean
-
#construct_request(klass, method, endpoint_ids, params = {}, object_key = nil, initial_ids = nil) ⇒ Object
(also: #c_r)
rubocop:disable Metrics/ParameterLists Constructs request to perform the specified action The base path is used for method chaining.
-
#format_params(params, object_key) ⇒ Hash
Converts ‘params` to hash with arrays under the `object_key` key.
-
#initialize(token, params = {}) ⇒ BaseClient
constructor
A new instance of BaseClient.
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_timeout ⇒ Object
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 |
#timeout ⇒ Object
Returns the value of attribute timeout.
6 7 8 |
# File 'lib/ruby_lokalise_api/base_client.rb', line 6 def timeout @timeout end |
#token ⇒ Object (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_header ⇒ Object (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_url ⇒ Object
43 |
# File 'lib/ruby_lokalise_api/base_client.rb', line 43 def base_url; end |
#compression? ⇒ 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
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
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 |