Class: MagLoft::TypeloftImage

Inherits:
RemoteResource show all
Defined in:
lib/magloft/typeloft_image.rb

Instance Attribute Summary collapse

Attributes inherited from RemoteResource

#destroyed, #id

Instance Method Summary collapse

Methods inherited from RemoteResource

all, #changed?, #changed_data, #clear_changed_data!, create, #destroy, #destroyed?, endpoint, find, find_one, #initialize, method_missing, remote_attribute, remote_attributes, respond_to_missing?, #save, #update_data, where

Constructor Details

This class inherits a constructor from MagLoft::RemoteResource

Instance Attribute Details

#content_typeObject

Returns the value of attribute content_type.



5
6
7
# File 'lib/magloft/typeloft_image.rb', line 5

def content_type
  @content_type
end

#policyObject

Returns the value of attribute policy.



5
6
7
# File 'lib/magloft/typeloft_image.rb', line 5

def policy
  @policy
end

Instance Method Details

#queue_upload(file_path, &block) ⇒ Object



18
19
20
21
22
23
# File 'lib/magloft/typeloft_image.rb', line 18

def queue_upload(file_path, &block)
  return false if policy.nil?
  request = Typhoeus::Request.new(policy["url"], method: :put, headers: policy["headers"], body: File.read(file_path), timeout: 200_000)
  request.on_complete(&block) if block
  request
end

#upload(file_path) ⇒ Object



7
8
9
10
11
12
13
14
15
16
# File 'lib/magloft/typeloft_image.rb', line 7

def upload(file_path)
  return false if policy.nil?
  conn = Faraday.new(url: policy["url"]) do |f|
    f.ssl.verify = false
    f.headers = policy["headers"]
    f.adapter :net_http
  end
  response = conn.put(nil, File.read(file_path))
  return (response.status == 200)
end