Method: YandexDisk::Api#properties

Defined in:
lib/yandex_disk/api.rb

#properties(path, options = {}) ⇒ Object

Example:

yd.properties('/home/graph.pdf')
=>
    {:name => 'graph.pdf',
    :created => (Time),
    :updated => (Time),
    :type => 'pdf',
    :size => 42432,
    :is_file => true,
    :public_url => nil}

Arguments:

path: path to yandex disk directory or file
h_size: return size in human readable format e.g, 100K 128M 1G (false for default)


140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/yandex_disk/api.rb', line 140

def properties(path, options = {})
  body = '<?xml version="1.0" encoding="utf-8"?><propfind xmlns="DAV:"><prop><displayname/><creationdate/><getlastmodified/><getcontenttype/><getcontentlength/><public_url xmlns="urn:yandex:disk:meta"/></prop></propfind>'
  send_propfind(0, :path => path, :body => body)
  prop = 'd:multistatus/d:response/d:propstat/d:prop/'
  xml = REXML::Document.new(@response.body)
  type = xml.elements[prop + 'd:getcontenttype'].text
  size = xml.elements[prop + 'd:getcontentlength'].text.to_i

  return {:name => xml.elements[prop + 'd:displayname'].text,
          :created => xml.elements[prop + 'd:getlastmodified'].text,
          :updated => xml.elements[prop + 'd:getlastmodified'].text,
          :type => type ? type : 'dir',
          :size => size.to_readable(options[:h_size]),
          :is_file => size > 0,
          :public_url => xml.elements[prop + 'public_url'].text}
end