Class: Whop_sdk::Files::Client
- Inherits:
-
Object
- Object
- Whop_sdk::Files::Client
- Defined in:
- lib/whop_sdk/files/client.rb
Instance Method Summary collapse
-
#complete(request_options: {}, **params) ⇒ Whop_sdk::Types::File
Assembles the parts of a multipart upload after every part has been PUT to its presigned URL.
-
#create(request_options: {}, **params) ⇒ Whop_sdk::Types::File
Creates a file and returns a presigned destination to upload its bytes to.
- #initialize(client:) ⇒ void constructor
-
#retrieve(request_options: {}, **params) ⇒ Whop_sdk::Types::File
Retrieves a file you uploaded — poll it after uploading the bytes to see
upload_statusbecomeready.
Constructor Details
#initialize(client:) ⇒ void
9 10 11 |
# File 'lib/whop_sdk/files/client.rb', line 9 def initialize(client:) @client = client end |
Instance Method Details
#complete(request_options: {}, **params) ⇒ Whop_sdk::Types::File
Assembles the parts of a multipart upload after every part has been PUT to its presigned URL. Pass the
multipart_upload_id from Create File and each part's ETag response header.
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/whop_sdk/files/client.rb', line 114 def complete(request_options: {}, **params) params = Whop_sdk::Internal::Types::Utils.normalize_keys(params) request_data = Whop_sdk::Files::Types::CompleteFilesRequest.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: "POST", path: "files/#{URI.encode_uri_component(params[:id].to_s)}/complete", 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::File.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::Types::File
Creates a file and returns a presigned destination to upload its bytes to. PUT the bytes to upload_url
(single-part), or to each of multipart_upload_urls and then call Complete File Multipart Upload. Once the
bytes land the file becomes ready, and its ID can be attached wherever a file is accepted — account legal
documents, dispute evidence documents.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/whop_sdk/files/client.rb', line 30 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: "files", body: Whop_sdk::Files::Types::CreateFilesRequest.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::File.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::File
Retrieves a file you uploaded — poll it after uploading the bytes to see upload_status become ready. Only
the creator can retrieve a file this way; a file attached to another resource is read through that resource.
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/whop_sdk/files/client.rb', line 69 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: "files/#{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::File.load(response.body) else error_class = Whop_sdk::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |