Class: CloudApp::Drop
Overview
An ActiveResource-like interface through which to interract with CloudApp drops.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#content_url ⇒ Object
readonly
Returns the value of attribute content_url.
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#deleted_at ⇒ Object
readonly
Returns the value of attribute deleted_at.
-
#href ⇒ Object
readonly
Returns the value of attribute href.
-
#icon ⇒ Object
readonly
Returns the value of attribute icon.
-
#item_type ⇒ Object
readonly
Returns the value of attribute item_type.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#private ⇒ Object
readonly
Returns the value of attribute private.
-
#redirect_url ⇒ Object
readonly
Returns the value of attribute redirect_url.
-
#remote_url ⇒ Object
readonly
Returns the value of attribute remote_url.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
-
#updated_at ⇒ Object
readonly
Returns the value of attribute updated_at.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
-
#view_counter ⇒ Object
readonly
Returns the value of attribute view_counter.
Attributes inherited from Base
Class Method Summary collapse
-
.all(opts = {}) ⇒ Array[CloudApp::Drop]
Page through your drops.
-
.create(kind, opts = {}) ⇒ CloudApp::Drop
Create a new drop.
-
.delete(href) ⇒ CloudApp::Drop
Send a drop to the trash.
-
.find(id) ⇒ CloudApp::Drop
Get metadata about a cl.ly URL like name, type, or view count.
-
.recover(href) ⇒ CloudApp::Drop
Recover a drop from the trash.
-
.update(href, opts = {}) ⇒ CloudApp::Drop
Modify a drop.
Instance Method Summary collapse
-
#archive? ⇒ Boolean
Is the drop an archive?.
-
#audio? ⇒ Boolean
Is the drop an audio file?.
-
#bookmark? ⇒ Boolean
Is the drop a bookmark?.
-
#delete ⇒ CloudApp::Drop
Send the drop to the trash.
-
#image? ⇒ Boolean
Is the drop an image?.
-
#raw ⇒ String
Return the drops raw data as a string, useful for returning the text of documents.
-
#recover ⇒ CloudApp::Drop
Recover the drop from the trash.
-
#text? ⇒ Boolean
Is the drop a text file?.
-
#unknown? ⇒ Boolean
Is the drop an unknown file type?.
-
#update(opts = {}) ⇒ CloudApp::Drop
Modify the drop.
-
#video? ⇒ Boolean
Is the drop a video file?.
Methods inherited from Base
authenticate, bad_response, #initialize
Constructor Details
This class inherits a constructor from CloudApp::Base
Instance Attribute Details
#content_url ⇒ Object (readonly)
Returns the value of attribute content_url.
153 154 155 |
# File 'lib/cloudapp/drop.rb', line 153 def content_url @content_url end |
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
153 154 155 |
# File 'lib/cloudapp/drop.rb', line 153 def created_at @created_at end |
#deleted_at ⇒ Object (readonly)
Returns the value of attribute deleted_at.
153 154 155 |
# File 'lib/cloudapp/drop.rb', line 153 def deleted_at @deleted_at end |
#href ⇒ Object (readonly)
Returns the value of attribute href.
153 154 155 |
# File 'lib/cloudapp/drop.rb', line 153 def href @href end |
#icon ⇒ Object (readonly)
Returns the value of attribute icon.
153 154 155 |
# File 'lib/cloudapp/drop.rb', line 153 def icon @icon end |
#item_type ⇒ Object (readonly)
Returns the value of attribute item_type.
153 154 155 |
# File 'lib/cloudapp/drop.rb', line 153 def item_type @item_type end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
153 154 155 |
# File 'lib/cloudapp/drop.rb', line 153 def name @name end |
#private ⇒ Object (readonly)
Returns the value of attribute private.
153 154 155 |
# File 'lib/cloudapp/drop.rb', line 153 def private @private end |
#redirect_url ⇒ Object (readonly)
Returns the value of attribute redirect_url.
153 154 155 |
# File 'lib/cloudapp/drop.rb', line 153 def redirect_url @redirect_url end |
#remote_url ⇒ Object (readonly)
Returns the value of attribute remote_url.
153 154 155 |
# File 'lib/cloudapp/drop.rb', line 153 def remote_url @remote_url end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
153 154 155 |
# File 'lib/cloudapp/drop.rb', line 153 def source @source end |
#updated_at ⇒ Object (readonly)
Returns the value of attribute updated_at.
153 154 155 |
# File 'lib/cloudapp/drop.rb', line 153 def updated_at @updated_at end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
153 154 155 |
# File 'lib/cloudapp/drop.rb', line 153 def url @url end |
#view_counter ⇒ Object (readonly)
Returns the value of attribute view_counter.
153 154 155 |
# File 'lib/cloudapp/drop.rb', line 153 def view_counter @view_counter end |
Class Method Details
.all(opts = {}) ⇒ Array[CloudApp::Drop]
Page through your drops.
Requires authentication.
77 78 79 80 |
# File 'lib/cloudapp/drop.rb', line 77 def self.all(opts = {}) res = get "/items", {:query => (opts.empty? ? nil : opts), :digest_auth => @@auth} res.ok? ? res.collect{|i| Drop.new(i)} : bad_response(res) end |
.self.create(: bookmark, opts = {}) ⇒ CloudApp::Drop .self.create(: bookmarks, bookmarks) ⇒ CloudApp::Drop .self.create(: upload, opts = {}) ⇒ CloudApp::Drop
Create a new drop. Multiple bookmarks can be created at once by passing an array of bookmark options parameters.
Requires authentication.
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/cloudapp/drop.rb', line 99 def self.create(kind, opts = {}) case kind when :bookmark res = post "/items", {:body => {:item => opts}, :digest_auth => @@auth} when :bookmarks res = post "/items", {:body => {:items => opts}, :digest_auth => @@auth} when :upload r = get "/items/new", {:query => ({:item => {:private => opts[:private]}} if opts.has_key?(:private)), :digest_auth => @@auth} return bad_response(r) unless r.ok? res = post r['url'], Multipart.new(r['params'].merge!(:file => File.new(opts[:file]))).payload.merge!(:digest_auth => @@auth) else # TODO raise an error return false end res.ok? ? (res.is_a?(Array) ? res.collect{|i| Drop.new(i)} : Drop.new(res)) : bad_response(res) end |
.delete(href) ⇒ CloudApp::Drop
Send a drop to the trash.
Requires authentication.
136 137 138 139 140 |
# File 'lib/cloudapp/drop.rb', line 136 def self.delete(href) # Use delete on the Base class to avoid recursion res = Base.delete href, :digest_auth => @@auth res.ok? ? Drop.new(res) : bad_response(res) end |
.find(id) ⇒ CloudApp::Drop
Get metadata about a cl.ly URL like name, type, or view count.
Finds the drop by it’s slug id, for example “2wr4”.
62 63 64 65 |
# File 'lib/cloudapp/drop.rb', line 62 def self.find(id) res = get "http://cl.ly/#{id}" res.ok? ? Drop.new(res) : bad_response(res) end |
.recover(href) ⇒ CloudApp::Drop
Recover a drop from the trash.
Requires authentication.
148 149 150 151 |
# File 'lib/cloudapp/drop.rb', line 148 def self.recover(href) res = put href, {:body => {:deleted => true, :item => {:deleted_at => nil}}, :digest_auth => @@auth} res.ok? ? Drop.new(res) : bad_response(res) end |
.update(href, opts = {}) ⇒ CloudApp::Drop
Modify a drop. Can currently modify it’s name or security setting by passing parameters.
Requires authentication.
125 126 127 128 |
# File 'lib/cloudapp/drop.rb', line 125 def self.update(href, opts = {}) res = put href, {:body => {:item => opts}, :digest_auth => @@auth} res.ok? ? Drop.new(res) : bad_response(res) end |
Instance Method Details
#archive? ⇒ Boolean
Is the drop an archive?
204 205 206 |
# File 'lib/cloudapp/drop.rb', line 204 def archive? item_type == 'archive' end |
#audio? ⇒ Boolean
Is the drop an audio file?
211 212 213 |
# File 'lib/cloudapp/drop.rb', line 211 def audio? item_type == 'audio' end |
#bookmark? ⇒ Boolean
Is the drop a bookmark?
190 191 192 |
# File 'lib/cloudapp/drop.rb', line 190 def bookmark? item_type == 'bookmark' end |
#delete ⇒ CloudApp::Drop
Send the drop to the trash.
169 170 171 |
# File 'lib/cloudapp/drop.rb', line 169 def delete self.class.delete self.href end |
#image? ⇒ Boolean
Is the drop an image?
183 184 185 |
# File 'lib/cloudapp/drop.rb', line 183 def image? item_type == 'image' end |
#raw ⇒ String
Return the drops raw data as a string, useful for returning the text of documents
232 233 234 |
# File 'lib/cloudapp/drop.rb', line 232 def raw @raw ||= HTTParty.get(content_url).to_s end |
#recover ⇒ CloudApp::Drop
Recover the drop from the trash.
176 177 178 |
# File 'lib/cloudapp/drop.rb', line 176 def recover self.class.recover self.href end |
#text? ⇒ Boolean
Is the drop a text file?
197 198 199 |
# File 'lib/cloudapp/drop.rb', line 197 def text? item_type == 'text' end |
#unknown? ⇒ Boolean
Is the drop an unknown file type?
225 226 227 |
# File 'lib/cloudapp/drop.rb', line 225 def unknown? item_type == 'unknown' end |
#update(opts = {}) ⇒ CloudApp::Drop
Modify the drop. Can currently modify it’s name or security setting by passing parameters.
162 163 164 |
# File 'lib/cloudapp/drop.rb', line 162 def update(opts = {}) self.class.update self.href, opts end |
#video? ⇒ Boolean
Is the drop a video file?
218 219 220 |
# File 'lib/cloudapp/drop.rb', line 218 def video? item_type == 'video' end |