Class: Parse::File
- Inherits:
-
Object
- Object
- Parse::File
- Defined in:
- lib/parse/datatypes.rb
Overview
File
tf = Parse::File.new(:body => “Hello World!”, :local_filename => “hello.txt”) tf.save
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
-
#content_type ⇒ Object
Returns the value of attribute content_type.
-
#local_filename ⇒ Object
‘{“__type”:“File”, “name”:“profile.png”, “url”=>“”}’.
-
#parse_filename ⇒ Object
eg “12-4-532d-d-g3-3-hello.text”.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
- #as_json(*a) ⇒ Object
- #eql?(other) ⇒ Boolean (also: #==)
- #hash ⇒ Object
-
#initialize(data) ⇒ File
constructor
A new instance of File.
- #save ⇒ Object
- #to_json(*a) ⇒ Object
Constructor Details
#initialize(data) ⇒ File
Returns a new instance of File.
297 298 299 300 301 302 303 304 305 |
# File 'lib/parse/datatypes.rb', line 297 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"] end |
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
294 295 296 |
# File 'lib/parse/datatypes.rb', line 294 def body @body end |
#content_type ⇒ Object
Returns the value of attribute content_type.
293 294 295 |
# File 'lib/parse/datatypes.rb', line 293 def content_type @content_type end |
#local_filename ⇒ Object
‘{“__type”:“File”, “name”:“profile.png”, “url”=>“”}’
291 292 293 |
# File 'lib/parse/datatypes.rb', line 291 def local_filename @local_filename end |
#parse_filename ⇒ Object
eg “12-4-532d-d-g3-3-hello.text”
292 293 294 |
# File 'lib/parse/datatypes.rb', line 292 def parse_filename @parse_filename end |
#url ⇒ Object
Returns the value of attribute url.
295 296 297 |
# File 'lib/parse/datatypes.rb', line 295 def url @url end |
Instance Method Details
#as_json(*a) ⇒ Object
326 327 328 329 330 331 332 |
# File 'lib/parse/datatypes.rb', line 326 def as_json(*a) { Protocol::KEY_TYPE => Protocol::TYPE_FILE, "name" => @parse_filename, "url" => @url } end |
#eql?(other) ⇒ Boolean Also known as: ==
307 308 309 310 |
# File 'lib/parse/datatypes.rb', line 307 def eql?(other) self.class.equal?(other.class) && url == other.url end |
#hash ⇒ Object
314 315 316 |
# File 'lib/parse/datatypes.rb', line 314 def hash url.hash end |
#save ⇒ Object
318 319 320 321 322 323 324 |
# File 'lib/parse/datatypes.rb', line 318 def save uri = Parse::Protocol.file_uri(@local_filename) resp = Parse.client.request(uri, :post, @body, nil, @content_type) @parse_filename = resp["name"] @url = resp["url"] resp end |
#to_json(*a) ⇒ Object
334 335 336 |
# File 'lib/parse/datatypes.rb', line 334 def to_json(*a) as_json.to_json(*a) end |