class LC::File

File


tf = LC::File.new(:body => “Hello World!”, :local_filename => “hello.txt”) tf.save

Attributes

body[RW]
content_type[RW]
id[RW]
local_filename[RW]

'{“avatar”: {“__type”:“File”, “name”:“profile.png”, “url”=>“”}}'

parse_filename[RW]
url[RW]

Public Class Methods

new(data) click to toggle source
# File lib/leancloud/datatypes.rb, line 308
def initialize(data)
  data = Hash[data.map{ |k, v| [k.to_s, v] }] # convert hash keys to strings
  @local_filename = data["local_filename"] if data["local_filename"]
  @parse_filename = data["name"]           if data["name"]
  @parse_filename = data["parse_filename"] if data["parse_filename"]
  @content_type   = data["content_type"]   if data["content_type"]
  @url            = data["url"]            if data["url"]
  @body           = data["body"]           if data["body"]
  @id             = data["id"]             if data["id"]
end

Public Instance Methods

==(other)
Alias for: eql?
as_json(*a)
Alias for: to_h
eql?(other) click to toggle source
# File lib/leancloud/datatypes.rb, line 319
def eql?(other)
  self.class.equal?(other.class) &&
    url == other.url
end
Also aliased as: ==
hash() click to toggle source
# File lib/leancloud/datatypes.rb, line 326
def hash
  url.hash
end
save() click to toggle source
# File lib/leancloud/datatypes.rb, line 330
def save
  uri = LC::Protocol.file_uri(@local_filename)
  resp = LC.client.request(uri, :post, @body, nil, @content_type)
  @parse_filename = resp["name"]
  @url = resp["url"]
  @id = resp["id"]
  resp
end
to_h(*a) click to toggle source
# File lib/leancloud/datatypes.rb, line 339
def to_h(*a)
  {
    Protocol::KEY_TYPE => Protocol::TYPE_FILE,
    "name" => @parse_filename,
    "url" => @url,
    "id" => @id
  }
end
Also aliased as: as_json
to_json(*a) click to toggle source
# File lib/leancloud/datatypes.rb, line 349
def to_json(*a)
to_h.to_json(*a)
end