class Fulcrum::Attachment
Public Instance Methods
all(params = {})
click to toggle source
# File lib/fulcrum/attachment.rb, line 21 def all(params = {}) call(:get, collection, params) end
collection()
click to toggle source
# File lib/fulcrum/attachment.rb, line 9 def collection resources_name end
create(file, attrs = {})
click to toggle source
# File lib/fulcrum/attachment.rb, line 25 def create(file, attrs = {}) response = call(:post, create_action, attrs) binary_upload(file, response['url'], attrs[:file_size]) { name: attrs[:name], attachment_id: response['id'] } end
finalize(id)
click to toggle source
# File lib/fulcrum/attachment.rb, line 5 def finalize(id) call(:post, "#{collection}/finalize", {id: id}) end
find(id)
click to toggle source
# File lib/fulcrum/attachment.rb, line 17 def find(id) call(:get, member(id)) end
member(id)
click to toggle source
# File lib/fulcrum/attachment.rb, line 13 def member(id) "#{resources_name}/#{id}" end
Private Instance Methods
binary_upload(file, url, file_size)
click to toggle source
# File lib/fulcrum/attachment.rb, line 33 def binary_upload(file, url, file_size) connection = Faraday.new(url: url) do |faraday| faraday.request :multipart faraday.adapter :net_http end connection.put do |req| req.headers['Content-Type'] = 'octet/stream' req.headers['Content-Length'] = "#{file_size}" req.headers['Content-Transfer-Encoding'] = 'binary' req.body = Faraday::UploadIO.new(file, 'octet/stream') end end