Class: Courier::TenantsClient

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

Parameters:



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

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

Instance Attribute Details

#request_clientObject (readonly)

Returns the value of attribute request_client.



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

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:



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/trycourier/tenants/client.rb', line 32

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

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


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

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

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



57
58
59
60
61
62
63
64
65
66
67
# File 'lib/trycourier/tenants/client.rb', line 57

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

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



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/trycourier/tenants/client.rb', line 111

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

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



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/trycourier/tenants/client.rb', line 74

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