Class: Courier::TranslationsClient

Inherits:
Object
  • Object
show all
Defined in:
lib/trycourier/translations/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request_client:) ⇒ TranslationsClient

Parameters:



12
13
14
15
# File 'lib/trycourier/translations/client.rb', line 12

def initialize(request_client:)
  # @type [RequestClient]
  @request_client = request_client
end

Instance Attribute Details

#request_clientObject (readonly)

Returns the value of attribute request_client.



8
9
10
# File 'lib/trycourier/translations/client.rb', line 8

def request_client
  @request_client
end

Instance Method Details

#get(domain:, locale:, request_options: nil) ⇒ String

Get translations by locale

Parameters:

  • domain (String)

    The domain you want to retrieve translations for. Only ‘default` is supported at the moment

  • locale (String)

    The locale you want to retrieve the translations for

  • request_options (RequestOptions) (defaults to: nil)

Returns:

  • (String)


23
24
25
26
27
28
29
30
31
32
33
# File 'lib/trycourier/translations/client.rb', line 23

def get(domain:, locale:, request_options: nil)
  response = @request_client.conn.get("/translations/#{domain}/#{locale}") do |req|
    req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
    unless request_options&.authorization_token.nil?
      req.headers["Authorization"] =
        request_options.authorization_token
    end
    req.headers = { **req.headers, **(request_options&.additional_headers || {}) }.compact
  end
  response.body
end

#update(domain:, locale:, request:, request_options: nil) ⇒ Void

Update a translation

Parameters:

  • domain (String)

    The domain you want to retrieve translations for. Only ‘default` is supported at the moment

  • locale (String)

    The locale you want to retrieve the translations for

  • request (String)

    .po file translation content

  • request_options (RequestOptions) (defaults to: nil)

Returns:

  • (Void)


42
43
44
45
46
47
48
49
50
51
52
# File 'lib/trycourier/translations/client.rb', line 42

def update(domain:, locale:, request:, request_options: nil)
  @request_client.conn.put("/translations/#{domain}/#{locale}") do |req|
    req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
    unless request_options&.authorization_token.nil?
      req.headers["Authorization"] =
        request_options.authorization_token
    end
    req.headers = { **req.headers, **(request_options&.additional_headers || {}) }.compact
    req.body = { **(request || {}), **(request_options&.additional_body_parameters || {}) }.compact
  end
end