Module: UploadUtils
- Included in:
- AV, FilestackClient, FilestackCommon, FilestackFilelink
- Defined in:
- lib/filestack/utils/utils.rb
Overview
Includes general utility functions for the Filestack Ruby SDK
Instance Method Summary collapse
- #build_store_task(options = {}) ⇒ Object
-
#get_url(base, handle: nil, path: nil, security: nil) ⇒ String
Generates the URL for a FilestackFilelink object.
-
#make_call(url, action, parameters: nil, headers: nil) ⇒ Typhoeus::Request
General request function.
-
#send_upload(apikey, external_url = nil, security = nil, options = nil) ⇒ Hash
Uploads to v1 REST API (for external URLs or if multipart is turned off).
Instance Method Details
#build_store_task(options = {}) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/filestack/utils/utils.rb', line 65 def build_store_task( = {}) return 'store' if .nil? || .empty? tasks = [] .each do |key, value| value = case key when :workflows [value.join('","')] when :path "\"#{value}\"" else value end tasks.push("#{key}:#{value.to_s.downcase}") end "store=#{tasks.join(',')}" end |
#get_url(base, handle: nil, path: nil, security: nil) ⇒ String
Generates the URL for a FilestackFilelink object
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/filestack/utils/utils.rb', line 120 def get_url(base, handle: nil, path: nil, security: nil) url_components = [base] url_components.push(path) unless path.nil? url_components.push(handle) unless handle.nil? url = url_components.join('/') if security policy = security.policy signature = security.signature security_path = "policy=#{policy}&signature=#{signature}" url = "#{url}?#{security_path}" end url end |
#make_call(url, action, parameters: nil, headers: nil) ⇒ Typhoeus::Request
General request function
54 55 56 57 58 59 60 61 62 63 |
# File 'lib/filestack/utils/utils.rb', line 54 def make_call(url, action, parameters: nil, headers: nil) headers = if headers headers.merge!(FilestackConfig::HEADERS) else FilestackConfig::HEADERS end Typhoeus.public_send( action, URI::Parser.new.escape(url), params: parameters, headers: headers ) end |
#send_upload(apikey, external_url = nil, security = nil, options = nil) ⇒ Hash
Uploads to v1 REST API (for external URLs or if multipart is turned off)
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/filestack/utils/utils.rb', line 91 def send_upload(apikey, external_url = nil, security = nil, = nil) base = "#{FilestackConfig::CDN_URL}/#{apikey}/#{build_store_task()}" if security policy = security.policy signature = security.signature base = "#{base}/security=s:#{signature},p:#{policy}" end response = Typhoeus.post("#{base}/#{external_url}", headers: FilestackConfig::HEADERS) if response.code == 200 begin response_body = JSON.parse(response.body) return response_body rescue StandardError raise response.body end end raise response.body end |