Class: YandexClient::Disk

Inherits:
Object
  • Object
show all
Includes:
Configurable, ErrorHandler
Defined in:
lib/yandex_client/disk.rb

Overview

Constant Summary collapse

ACTION_URL =
'https://cloud-api.yandex.net'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Configurable

included

Constructor Details

#initialize(token) ⇒ Disk

Returns a new instance of Disk.



29
30
31
# File 'lib/yandex_client/disk.rb', line 29

def initialize(token)
  @token = token
end

Instance Attribute Details

#tokenObject (readonly)

Returns the value of attribute token.



19
20
21
# File 'lib/yandex_client/disk.rb', line 19

def token
  @token
end

Class Method Details

.with_token(token) ⇒ Object Also known as: []



22
23
24
# File 'lib/yandex_client/disk.rb', line 22

def with_token(token)
  new(token)
end

Instance Method Details

#download_url(path) ⇒ Object



39
40
41
42
43
44
45
46
47
48
# File 'lib/yandex_client/disk.rb', line 39

def download_url(path)
  url = URI.parse(ACTION_URL).tap do |uri|
    uri.path = '/v1/disk/resources/download'
    uri.query = URI.encode_www_form(path: path)
  end

  process_response(
    with_config.get(url, headers: auth_headers)
  ).fetch(:href)
end

#infoObject



33
34
35
36
37
# File 'lib/yandex_client/disk.rb', line 33

def info
  process_response(
    with_config.get("#{ACTION_URL}/v1/disk/", headers: auth_headers)
  )
end

#move(from, to, overwrite: false) ⇒ Object



61
62
63
64
65
66
67
68
69
70
# File 'lib/yandex_client/disk.rb', line 61

def move(from, to, overwrite: false)
  url = URI.parse(ACTION_URL).tap do |uri|
    uri.path = '/v1/disk/resources/move'
    uri.query = URI.encode_www_form(from: from, path: to, overwrite: overwrite)
  end

  process_response(
    with_config.post(url, headers: auth_headers)
  ).fetch(:href)
end

#upload_url(path, overwrite: false) ⇒ Object



50
51
52
53
54
55
56
57
58
59
# File 'lib/yandex_client/disk.rb', line 50

def upload_url(path, overwrite: false)
  url = URI.parse(ACTION_URL).tap do |uri|
    uri.path = '/v1/disk/resources/upload'
    uri.query = URI.encode_www_form(path: path, overwrite: overwrite)
  end

  process_response(
    with_config.get(url, headers: auth_headers)
  ).fetch(:href)
end