Class: Pinnacle::Tools::File::Client
- Inherits:
-
Object
- Object
- Pinnacle::Tools::File::Client
- Defined in:
- lib/pinnacle/tools/file/client.rb
Direct Known Subclasses
Instance Method Summary collapse
- #initialize(client:) ⇒ void constructor
-
#refresh(request_options: {}, **params) ⇒ Array[Pinnacle::Types::RefreshedFile]
Refresh expiring presigned URLs for Pinnacle-hosted files to extend their access time.
-
#upload(request_options: {}, **params) ⇒ Pinnacle::Types::UploadResults
Generate presigned URLs that let you upload files directly to our storage and allow your users to download them securely.
Constructor Details
#initialize(client:) ⇒ void
10 11 12 |
# File 'lib/pinnacle/tools/file/client.rb', line 10 def initialize(client:) @client = client end |
Instance Method Details
#refresh(request_options: {}, **params) ⇒ Array[Pinnacle::Types::RefreshedFile]
Refresh expiring presigned URLs for Pinnacle-hosted files to extend their access time.
<Callout type=“info”> This only works for presigned download URLs. At this moment, you cannot refresh a presigned upload URL, generate a new one instead. </Callout>
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/pinnacle/tools/file/client.rb', line 68 def refresh(request_options: {}, **params) params = Pinnacle::Internal::Types::Utils.normalize_keys(params) body_prop_names = i[urls] body_bag = params.slice(*body_prop_names) request = Pinnacle::Internal::JSON::Request.new( base_url: [:base_url], method: "POST", path: "tools/files/refresh", body: Pinnacle::Tools::File::Types::RefreshFileParams.new(body_bag).to_h, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Pinnacle::Errors::TimeoutError end code = response.code.to_i return if code.between?(200, 299) error_class = Pinnacle::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end |
#upload(request_options: {}, **params) ⇒ Pinnacle::Types::UploadResults
Generate presigned URLs that let you upload files directly to our storage and allow your users to download them securely.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/pinnacle/tools/file/client.rb', line 26 def upload(request_options: {}, **params) params = Pinnacle::Internal::Types::Utils.normalize_keys(params) body_prop_names = i[content_type size name ] body_bag = params.slice(*body_prop_names) request = Pinnacle::Internal::JSON::Request.new( base_url: [:base_url], method: "POST", path: "tools/files/upload", body: Pinnacle::Tools::File::Types::UploadFileParams.new(body_bag).to_h, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Pinnacle::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Pinnacle::Types::UploadResults.load(response.body) else error_class = Pinnacle::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |