Class: Courier::AsyncTranslationsClient

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:) ⇒ AsyncTranslationsClient

Parameters:



60
61
62
63
# File 'lib/trycourier/translations/client.rb', line 60

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

Instance Attribute Details

#request_clientObject (readonly)

Returns the value of attribute request_client.



56
57
58
# File 'lib/trycourier/translations/client.rb', line 56

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)


71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/trycourier/translations/client.rb', line 71

def get(domain:, locale:, request_options: nil)
  Async do
    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
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)


92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/trycourier/translations/client.rb', line 92

def update(domain:, locale:, request:, request_options: nil)
  Async do
    @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
end