Class: LiquidPlanner::Resources::Document

Inherits:
Luggage show all
Defined in:
lib/liquidplanner/resources/document.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from LiquidPlannerResource

#load

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class LiquidPlanner::LiquidPlannerResource

Class Method Details

.upload_document(workspace_id, item_id, attached_file_path, options = {}) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/liquidplanner/resources/document.rb', line 5

def self.upload_document( workspace_id, item_id, attached_file_path, options={} )
  file_name   = options[:file_name]   || File.basename(attached_file_path)
  description = options[:description] || ""
  content_type = options[:content_type] || "application/octet-stream"
  url         = site + "/api/workspaces/#{workspace_id}/treeitems/#{item_id}/documents"
  File.open(attached_file_path) do |handle|
    req = Net::HTTP::Post::Multipart.new( url.path, "document[file_name]"     => file_name,
                                                    "document[description]"   => description,
                                                    "document[attached_file]" => UploadIO.new(handle, content_type, attached_file_path)
                                        )
    req.basic_auth( user, password )
    res = nil
    begin
      res = Net::HTTP.start(url.host, url.port) do |http|
        http.use_ssl = true if url.scheme == "https" 
        http.request(req)
      end
    rescue Timeout::Error => e
      raise TimeoutError.new(e.message)
    rescue OpenSSL::SSL::SSLError => e
      raise SSLError.new(e.message)
    end
    connection.send(:handle_response, res)
    doc = new(format.decode(res.body))
  end
end

Instance Method Details

#downloadObject



36
37
38
# File 'lib/liquidplanner/resources/document.rb', line 36

def download
  get_raw(:download)
end

#get_raw(custom_method_name, options = {}) ⇒ Object



32
33
34
# File 'lib/liquidplanner/resources/document.rb', line 32

def get_raw(custom_method_name, options = {})
  connection.get_raw(custom_method_element_url(custom_method_name, options), self.class.headers)
end

#thumbnailObject



40
41
42
# File 'lib/liquidplanner/resources/document.rb', line 40

def thumbnail
  get_raw(:thumbnail)
end