Class: Yandex::Disk::Client
- Inherits:
-
Object
- Object
- Yandex::Disk::Client
- Defined in:
- lib/yandex/disk/client.rb
Defined Under Namespace
Modules: Request
Instance Method Summary collapse
- #copy(src, dest) ⇒ Object
- #copy!(src, dest) ⇒ Object
- #delete(path) ⇒ Object
- #delete!(path) ⇒ Object
- #get(path) ⇒ Object
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
- #list(path) ⇒ Object
- #make_private(path) ⇒ Object
- #make_public(path) ⇒ Object
- #mkcol(path) ⇒ Object (also: #mkdir)
- #mkcol! ⇒ Object
- #mkdir_p(path) ⇒ Object
- #move(src, dest) ⇒ Object
- #move!(src, dest) ⇒ Object
- #put(src, dest) ⇒ Object
- #put!(src, dest) ⇒ Object
- #space ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/yandex/disk/client.rb', line 15 def initialize ={} @timeout = [:timeout] || 300 @http = Faraday.new(:url => 'https://webdav.yandex.ru') do |builder| if [:access_token] && [:access_token].length > 0 builder.request :authorization, "OAuth", [:access_token] elsif [:login] && [:password] basic_token = Base64.encode64("#{[:login]}:#{[:password]}") builder.request :authorization, "Basic", basic_token else raise ArgumentError, 'No :access_token or :login and :password' end if faraday_configurator = [:faraday_configurator] faraday_configurator.call(builder) else builder.adapter :excon end end end |
Instance Method Details
#copy(src, dest) ⇒ Object
87 88 89 |
# File 'lib/yandex/disk/client.rb', line 87 def copy src, dest file_operation_response('COPY', src, dest).success? end |
#copy!(src, dest) ⇒ Object
91 92 93 94 |
# 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) ⇒ Object
105 106 107 |
# File 'lib/yandex/disk/client.rb', line 105 def delete path delete_response(path).success? end |
#delete!(path) ⇒ Object
109 110 111 112 |
# File 'lib/yandex/disk/client.rb', line 109 def delete! path res = delete_response(path) raise res.body unless res.success? end |
#get(path) ⇒ Object
53 54 55 |
# File 'lib/yandex/disk/client.rb', line 53 def get path @http.get(path) end |
#list(path) ⇒ Object
62 63 64 65 |
# File 'lib/yandex/disk/client.rb', line 62 def list path request = Request::List.new(@http, path) request.perform end |
#make_private(path) ⇒ Object
72 73 74 75 |
# File 'lib/yandex/disk/client.rb', line 72 def make_private path request = Request::Private.new(@http, path) request.perform end |
#make_public(path) ⇒ Object
67 68 69 70 |
# File 'lib/yandex/disk/client.rb', line 67 def make_public path request = Request::Publication.new(@http, path) request.perform end |
#mkcol(path) ⇒ Object Also known as: mkdir
44 45 46 |
# File 'lib/yandex/disk/client.rb', line 44 def mkcol path mkcol_response(path).success? end |
#mkcol! ⇒ Object
48 49 50 51 |
# File 'lib/yandex/disk/client.rb', line 48 def mkcol! res = mkcol_response(path) raise res.body unless res.success? end |
#mkdir_p(path) ⇒ Object
79 80 81 82 83 84 85 |
# 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) ⇒ Object
96 97 98 |
# File 'lib/yandex/disk/client.rb', line 96 def move src, dest file_operation_response('MOVE', src, dest).success? end |
#move!(src, dest) ⇒ Object
100 101 102 103 |
# 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) ⇒ Object
35 36 37 |
# File 'lib/yandex/disk/client.rb', line 35 def put src, dest put_response(src, dest).success? end |
#put!(src, dest) ⇒ Object
39 40 41 42 |
# File 'lib/yandex/disk/client.rb', line 39 def put! src, dest res = put_response(src, dest) raise res.body unless res.success? end |