Class: Yandex::API::Disk::Storage

Inherits:
Object
  • Object
show all
Defined in:
lib/yandex-api/disk.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeStorage

Returns a new instance of Storage.



104
105
106
# File 'lib/yandex-api/disk.rb', line 104

def initialize
  super Disk::request(:get, '/v1/disk/')
end

Class Method Details

.clean(path = nil) ⇒ Object



174
175
176
# File 'lib/yandex-api/disk.rb', line 174

def clean(path = nil)
  clean!(path) rescue false
end

.clean!(path = nil) ⇒ Object



166
167
168
169
170
171
172
173
# File 'lib/yandex-api/disk.rb', line 166

def clean!(path = nil)
  if path.nil?
    Disk::request :delete, "/v1/disk/trash/resources"
  else
    Disk::request :delete, "/v1/disk/trash/resources?path=#{path}"
  end
  true
end

.copy(from, to) ⇒ Object



145
146
147
# File 'lib/yandex-api/disk.rb', line 145

def copy(from, to)
  copy!(from, to) rescue false
end

.copy!(from, to) ⇒ Object



141
142
143
144
# File 'lib/yandex-api/disk.rb', line 141

def copy!(from, to)
  Disk::request :post, "/v1/disk/resources/copy?from=#{from}&path=#{to}"
  true
end

.exists?(path) ⇒ Boolean

Returns:

  • (Boolean)


121
122
123
# File 'lib/yandex-api/disk.rb', line 121

def exists?(path)
  Disk::request :get, "/v1/disk/resources?path=#{path}"
end

.ls(path) ⇒ Object



109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/yandex-api/disk.rb', line 109

def ls(path)
  response = Disk::request(:get,  "/v1/disk/resources?path=#{path}")['_embedded'] || {}
  response['items'] ||= []
  response['items'].collect do |item|
    case item['type']
      when 'dir' then
        Disk::Folder.new(item)
      when 'file' then
        Disk::Object.new(item)
    end
  end
end

.mkdir(path) ⇒ Object



129
130
131
# File 'lib/yandex-api/disk.rb', line 129

def mkdir(path)
  mkdir!(path) rescue false
end

.mkdir!(path) ⇒ Object



125
126
127
128
# File 'lib/yandex-api/disk.rb', line 125

def mkdir!(path)
  Disk::request :put, "/v1/disk/resources?path=#{path}"
  true
end

.move(from, to) ⇒ Object



153
154
155
# File 'lib/yandex-api/disk.rb', line 153

def move(from, to)
  move!(from,to) rescue false
end

.move!(from, to) ⇒ Object



149
150
151
152
# File 'lib/yandex-api/disk.rb', line 149

def move!(from, to)
  Disk::request :post, "/v1/disk/resources/move?from=#{from}&path=#{to}"
  true
end

.restore(path, to = path) ⇒ Object



182
183
184
# File 'lib/yandex-api/disk.rb', line 182

def restore(path, to = path)
  restore!(path, to) rescue false
end

.restore!(path, to = path) ⇒ Object



178
179
180
181
# File 'lib/yandex-api/disk.rb', line 178

def restore!(path, to = path)
  Disk::request :put, "/v1/disk/trash/resources/restore?path=#{to}&name=#{path}"
  true
end

.rm(path) ⇒ Object



137
138
139
# File 'lib/yandex-api/disk.rb', line 137

def rm(path)
  rm!(path) rescue false
end

.rm!(path) ⇒ Object



133
134
135
136
# File 'lib/yandex-api/disk.rb', line 133

def rm!(path)
  Disk::request :delete, "/v1/disk/resources?path=#{path}"
  true
end

.write(file, to) ⇒ Object



162
163
164
# File 'lib/yandex-api/disk.rb', line 162

def write(file, to)
  write!(file, to) rescue false
end

.write!(file, to) ⇒ Object



157
158
159
160
161
# File 'lib/yandex-api/disk.rb', line 157

def write!(file, to)
  params = Disk::request :get, "/v1/disk/resources/upload?path=#{to}"
  Disk::upload(file, to.split('/').last, params['href'])
  true
end