Class: Courier::Users::TenantsClient

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::TenantsClient

Parameters:



16
17
18
19
# File 'lib/trycourier/users/tenants/client.rb', line 16

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

Instance Attribute Details

#request_clientObject (readonly)

Returns the value of attribute request_client.



12
13
14
# File 'lib/trycourier/users/tenants/client.rb', line 12

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)


63
64
65
66
67
68
69
70
71
72
73
# File 'lib/trycourier/users/tenants/client.rb', line 63

def add(user_id:, tenant_id:, profile:, request_options: nil)
  @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

#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)


35
36
37
38
39
40
41
42
43
44
45
# File 'lib/trycourier/users/tenants/client.rb', line 35

def add_multple(user_id:, tenants:, request_options: nil)
  @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

#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:



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/trycourier/users/tenants/client.rb', line 116

def list(user_id:, limit: nil, cursor: nil, request_options: nil)
  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

#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)


97
98
99
100
101
102
103
104
105
106
# File 'lib/trycourier/users/tenants/client.rb', line 97

def remove(user_id:, tenant_id:, request_options: nil)
  @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

#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)


80
81
82
83
84
85
86
87
88
89
# File 'lib/trycourier/users/tenants/client.rb', line 80

def remove_all(user_id:, request_options: nil)
  @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