Class: Parse::File

Inherits:
Object
  • Object
show all
Defined in:
lib/parse/datatypes.rb

Overview

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data, client = nil) ⇒ File

Returns a new instance of File.



288
289
290
291
292
293
294
295
296
297
298
299
# File 'lib/parse/datatypes.rb', line 288

def initialize(data, client = nil)
  # convert hash keys to strings
  data = Hash[data.map { |k, v| [k.to_s, v] }]

  @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']
  @client         = client || Parse.client
end

Instance Attribute Details

#bodyObject

Returns the value of attribute body.



284
285
286
# File 'lib/parse/datatypes.rb', line 284

def body
  @body
end

#clientObject

Returns the value of attribute client.



286
287
288
# File 'lib/parse/datatypes.rb', line 286

def client
  @client
end

#content_typeObject

Returns the value of attribute content_type.



283
284
285
# File 'lib/parse/datatypes.rb', line 283

def content_type
  @content_type
end

#local_filenameObject

Returns the value of attribute local_filename.



281
282
283
# File 'lib/parse/datatypes.rb', line 281

def local_filename
  @local_filename
end

#parse_filenameObject

Returns the value of attribute parse_filename.



282
283
284
# File 'lib/parse/datatypes.rb', line 282

def parse_filename
  @parse_filename
end

#urlObject

Returns the value of attribute url.



285
286
287
# File 'lib/parse/datatypes.rb', line 285

def url
  @url
end

Instance Method Details

#eql?(other) ⇒ Boolean Also known as: ==

Returns:

  • (Boolean)


301
302
303
304
# File 'lib/parse/datatypes.rb', line 301

def eql?(other)
  self.class.equal?(other.class) &&
    url == other.url
end

#hashObject



307
308
309
# File 'lib/parse/datatypes.rb', line 307

def hash
  url.hash
end

#saveObject



311
312
313
314
315
316
317
# File 'lib/parse/datatypes.rb', line 311

def save
  uri = Parse::Protocol.file_uri(@local_filename)
  resp = @client.request(uri, :post, @body, nil, @content_type)
  @parse_filename = resp['name']
  @url = resp['url']
  resp
end

#to_h(*_a) ⇒ Object Also known as: as_json



319
320
321
322
323
324
325
# File 'lib/parse/datatypes.rb', line 319

def to_h(*_a)
  {
    Protocol::KEY_TYPE => Protocol::TYPE_FILE,
    'name' => @parse_filename,
    'url' => @url
  }
end

#to_json(*a) ⇒ Object



328
329
330
# File 'lib/parse/datatypes.rb', line 328

def to_json(*a)
  to_h.to_json(*a)
end