Class: Courier::AsyncTenantsClient

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request_client:) ⇒ AsyncTenantsClient

Parameters:



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

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

Instance Attribute Details

#request_clientObject (readonly)

Returns the value of attribute request_client.



130
131
132
# File 'lib/trycourier/tenants/client.rb', line 130

def request_client
  @request_client
end

Instance Method Details

#create_or_replace(tenant_id:, name:, parent_tenant_id: nil, default_preferences: nil, properties: nil, user_profile: nil, brand_id: nil, request_options: nil) ⇒ Tenants::Tenant

Parameters:

  • tenant_id (String)

    A unique identifier representing the tenant to be returned.

  • name (String)

    Name of the tenant.

  • parent_tenant_id (String) (defaults to: nil)

    Tenant’s parent id (if any).

  • default_preferences (Hash) (defaults to: nil)

    Defines the preferences used for the tenant when the user hasn’t specified their own.Request of type Tenants::DefaultPreferences, as a Hash

    • :items (Array<Tenants::SubscriptionTopic>)

  • properties (Array<Tenants::TEMPLATE_PROPERTY>) (defaults to: nil)

    Arbitrary properties accessible to a template.

  • user_profile (Hash{String => String}) (defaults to: nil)

    A user profile object merged with user profile on send.

  • brand_id (String) (defaults to: nil)

    Brand to be used for the account when one is not specified by the send call.

  • request_options (RequestOptions) (defaults to: nil)

Returns:



149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# File 'lib/trycourier/tenants/client.rb', line 149

def create_or_replace(tenant_id:, name:, parent_tenant_id: nil, default_preferences: nil, properties: nil,
                      user_profile: nil, brand_id: nil, request_options: nil)
  Async do
    response = @request_client.conn.put("/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 || {}),
        name: name,
        parent_tenant_id: parent_tenant_id,
        default_preferences: default_preferences,
        properties: properties,
        user_profile: ,
        brand_id: brand_id
      }.compact
    end
    Tenants::Tenant.from_json(json_object: response.body)
  end
end

#delete(tenant_id:, request_options: nil) ⇒ Void

Parameters:

  • tenant_id (String)

    Id of the tenant to be deleted.

  • request_options (RequestOptions) (defaults to: nil)

Returns:

  • (Void)


217
218
219
220
221
222
223
224
225
226
227
228
# File 'lib/trycourier/tenants/client.rb', line 217

def delete(tenant_id:, request_options: nil)
  Async do
    @request_client.conn.delete("/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

#get(tenant_id:, request_options: nil) ⇒ Tenants::Tenant

Parameters:

  • tenant_id (String)

    A unique identifier representing the tenant to be returned.

  • request_options (RequestOptions) (defaults to: nil)

Returns:



176
177
178
179
180
181
182
183
184
185
186
187
188
# File 'lib/trycourier/tenants/client.rb', line 176

def get(tenant_id:, request_options: nil)
  Async do
    response = @request_client.conn.get("/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
    Tenants::Tenant.from_json(json_object: response.body)
  end
end

#get_users_by_tenant(tenant_id:, limit: nil, cursor: nil, request_options: nil) ⇒ Tenants::ListUsersForTenantResponse

Parameters:

  • tenant_id (String)

    Id of the tenant for user membership.

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



236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
# File 'lib/trycourier/tenants/client.rb', line 236

def get_users_by_tenant(tenant_id:, limit: nil, cursor: nil, request_options: nil)
  Async do
    response = @request_client.conn.get("/tenants/#{tenant_id}/users") 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
    Tenants::ListUsersForTenantResponse.from_json(json_object: response.body)
  end
end

#list(limit: nil, cursor: nil, request_options: nil) ⇒ Tenants::TenantListResponse

Parameters:

  • limit (Integer) (defaults to: nil)

    The number of accousnts 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:



195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
# File 'lib/trycourier/tenants/client.rb', line 195

def list(limit: nil, cursor: nil, request_options: nil)
  Async do
    response = @request_client.conn.get("/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
    Tenants::TenantListResponse.from_json(json_object: response.body)
  end
end