Class: CarrierWave::Storage::Yandex::Disk::File

Inherits:
Object
  • Object
show all
Includes:
Utilities::Uri
Defined in:
lib/carrierwave/yandex/storage/disk.rb

Overview

Rubocop, shut up

Instance Method Summary collapse

Constructor Details

#initialize(public_url, location, yandex_disk_client) ⇒ File

Returns a new instance of File.



73
74
75
76
77
# File 'lib/carrierwave/yandex/storage/disk.rb', line 73

def initialize(public_url, location, yandex_disk_client)
  @public_url = public_url
  @location = location
  @yandex_disk_client = yandex_disk_client
end

Instance Method Details

#deleteObject



105
106
107
108
# File 'lib/carrierwave/yandex/storage/disk.rb', line 105

def delete
  @yandex_disk_client.delete @location
  @yandex_disk_client.delete(::File.dirname(@location))
end

#extensionObject



83
84
85
# File 'lib/carrierwave/yandex/storage/disk.rb', line 83

def extension
  ::File.extname @location
end

#filenameObject



79
80
81
# File 'lib/carrierwave/yandex/storage/disk.rb', line 79

def filename
  ::File.basename @location
end

#public_urlObject



96
97
98
# File 'lib/carrierwave/yandex/storage/disk.rb', line 96

def public_url
  CGI.unescape @public_url
end

#storage_pathObject



100
101
102
103
# File 'lib/carrierwave/yandex/storage/disk.rb', line 100

def storage_path
  # deviation from http://www.rubydoc.info/gems/carrierwave/CarrierWave/Storage/Fog/File
  @location
end

#urlObject



87
88
89
90
91
92
93
94
# File 'lib/carrierwave/yandex/storage/disk.rb', line 87

def url
  query = 'https://cloud-api.yandex.net/v1/disk/public/resources/' \
  "download?public_key=#{@public_url}"
  uri = URI query
  res = Net::HTTP.get(uri)
  hash = JSON.parse(res)
  hash['href']
end