Class: Whop_sdk::Products::Client
- Inherits:
-
Object
- Object
- Whop_sdk::Products::Client
- Defined in:
- lib/whop_sdk/products/client.rb
Instance Method Summary collapse
-
#create(request_options: {}, **params) ⇒ Whop_sdk::Types::Product
Creates a new product for an account.
-
#delete(request_options: {}, **params) ⇒ Whop_sdk::Products::Types::DeleteProductsResponse
Deletes a product.
- #initialize(client:) ⇒ void constructor
-
#list(request_options: {}, **params) ⇒ Whop_sdk::Products::Types::ListProductsResponse
Returns a paginated list of products.
-
#publish(request_options: {}, **params) ⇒ Whop_sdk::Types::Product
Submits a product to the whop.com marketplace for review.
-
#retrieve(request_options: {}, **params) ⇒ Whop_sdk::Types::Product
Retrieves a product.
-
#unpublish(request_options: {}, **params) ⇒ Whop_sdk::Types::Product
Removes a product from the whop.com marketplace.
-
#update(request_options: {}, **params) ⇒ Whop_sdk::Types::Product
Updates an existing product.
Constructor Details
#initialize(client:) ⇒ void
9 10 11 |
# File 'lib/whop_sdk/products/client.rb', line 9 def initialize(client:) @client = client end |
Instance Method Details
#create(request_options: {}, **params) ⇒ Whop_sdk::Types::Product
Creates a new product for an account.
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/whop_sdk/products/client.rb', line 111 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: "products", body: Whop_sdk::Products::Types::CreateProductsRequest.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::Types::Product.load(response.body) else error_class = Whop_sdk::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#delete(request_options: {}, **params) ⇒ Whop_sdk::Products::Types::DeleteProductsResponse
Deletes a product. Only products with no memberships, entries, reviews, or invoices can be deleted.
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 |
# File 'lib/whop_sdk/products/client.rb', line 186 def delete(request_options: {}, **params) params = Whop_sdk::Internal::Types::Utils.normalize_keys(params) request = Whop_sdk::Internal::JSON::Request.new( base_url: [:base_url], method: "DELETE", path: "products/#{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::Products::Types::DeleteProductsResponse.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::Products::Types::ListProductsResponse
Returns a paginated list of products. Omit account_id to search the public marketplace.
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 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/whop_sdk/products/client.rb', line 47 def list(request_options: {}, **params) params = Whop_sdk::Internal::Types::Utils.normalize_keys(params) query_params = {} query_params["account_id"] = params[:account_id] if params.key?(:account_id) query_params["query"] = params[:query] if params.key?(:query) query_params["marketplace_category_route"] = params[:marketplace_category_route] if params.key?(:marketplace_category_route) query_params["plan_types"] = params[:plan_types] if params.key?(:plan_types) query_params["price_minimum"] = params[:price_minimum] if params.key?(:price_minimum) query_params["price_maximum"] = params[:price_maximum] if params.key?(:price_maximum) query_params["visibilities"] = params[:visibilities] if params.key?(:visibilities) query_params["access_pass_types"] = params[:access_pass_types] if params.key?(:access_pass_types) query_params["labels"] = params[:labels] if params.key?(:labels) query_params["direction"] = params[:direction] if params.key?(:direction) query_params["order"] = params[:order] if params.key?(:order) query_params["first"] = params[:first] if params.key?(:first) query_params["after"] = params[:after] if params.key?(:after) query_params["last"] = params[:last] if params.key?(:last) query_params["before"] = params[:before] if params.key?(:before) query_params["created_after"] = params[:created_after] if params.key?(:created_after) query_params["created_before"] = params[:created_before] if params.key?(:created_before) 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: "products", 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::Products::Types::ListProductsResponse.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 |
#publish(request_options: {}, **params) ⇒ Whop_sdk::Types::Product
Submits a product to the whop.com marketplace for review. The product moves to pending_review; a Whop reviewer
approves it before it goes live.
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 |
# File 'lib/whop_sdk/products/client.rb', line 266 def publish(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: "products/#{URI.encode_uri_component(params[:id].to_s)}/publish", 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::Product.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::Product
Retrieves a product. Public — no credentials.
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/whop_sdk/products/client.rb', line 149 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: "products/#{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::Product.load(response.body) else error_class = Whop_sdk::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#unpublish(request_options: {}, **params) ⇒ Whop_sdk::Types::Product
Removes a product from the whop.com marketplace. The product moves to not_available.
303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 |
# File 'lib/whop_sdk/products/client.rb', line 303 def unpublish(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: "products/#{URI.encode_uri_component(params[:id].to_s)}/unpublish", 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::Product.load(response.body) else error_class = Whop_sdk::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#update(request_options: {}, **params) ⇒ Whop_sdk::Types::Product
Updates an existing product.
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 |
# File 'lib/whop_sdk/products/client.rb', line 223 def update(request_options: {}, **params) params = Whop_sdk::Internal::Types::Utils.normalize_keys(params) request_data = Whop_sdk::Products::Types::UpdateProductsRequest.new(params).to_h non_body_param_names = %w[id] body = request_data.except(*non_body_param_names) request = Whop_sdk::Internal::JSON::Request.new( base_url: [:base_url], method: "PATCH", path: "products/#{URI.encode_uri_component(params[:id].to_s)}", body: body, 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::Product.load(response.body) else error_class = Whop_sdk::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |