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
- #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.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/yandex/disk/client.rb', line 14 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 builder.response :follow_redirects if faraday_configurator = [:faraday_configurator] faraday_configurator.call(builder) else builder.adapter :excon end end end |
Instance Method Details
#copy(src, dest) ⇒ Object
78 79 80 |
# File 'lib/yandex/disk/client.rb', line 78 def copy src, dest file_operation_response('COPY', src, dest).success? end |
#copy!(src, dest) ⇒ Object
82 83 84 85 |
# File 'lib/yandex/disk/client.rb', line 82 def copy! src, dest res = file_operation_response('COPY', src, dest) raise res.body unless res.success? end |
#delete(path) ⇒ Object
96 97 98 |
# File 'lib/yandex/disk/client.rb', line 96 def delete path delete_response(path).success? end |
#delete!(path) ⇒ Object
100 101 102 103 |
# File 'lib/yandex/disk/client.rb', line 100 def delete! path res = delete_response(path) raise res.body unless res.success? end |
#get(path) ⇒ Object
54 55 56 |
# File 'lib/yandex/disk/client.rb', line 54 def get path @http.get(path) end |
#list(path) ⇒ Object
63 64 65 66 |
# File 'lib/yandex/disk/client.rb', line 63 def list path request = Request::List.new(@http, path) request.perform end |
#mkcol(path) ⇒ Object Also known as: mkdir
45 46 47 |
# File 'lib/yandex/disk/client.rb', line 45 def mkcol path mkcol_response(path).success? end |
#mkcol! ⇒ Object
49 50 51 52 |
# File 'lib/yandex/disk/client.rb', line 49 def mkcol! res = mkcol_response(path) raise res.body unless res.success? end |
#mkdir_p(path) ⇒ Object
70 71 72 73 74 75 76 |
# File 'lib/yandex/disk/client.rb', line 70 def mkdir_p path path_parts = [] path.split('/').each do |part| path_parts << part mkdir(path_parts.join('/')) end end |
#move(src, dest) ⇒ Object
87 88 89 |
# File 'lib/yandex/disk/client.rb', line 87 def move src, dest file_operation_response('MOVE', src, dest).success? end |
#move!(src, dest) ⇒ Object
91 92 93 94 |
# File 'lib/yandex/disk/client.rb', line 91 def move! src, dest res = file_operation_response('MOVE', src, dest) raise res.body unless res.success? end |
#put(src, dest) ⇒ Object
36 37 38 |
# File 'lib/yandex/disk/client.rb', line 36 def put src, dest put_response(src, dest).success? end |
#put!(src, dest) ⇒ Object
40 41 42 43 |
# File 'lib/yandex/disk/client.rb', line 40 def put! src, dest res = put_response(src, dest) raise res.body unless res.success? end |