class Yandex::Disk::Client
Public Class Methods
new(options={})
click to toggle source
# File lib/yandex/disk/client.rb, line 15 def initialize options={} @timeout = options[:timeout] || 300 @http = Faraday.new(:url => 'https://webdav.yandex.ru') do |builder| if options[:access_token] && options[:access_token].length > 0 builder.request :authorization, "OAuth", options[:access_token] elsif options[:login] && options[:password] basic_token = Base64.encode64("#{options[:login]}:#{options[:password]}") builder.request :authorization, "Basic", basic_token else raise ArgumentError, 'No :access_token or :login and :password' end if faraday_configurator = options[:faraday_configurator] faraday_configurator.call(builder) else builder.adapter :excon end end end
Public Instance Methods
copy(src, dest)
click to toggle source
# File lib/yandex/disk/client.rb, line 87 def copy src, dest file_operation_response('COPY', src, dest).success? end
copy!(src, dest)
click to toggle source
# File lib/yandex/disk/client.rb, line 91 def copy! src, dest res = file_operation_response('COPY', src, dest) raise res.body unless res.success? end
delete(path)
click to toggle source
# File lib/yandex/disk/client.rb, line 105 def delete path delete_response(path).success? end
delete!(path)
click to toggle source
# File lib/yandex/disk/client.rb, line 109 def delete! path res = delete_response(path) raise res.body unless res.success? end
get(path)
click to toggle source
# File lib/yandex/disk/client.rb, line 53 def get path @http.get(path) end
list(path)
click to toggle source
# File lib/yandex/disk/client.rb, line 62 def list path request = Request::List.new(@http, path) request.perform end
make_private(path)
click to toggle source
# File lib/yandex/disk/client.rb, line 72 def make_private path request = Request::Private.new(@http, path) request.perform end
make_public(path)
click to toggle source
# File lib/yandex/disk/client.rb, line 67 def make_public path request = Request::Publication.new(@http, path) request.perform end
mkcol(path)
click to toggle source
# File lib/yandex/disk/client.rb, line 44 def mkcol path mkcol_response(path).success? end
Also aliased as: mkdir
mkcol!()
click to toggle source
# File lib/yandex/disk/client.rb, line 48 def mkcol! res = mkcol_response(path) raise res.body unless res.success? end
mkdir_p(path)
click to toggle source
# File lib/yandex/disk/client.rb, line 79 def mkdir_p path path_parts = [] path.split('/').each do |part| path_parts << part mkdir(path_parts.join('/')) end end
move(src, dest)
click to toggle source
# File lib/yandex/disk/client.rb, line 96 def move src, dest file_operation_response('MOVE', src, dest).success? end
move!(src, dest)
click to toggle source
# File lib/yandex/disk/client.rb, line 100 def move! src, dest res = file_operation_response('MOVE', src, dest) raise res.body unless res.success? end
put(src, dest)
click to toggle source
# File lib/yandex/disk/client.rb, line 35 def put src, dest put_response(src, dest).success? end
put!(src, dest)
click to toggle source
# File lib/yandex/disk/client.rb, line 39 def put! src, dest res = put_response(src, dest) raise res.body unless res.success? end
space()
click to toggle source
# File lib/yandex/disk/client.rb, line 57 def space request = Request::Space.new(@http) request.perform end
Private Instance Methods
delete_response(path)
click to toggle source
# File lib/yandex/disk/client.rb, line 145 def delete_response path @http.delete(path) end
file_operation_response(op, src, dest)
click to toggle source
# File lib/yandex/disk/client.rb, line 134 def file_operation_response op, src, dest request = @http.build_request(op) do |req| req.url(path) req.headers['Destination'] = dest end env = request.to_env(@http) res = @http.app.call(env) res.success? end
mkcol_response(path)
click to toggle source
# File lib/yandex/disk/client.rb, line 125 def mkcol_response path request = @http.build_request('MKCOL') do |req| req.url(path) end env = request.to_env(@http) @http.app.call(env) end
put_response(src, dest)
click to toggle source
# File lib/yandex/disk/client.rb, line 116 def put_response src, dest @http.put do |req| req.url dest req.headers['Content-Type'] = 'application/binary' req.options[:timeout] = @timeout req.body = Faraday::UploadIO.new(src, '') end end