Class: Parse::File
- Inherits:
-
Object
- Object
- Parse::File
- Defined in:
- lib/parse/datatypes.rb
Overview
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
-
#client ⇒ Object
Returns the value of attribute client.
-
#content_type ⇒ Object
Returns the value of attribute content_type.
-
#local_filename ⇒ Object
Returns the value of attribute local_filename.
-
#parse_filename ⇒ Object
Returns the value of attribute parse_filename.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
- #eql?(other) ⇒ Boolean (also: #==)
- #hash ⇒ Object
-
#initialize(data, client = nil) ⇒ File
constructor
A new instance of File.
- #save ⇒ Object
- #to_h(*_a) ⇒ Object (also: #as_json)
- #to_json(*a) ⇒ Object
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
#body ⇒ Object
Returns the value of attribute body.
284 285 286 |
# File 'lib/parse/datatypes.rb', line 284 def body @body end |
#client ⇒ Object
Returns the value of attribute client.
286 287 288 |
# File 'lib/parse/datatypes.rb', line 286 def client @client end |
#content_type ⇒ Object
Returns the value of attribute content_type.
283 284 285 |
# File 'lib/parse/datatypes.rb', line 283 def content_type @content_type end |
#local_filename ⇒ Object
Returns the value of attribute local_filename.
281 282 283 |
# File 'lib/parse/datatypes.rb', line 281 def local_filename @local_filename end |
#parse_filename ⇒ Object
Returns the value of attribute parse_filename.
282 283 284 |
# File 'lib/parse/datatypes.rb', line 282 def parse_filename @parse_filename end |
#url ⇒ Object
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: ==
301 302 303 304 |
# File 'lib/parse/datatypes.rb', line 301 def eql?(other) self.class.equal?(other.class) && url == other.url end |
#hash ⇒ Object
307 308 309 |
# File 'lib/parse/datatypes.rb', line 307 def hash url.hash end |
#save ⇒ Object
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 |