Class: Whop_sdk::Swaps::Client
- Inherits:
-
Object
- Object
- Whop_sdk::Swaps::Client
- Defined in:
- lib/whop_sdk/swaps/client.rb
Instance Method Summary collapse
-
#create(request_options: {}, **params) ⇒ Whop_sdk::Swaps::Types::CreateSwapsResponse
Swaps one token for another from the account's wallet, or converts between fiat currencies in the account's ledger at the mid-market rate.
-
#create_quote(request_options: {}, **params) ⇒ Whop_sdk::Swaps::Types::CreateQuoteSwapsResponse
Previews the price of a swap.
- #initialize(client:) ⇒ void constructor
-
#list(request_options: {}, **params) ⇒ Whop_sdk::Swaps::Types::ListSwapsResponse
Retrieve the account's completed or pending swaps — currently just the latest one.
-
#retrieve(request_options: {}, **params) ⇒ Whop_sdk::Swaps::Types::RetrieveSwapsResponse
Retrieves a single swap and its status.
Constructor Details
#initialize(client:) ⇒ void
9 10 11 |
# File 'lib/whop_sdk/swaps/client.rb', line 9 def initialize(client:) @client = client end |
Instance Method Details
#create(request_options: {}, **params) ⇒ Whop_sdk::Swaps::Types::CreateSwapsResponse
Swaps one token for another from the account's wallet, or converts between fiat currencies in the account's ledger at the mid-market rate. Crypto swaps finish in the background — check the swap for its status.
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/whop_sdk/swaps/client.rb', line 73 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: "swaps", body: Whop_sdk::Swaps::Types::CreateSwapsRequest.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::Swaps::Types::CreateSwapsResponse.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_quote(request_options: {}, **params) ⇒ Whop_sdk::Swaps::Types::CreateQuoteSwapsResponse
Previews the price of a swap. Fiat pairs quote the in-ledger mid-market conversion — the same rate creating the swap fills at. No funds move and nothing is saved.
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/whop_sdk/swaps/client.rb', line 115 def create_quote(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: "swaps/quote", body: Whop_sdk::Swaps::Types::CreateQuoteSwapsRequest.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::Swaps::Types::CreateQuoteSwapsResponse.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::Swaps::Types::ListSwapsResponse
Retrieve the account's completed or pending swaps — currently just the latest one.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/whop_sdk/swaps/client.rb', line 28 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) request = Whop_sdk::Internal::JSON::Request.new( base_url: [:base_url], method: "GET", path: "swaps", 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::Swaps::Types::ListSwapsResponse.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::Swaps::Types::RetrieveSwapsResponse
Retrieves a single swap and its status.
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/whop_sdk/swaps/client.rb', line 153 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: "swaps/#{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::Swaps::Types::RetrieveSwapsResponse.load(response.body) else error_class = Whop_sdk::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |