Class: Snapshot::Image
- Inherits:
-
Object
- Object
- Snapshot::Image
- Defined in:
- lib/snapshot/image.rb
Instance Attribute Summary collapse
-
#filesize ⇒ Object
Returns the value of attribute filesize.
-
#format ⇒ Object
Returns the value of attribute format.
-
#height ⇒ Object
Returns the value of attribute height.
-
#id ⇒ Object
Returns the value of attribute id.
-
#last_accessed_at ⇒ Object
Returns the value of attribute last_accessed_at.
-
#uploaded_at ⇒ Object
(also: #created_at)
Returns the value of attribute uploaded_at.
-
#width ⇒ Object
Returns the value of attribute width.
Class Method Summary collapse
-
.create(file) ⇒ Object
Uploads a file to the connected Snapshot account.
-
.destroy(id) ⇒ Object
Deletes a file from Snapshot.
-
.find(id) ⇒ Object
Finds a file on the connected Snapshot account.
Instance Method Summary collapse
-
#destroy ⇒ Object
Removes the image from the connect Snapshot account.
-
#url(&block) ⇒ Object
Return the URL of the image.
Instance Attribute Details
#filesize ⇒ Object
Returns the value of attribute filesize.
5 6 7 |
# File 'lib/snapshot/image.rb', line 5 def filesize @filesize end |
#format ⇒ Object
Returns the value of attribute format.
5 6 7 |
# File 'lib/snapshot/image.rb', line 5 def format @format end |
#height ⇒ Object
Returns the value of attribute height.
5 6 7 |
# File 'lib/snapshot/image.rb', line 5 def height @height end |
#id ⇒ Object
Returns the value of attribute id.
5 6 7 |
# File 'lib/snapshot/image.rb', line 5 def id @id end |
#last_accessed_at ⇒ Object
Returns the value of attribute last_accessed_at.
5 6 7 |
# File 'lib/snapshot/image.rb', line 5 def last_accessed_at @last_accessed_at end |
#uploaded_at ⇒ Object Also known as: created_at
Returns the value of attribute uploaded_at.
5 6 7 |
# File 'lib/snapshot/image.rb', line 5 def uploaded_at @uploaded_at end |
#width ⇒ Object
Returns the value of attribute width.
5 6 7 |
# File 'lib/snapshot/image.rb', line 5 def width @width end |
Class Method Details
.create(file) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/snapshot/image.rb', line 27 def create(file) file = File.open(file) if file.is_a?(String) result = Snapshot.connection.post('/', file: file) info = JSON.parse(result)['file'] self.new.tap do |img| img.filesize = info['size'].to_i img.format = info['type'] img.height = info['height'].to_i img.id = info['id'] img.uploaded_at = Time.at(info['uploaded_at'].to_i) img.width = info['width'].to_i end end |
.destroy(id) ⇒ Object
52 53 54 |
# File 'lib/snapshot/image.rb', line 52 def destroy(id) find(id).destroy end |
.find(id) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/snapshot/image.rb', line 66 def find(id) result = Snapshot.connection.get("/#{id}") info = JSON.parse(result) self.new.tap do |img| img.filesize = info['size'].to_i img.format = info['type'] img.height = info['height'].to_i img.id = info['id'] img.last_accessed_at = Time.at(info['last_accessed_at'].to_i) img.uploaded_at = Time.at(info['uploaded_at'].to_i) img.width = info['width'].to_i end rescue RestClient::ResourceNotFound nil end |
Instance Method Details
#destroy ⇒ Object
91 92 93 94 95 96 |
# File 'lib/snapshot/image.rb', line 91 def destroy Snapshot.connection.delete("/#{id}") true rescue RestClient::ResourceNotFound nil end |