Class: RubyLokaliseApi::Endpoints::BaseEndpoint

Inherits:
Object
  • Object
show all
Includes:
Request
Defined in:
lib/ruby_lokalise_api/endpoints/base_endpoint.rb

Direct Known Subclasses

MainEndpoint, OAuth2::OAuth2Endpoint

Constant Summary collapse

BASE_URL =
''
PARTIAL_URI_TEMPLATE =
'{/segments*}'
HTTP_METHODS =
%i[get post put delete patch].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Request

#delete, #get, #patch, #post, #put

Methods included from Connection

#connection

Methods included from JsonHandler

#custom_dump, #custom_load

Constructor Details

#initialize(client, params = {}) ⇒ BaseEndpoint

Returns a new instance of BaseEndpoint.



15
16
17
18
19
20
# File 'lib/ruby_lokalise_api/endpoints/base_endpoint.rb', line 15

def initialize(client, params = {})
  @query_params = params[:query].to_array
  @client = client
  @req_params = params[:req]
  @uri = nil
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



9
10
11
# File 'lib/ruby_lokalise_api/endpoints/base_endpoint.rb', line 9

def client
  @client
end

#req_paramsObject (readonly)

Returns the value of attribute req_params.



9
10
11
# File 'lib/ruby_lokalise_api/endpoints/base_endpoint.rb', line 9

def req_params
  @req_params
end

#uriObject (readonly)

Returns the value of attribute uri.



9
10
11
# File 'lib/ruby_lokalise_api/endpoints/base_endpoint.rb', line 9

def uri
  @uri
end

Instance Method Details

#base_urlObject



30
31
32
# File 'lib/ruby_lokalise_api/endpoints/base_endpoint.rb', line 30

def base_url
  self.class::BASE_URL
end

#full_uriObject



34
35
36
# File 'lib/ruby_lokalise_api/endpoints/base_endpoint.rb', line 34

def full_uri
  base_url + uri.to_s
end

#reinitialize(query_params: nil, req_params: {}) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/ruby_lokalise_api/endpoints/base_endpoint.rb', line 22

def reinitialize(query_params: nil, req_params: {})
  @query_params = query_params || @query_params
  @req_params = req_params || @req_params
  @uri = partial_uri(base_query(*@query_params))

  self
end