Class: Pcloud::FileHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/pcloud/files/file_handler.rb

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ FileHandler



5
6
7
# File 'lib/pcloud/files/file_handler.rb', line 5

def initialize(client)
  @client = client
end

Instance Method Details

#download(params) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/pcloud/files/file_handler.rb', line 13

def download(params)
  url = params[:url]
  begin
    res = RestClient.get(url)
  rescue => e
    raise HTTPError.new(:HTTPError, e.message)
  end
  
  filename = params[:filename] ? params[:filename] : url.split("/").last
  File.open("#{params[:destination]}/#{filename}", 'wb' ) do |f|
    f.write res
  end
  res.code
end

#upload(params, payload) ⇒ Object



9
10
11
# File 'lib/pcloud/files/file_handler.rb', line 9

def upload(params, payload)
  create_request(:post, 'uploadfile', params, payload).call
end