Class: Whop_sdk::Users::Preferences::Notifications::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/whop_sdk/users/preferences/notifications/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ void



11
12
13
# File 'lib/whop_sdk/users/preferences/notifications/client.rb', line 11

def initialize(client:)
  @client = client
end

Instance Method Details

#experiencesWhop_sdk::Experiences::Client



67
68
69
# File 'lib/whop_sdk/users/preferences/notifications/client.rb', line 67

def experiences
  @experiences ||= Whop_sdk::Users::Preferences::Notifications::Experiences::Client.new(client: @client)
end

#set(request_options: {}, **params) ⇒ Whop_sdk::Users::Preferences::Notifications::Types::SetNotificationsResponse

Sets the authenticated user's notification preferences. Each preference is addressed by scope, not by id, so a scope read back from either list endpoint can be sent straight here.

A scope naming an experience with no topic sets that experience's level, and accepts all three levels. Any other scope sets a topic override, which is binary — all or nothing — and requires a channel.

level: null clears the preference. Preferences are stored as overrides, so clearing one means the scope inherits its default again rather than being switched off.

The batch is applied in one transaction: if any entry is rejected, none are written. Experience levels are applied before topic overrides, because setting a level replaces every topic preference for that experience — so an override sent alongside a level wins. The response reports what each scope now resolves to, in the order the entries were sent.

Examples:

client.users.preferences.notifications.set(preferences: [{
  scope: {}
}])

Parameters:

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Returns:



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/whop_sdk/users/preferences/notifications/client.rb', line 43

def set(request_options: {}, **params)
  params = Whop_sdk::Internal::Types::Utils.normalize_keys(params)
  request = Whop_sdk::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "PATCH",
    path: "users/me/preferences/notifications",
    body: Whop_sdk::Users::Preferences::Notifications::Types::SetNotificationsRequest.new(params).to_h,
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Whop_sdk::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Whop_sdk::Users::Preferences::Notifications::Types::SetNotificationsResponse.load(response.body)
  else
    error_class = Whop_sdk::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#topicsWhop_sdk::Topics::Client

Returns:

  • (Whop_sdk::Topics::Client)


72
73
74
# File 'lib/whop_sdk/users/preferences/notifications/client.rb', line 72

def topics
  @topics ||= Whop_sdk::Users::Preferences::Notifications::Topics::Client.new(client: @client)
end