Class: Courier::Users::AsyncTenantsClient

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request_client:) ⇒ Users::AsyncTenantsClient

Parameters:



139
140
141
142
# File 'lib/trycourier/users/tenants/client.rb', line 139

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

Instance Attribute Details

#request_clientObject (readonly)

Returns the value of attribute request_client.



135
136
137
# File 'lib/trycourier/users/tenants/client.rb', line 135

def request_client
  @request_client
end

Instance Method Details

#add(user_id:, tenant_id:, profile:, request_options: nil) ⇒ Void

This endpoint is used to add a single tenant.

A custom profile can also be supplied with the tenant. This profile will be merged with the user’s main profile when sending to the user with that tenant.

Parameters:

  • user_id (String)

    Id of the user to be added to the supplied tenant.

  • tenant_id (String)

    Id of the tenant the user should be added to.

  • profile (Hash)

    Request of type Users::Tenants::AddUserToSingleTenantsParamsProfile, as a Hash

    • :title (String)

    • :email (String)

    • :phone_number (String)

    • :locale (String)

    • :additional_fields (Hash=> String)

  • request_options (RequestOptions) (defaults to: nil)

Returns:

  • (Void)


188
189
190
191
192
193
194
195
196
197
198
199
200
# File 'lib/trycourier/users/tenants/client.rb', line 188

def add(user_id:, tenant_id:, profile:, request_options: nil)
  Async do
    @request_client.conn.put("/users/#{user_id}/tenants/#{tenant_id}") 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_options&.additional_body_parameters || {}), profile: profile }.compact
    end
  end
end

#add_multple(user_id:, tenants:, request_options: nil) ⇒ Void

This endpoint is used to add a user to multiple tenants in one call. A custom profile can also be supplied for each tenant. This profile will be merged with the user’s main profile when sending to the user with that tenant.

Parameters:

  • user_id (String)

    The user’s ID. This can be any uniquely identifiable string.

  • tenants (Array<Hash>)

    Request of type Array<Commons::UserTenantAssociation>, as a Hash

    • :user_id (String)

    • :type (String)

    • :tenant_id (String)

    • :profile (Hash=> String)

  • request_options (RequestOptions) (defaults to: nil)

Returns:

  • (Void)


158
159
160
161
162
163
164
165
166
167
168
169
170
# File 'lib/trycourier/users/tenants/client.rb', line 158

def add_multple(user_id:, tenants:, request_options: nil)
  Async do
    @request_client.conn.put("/users/#{user_id}/tenants") 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_options&.additional_body_parameters || {}), tenants: tenants }.compact
    end
  end
end

#list(user_id:, limit: nil, cursor: nil, request_options: nil) ⇒ Users::Tenants::ListTenantsForUserResponse

Returns a paginated list of user tenant associations.

Parameters:

  • user_id (String)

    Id of the user to retrieve all associated tenants for.

  • limit (Integer) (defaults to: nil)

    The number of accounts to return (defaults to 20, maximum value of 100)

  • cursor (String) (defaults to: nil)

    Continue the pagination with the next cursor

  • request_options (RequestOptions) (defaults to: nil)

Returns:



247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
# File 'lib/trycourier/users/tenants/client.rb', line 247

def list(user_id:, limit: nil, cursor: nil, request_options: nil)
  Async do
    response = @request_client.conn.get("/users/#{user_id}/tenants") 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.params = {
        **(request_options&.additional_query_parameters || {}),
        "limit": limit,
        "cursor": cursor
      }.compact
    end
    Users::Tenants::ListTenantsForUserResponse.from_json(json_object: response.body)
  end
end

#remove(user_id:, tenant_id:, request_options: nil) ⇒ Void

Removes a user from the supplied tenant.

Parameters:

  • user_id (String)

    Id of the user to be removed from the supplied tenant.

  • tenant_id (String)

    Id of the tenant the user should be removed from.

  • request_options (RequestOptions) (defaults to: nil)

Returns:

  • (Void)


226
227
228
229
230
231
232
233
234
235
236
237
# File 'lib/trycourier/users/tenants/client.rb', line 226

def remove(user_id:, tenant_id:, request_options: nil)
  Async do
    @request_client.conn.delete("/users/#{user_id}/tenants/#{tenant_id}") 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
  end
end

#remove_all(user_id:, request_options: nil) ⇒ Void

Removes a user from any tenants they may have been associated with.

Parameters:

  • user_id (String)

    Id of the user to be removed from the supplied tenant.

  • request_options (RequestOptions) (defaults to: nil)

Returns:

  • (Void)


207
208
209
210
211
212
213
214
215
216
217
218
# File 'lib/trycourier/users/tenants/client.rb', line 207

def remove_all(user_id:, request_options: nil)
  Async do
    @request_client.conn.delete("/users/#{user_id}/tenants") 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
  end
end