Class: Whop_sdk::Notifications::Client
- Inherits:
-
Object
- Object
- Whop_sdk::Notifications::Client
- Defined in:
- lib/whop_sdk/notifications/client.rb
Instance Method Summary collapse
-
#badges(request_options: {}, **params) ⇒ Whop_sdk::Notifications::Types::BadgesNotificationsResponse
Lists the authenticated user's per-experience unread badge state.
-
#create(request_options: {}, **params) ⇒ Whop_sdk::Notifications::Types::CreateNotificationsResponse
Queues a notification to every user of an experience or to an account's team, processed asynchronously.
- #initialize(client:) ⇒ void constructor
-
#list(request_options: {}, **params) ⇒ Whop_sdk::Notifications::Types::ListNotificationsResponse
Lists the authenticated user's notifications, newest first.
-
#mark_read(request_options: {}, **params) ⇒ Whop_sdk::Notifications::Types::MarkReadNotificationsResponse
Marks the authenticated user's notifications as read: one experience's (
experience_id) or everything (all: true) — exactly one of the two. -
#retrieve(request_options: {}, **params) ⇒ Whop_sdk::Types::Notification
Retrieves a single notification by id — either an
idreturned by List Notifications, or the ephemeral id delivered with a push/websocket event. - #topics ⇒ Whop_sdk::Topics::Client
Constructor Details
#initialize(client:) ⇒ void
9 10 11 |
# File 'lib/whop_sdk/notifications/client.rb', line 9 def initialize(client:) @client = client end |
Instance Method Details
#badges(request_options: {}, **params) ⇒ Whop_sdk::Notifications::Types::BadgesNotificationsResponse
Lists the authenticated user's per-experience unread badge state. Requires a user credential. Returns one row per experience the user belongs to (or per requested experience).
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/whop_sdk/notifications/client.rb', line 133 def badges(request_options: {}, **params) params = Whop_sdk::Internal::Types::Utils.normalize_keys(params) query_params = {} query_params["experience_ids"] = params[:experience_ids] if params.key?(:experience_ids) query_params["last_fetched_at"] = params[:last_fetched_at] if params.key?(:last_fetched_at) request = Whop_sdk::Internal::JSON::Request.new( base_url: [:base_url], method: "GET", path: "notifications/badges", query: query_params, 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::Notifications::Types::BadgesNotificationsResponse.load(response.body) else error_class = Whop_sdk::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#create(request_options: {}, **params) ⇒ Whop_sdk::Notifications::Types::CreateNotificationsResponse
Queues a notification to every user of an experience or to an account's team, processed asynchronously. Every
send is attributed to an app: use an app API key, or a credential acting on behalf of an app. Narrow the
audience with user_ids to send a mention.
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/whop_sdk/notifications/client.rb', line 93 def create(request_options: {}, **params) params = Whop_sdk::Internal::Types::Utils.normalize_keys(params) request = Whop_sdk::Internal::JSON::Request.new( base_url: [:base_url], method: "POST", path: "notifications", body: Whop_sdk::Notifications::Types::CreateNotificationsRequest.new(params).to_h, 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::Notifications::Types::CreateNotificationsResponse.load(response.body) else error_class = Whop_sdk::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#list(request_options: {}, **params) ⇒ Whop_sdk::Notifications::Types::ListNotificationsResponse
Lists the authenticated user's notifications, newest first. Requires a user credential — an account API key has no notification feed. Without filters the feed spans every experience the user belongs to plus the teams they are a member of.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/whop_sdk/notifications/client.rb', line 35 def list(request_options: {}, **params) params = Whop_sdk::Internal::Types::Utils.normalize_keys(params) query_params = {} query_params["unread"] = params[:unread] if params.key?(:unread) query_params["experience_id"] = params[:experience_id] if params.key?(:experience_id) query_params["account_id"] = params[:account_id] if params.key?(:account_id) query_params["mentions"] = params[:mentions] if params.key?(:mentions) query_params["first"] = params[:first] if params.key?(:first) query_params["after"] = params[:after] if params.key?(:after) Whop_sdk::Internal::CursorItemIterator.new( cursor_field: :end_cursor, item_field: :data, initial_cursor: query_params["after"] ) do |next_cursor| query_params["after"] = next_cursor request = Whop_sdk::Internal::JSON::Request.new( base_url: [:base_url], method: "GET", path: "notifications", query: query_params, 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) parsed_response = Whop_sdk::Notifications::Types::ListNotificationsResponse.load(response.body) [parsed_response, response] else error_class = Whop_sdk::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end end |
#mark_read(request_options: {}, **params) ⇒ Whop_sdk::Notifications::Types::MarkReadNotificationsResponse
Marks the authenticated user's notifications as read: one experience's (experience_id) or everything (all: true) — exactly one of the two. Requires a user credential. Responds with the refreshed badge rows for the
affected scope.
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
# File 'lib/whop_sdk/notifications/client.rb', line 176 def mark_read(request_options: {}, **params) params = Whop_sdk::Internal::Types::Utils.normalize_keys(params) request = Whop_sdk::Internal::JSON::Request.new( base_url: [:base_url], method: "POST", path: "notifications/mark_read", body: Whop_sdk::Notifications::Types::MarkReadNotificationsRequest.new(params).to_h, 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::Notifications::Types::MarkReadNotificationsResponse.load(response.body) else error_class = Whop_sdk::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#retrieve(request_options: {}, **params) ⇒ Whop_sdk::Types::Notification
Retrieves a single notification by id — either an id returned by List Notifications, or the ephemeral id
delivered with a push/websocket event. Requires a user credential.
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 |
# File 'lib/whop_sdk/notifications/client.rb', line 215 def retrieve(request_options: {}, **params) params = Whop_sdk::Internal::Types::Utils.normalize_keys(params) request = Whop_sdk::Internal::JSON::Request.new( base_url: [:base_url], method: "GET", path: "notifications/#{URI.encode_uri_component(params[:id].to_s)}", 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::Types::Notification.load(response.body) else error_class = Whop_sdk::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#topics ⇒ Whop_sdk::Topics::Client
238 239 240 |
# File 'lib/whop_sdk/notifications/client.rb', line 238 def topics @topics ||= Whop_sdk::Notifications::Topics::Client.new(client: @client) end |