Class: Courier::Resources::Users::Tenants

Inherits:
Object
  • Object
show all
Defined in:
lib/courier/resources/users/tenants.rb,
sig/courier/resources/users/tenants.rbs

Overview

Associate a user with one or more tenants, and read or remove those associations.

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Tenants

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Tenants.

Parameters:



148
149
150
# File 'lib/courier/resources/users/tenants.rb', line 148

def initialize(client:)
  @client = client
end

Instance Method Details

#add_multiple(user_id, tenants:, request_options: {}) ⇒ nil

Adds a user to several tenants in one call, each optionally with a per-tenant profile that overrides their workspace profile.

Parameters:

Returns:

  • (nil)

See Also:



54
55
56
57
58
59
60
61
62
63
# File 'lib/courier/resources/users/tenants.rb', line 54

def add_multiple(user_id, params)
  parsed, options = Courier::Users::TenantAddMultipleParams.dump_request(params)
  @client.request(
    method: :put,
    path: ["users/%1$s/tenants", user_id],
    body: parsed,
    model: NilClass,
    options: options
  )
end

#add_single(tenant_id, user_id:, profile: nil, request_options: {}) ⇒ nil

Adds a user to one tenant, optionally with a tenant-specific profile that overrides their workspace profile for sends in that tenant.

Parameters:

  • tenant_id (String)

    Path param: Id of the tenant the user should be added to.

  • user_id (String)

    Path param: Id of the user to be added to the supplied tenant.

  • profile (Hash{Symbol=>Object}, nil)

    Body param

  • request_options (Courier::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

  • (nil)

See Also:



81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/courier/resources/users/tenants.rb', line 81

def add_single(tenant_id, params)
  parsed, options = Courier::Users::TenantAddSingleParams.dump_request(params)
  user_id =
    parsed.delete(:user_id) do
      raise ArgumentError.new("missing required path argument #{_1}")
    end
  @client.request(
    method: :put,
    path: ["users/%1$s/tenants/%2$s", user_id, tenant_id],
    body: parsed,
    model: NilClass,
    options: options
  )
end

#list(user_id, cursor: nil, limit: nil, request_options: {}) ⇒ Courier::Models::Users::TenantListResponse

Some parameter documentations has been truncated, see Models::Users::TenantListParams for more details.

Returns the tenants a user belongs to, with cursor paging. A user can belong to many tenants, each with its own profile and preferences.

Parameters:

  • user_id (String)

    Id of the user to retrieve all associated tenants for.

  • cursor (String, nil)

    Continue the pagination with the next cursor

  • limit (Integer, nil)

    The number of accounts to return

  • request_options (Courier::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/courier/resources/users/tenants.rb', line 28

def list(user_id, params = {})
  parsed, options = Courier::Users::TenantListParams.dump_request(params)
  query = Courier::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :get,
    path: ["users/%1$s/tenants", user_id],
    query: query,
    model: Courier::Models::Users::TenantListResponse,
    options: options
  )
end

#remove_all(user_id, request_options: {}) ⇒ nil

Removes a user from every tenant they belong to in one call. Their workspace-level profile is a separate resource.

Parameters:

  • user_id (String)

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

  • request_options (Courier::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

  • (nil)

See Also:



108
109
110
111
112
113
114
115
# File 'lib/courier/resources/users/tenants.rb', line 108

def remove_all(user_id, params = {})
  @client.request(
    method: :delete,
    path: ["users/%1$s/tenants", user_id],
    model: NilClass,
    options: params[:request_options]
  )
end

#remove_single(tenant_id, user_id:, request_options: {}) ⇒ nil

Removes a user from one tenant. Their other tenant memberships and workspace profile are managed through separate endpoints.

Parameters:

  • tenant_id (String)

    Id of the tenant the user should be removed from.

  • user_id (String)

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

  • request_options (Courier::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

  • (nil)

See Also:



131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/courier/resources/users/tenants.rb', line 131

def remove_single(tenant_id, params)
  parsed, options = Courier::Users::TenantRemoveSingleParams.dump_request(params)
  user_id =
    parsed.delete(:user_id) do
      raise ArgumentError.new("missing required path argument #{_1}")
    end
  @client.request(
    method: :delete,
    path: ["users/%1$s/tenants/%2$s", user_id, tenant_id],
    model: NilClass,
    options: options
  )
end