Class: CloudApp::Drop

Inherits:
Base
  • Object
show all
Defined in:
lib/cloudapp/drop.rb

Overview

An ActiveResource-like interface through which to interract with CloudApp drops.

Examples:

Gets started by Authenticating

CloudApp.authenticate "username", "password"

Usage via the Drop class

# Find a single drop by it's slug
@drop = CloudApp::Drop.find "2wr4"

# Get a list of all drops
@drops = CloudApp::Drop.all

# Create a new bookmark
@drop = CloudApp::Drop.create :bookmark, :name => "CloudApp", :redirect_url => "http://getcloudapp.com"

# Create multiple bookmarks
bookmarks = [
  { :name => "Authur Dent", :redirect_url => "http://en.wikipedia.org/wiki/Arthur_Dent" },
  { :name => "Zaphod Beeblebrox", :redirect_url => "http://en.wikipedia.org/wiki/Zaphod_Beeblebrox" }
]
@drops = CloudApp::Drop.create :bookmarks, bookmarks

# Upload a file
@drop = CloudApp::Drop.create :upload, :file => "/path/to/image.png"
@drop = CloudApp::Drop.create :upload, :file => "/path/to/image.png", :private => true

# Rename a file
CloudApp::Drop.update "http://my.cl.ly/items/1912565", :name => "Big Screenshot"

# Set a drop's privacy
CloudApp::Drop.update "http://my.cl.ly/items/1912565", :private => true

# Delete a drop
CloudApp::Drop.delete "http://my.cl.ly/items/1912565"

# Recover a deleted drop
CloudApp::Drop.recover "http://my.cl.ly/items/1912565"

Usage via the class instance

# Rename a file
@drop.update :name => "Big Screenshot"

# Set the drop's privacy
@drop.update :private => true

# Delete a drop
@drop.delete

# Recover a deleted drop
@drop.recover

Direct Known Subclasses

Item

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods inherited from Base

authenticate

Constructor Details

- (Drop) initialize(attributes = {})

Create a new CloudApp::Drop object.

Only used internally.

Parameters:



162
163
164
# File 'lib/cloudapp/drop.rb', line 162

def initialize(attributes = {})
  load(attributes)
end

Instance Attribute Details

- (Object) content_url (readonly)

Returns the value of attribute content_url



153
154
155
# File 'lib/cloudapp/drop.rb', line 153

def content_url
  @content_url
end

- (Object) created_at (readonly)

Returns the value of attribute created_at



153
154
155
# File 'lib/cloudapp/drop.rb', line 153

def created_at
  @created_at
end

- (Object) deleted_at (readonly)

Returns the value of attribute deleted_at



153
154
155
# File 'lib/cloudapp/drop.rb', line 153

def deleted_at
  @deleted_at
end

- (Object) href (readonly)

Returns the value of attribute href



153
154
155
# File 'lib/cloudapp/drop.rb', line 153

def href
  @href
end

- (Object) icon (readonly)

Returns the value of attribute icon



153
154
155
# File 'lib/cloudapp/drop.rb', line 153

def icon
  @icon
end

- (Object) item_type (readonly)

Returns the value of attribute item_type



153
154
155
# File 'lib/cloudapp/drop.rb', line 153

def item_type
  @item_type
end

- (Object) name (readonly)

Returns the value of attribute name



153
154
155
# File 'lib/cloudapp/drop.rb', line 153

def name
  @name
end

- (Object) private (readonly)

Returns the value of attribute private



153
154
155
# File 'lib/cloudapp/drop.rb', line 153

def private
  @private
end

- (Object) redirect_url (readonly)

Returns the value of attribute redirect_url



153
154
155
# File 'lib/cloudapp/drop.rb', line 153

def redirect_url
  @redirect_url
end

- (Object) remote_url (readonly)

Returns the value of attribute remote_url



153
154
155
# File 'lib/cloudapp/drop.rb', line 153

def remote_url
  @remote_url
end

- (Object) updated_at (readonly)

Returns the value of attribute updated_at



153
154
155
# File 'lib/cloudapp/drop.rb', line 153

def updated_at
  @updated_at
end

- (Object) url (readonly)

Returns the value of attribute url



153
154
155
# File 'lib/cloudapp/drop.rb', line 153

def url
  @url
end

- (Object) view_counter (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

+ (Array[CloudApp::Drop]) all(opts = {})

Page through your drops.

Requires authentication.

Parameters:

  • opts (Hash) (defaults to: {})

    options parameters

Options Hash (opts):

  • :page (Integer)

    Page number starting at 1

  • :per_page (Integer)

    Number of items per page

  • :type (String)

    Filter items by type (image, bookmark, text, archive, audio, video, or unknown)

  • :deleted (Boolean)

    Show trashed drops

Returns:



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)} : res
end

+ (CloudApp::Drop) self.create(:bookmark, opts = {}) + (CloudApp::Drop) self.create(:bookmarks, bookmarks) + (CloudApp::Drop) self.create(:upload, opts = {})

Create a new drop. Multiple bookmarks can be created at once by passing an array of bookmark options parameters.

Requires authentication.

Overloads:

  • + (CloudApp::Drop) self.create(:bookmark, opts = {})

    Parameters:

    • opts (Hash)

      options paramaters

    Options Hash (opts):

    • :name (String)

      Name of bookmark (only required for :bookmark kind)

    • :redirect_url (String)

      Redirect URL (only required for :bookmark kind)

  • + (CloudApp::Drop) self.create(:bookmarks, bookmarks)

    Parameters:

    • bookmarks (Array)

      array of bookmark option parameters (containing :name and :redirect_url)

  • + (CloudApp::Drop) self.create(:upload, opts = {})

    Parameters:

    • opts (Hash)

      options paramaters

    Options Hash (opts):

    • :file (String)

      Path to file (only required for :upload kind)

    • :private (Boolean)

      override the account default privacy setting

Parameters:

  • kind (Symbol)

    type of drop (can be :bookmark, :bookmarks or :upload)

Returns:



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 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)) : res
end

+ (CloudApp::Drop) delete(href)

Send a drop to the trash.

Requires authentication.

Parameters:

  • href (String)

    href attribute of the drop

Returns:



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) : res
end

+ (CloudApp::Drop) find(id)

Get metadata about a cl.ly URL like name, type, or view count.

Finds the drop by it's slug id, for example "2wr4".

Parameters:

  • id (String)

    cl.ly slug id

Returns:



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) : res
end

+ (CloudApp::Drop) recover(href)

Recover a drop from the trash.

Requires authentication.

Parameters:

  • href (String)

    href attribute of the drop

Returns:



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) : res
end

+ (CloudApp::Drop) update(href, opts = {})

Modify a drop. Can currently modify it's name or security setting by passing parameters.

Requires authentication.

Parameters:

  • href (String)

    href attribute of drop

  • opts (Hash) (defaults to: {})

    options paramaters

Options Hash (opts):

  • :name (String)

    for renaming the drop

  • :privacy (Boolean)

    set drop privacy

Returns:



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) : res
end

Instance Method Details

- (CloudApp::Drop) delete

Send the drop to the trash.

Returns:



179
180
181
# File 'lib/cloudapp/drop.rb', line 179

def delete
  self.class.delete self.href
end

- (CloudApp::Drop) recover

Recover the drop from the trash.

Returns:



186
187
188
# File 'lib/cloudapp/drop.rb', line 186

def recover
  self.class.recover self.href
end

- (CloudApp::Drop) update(opts = {})

Modify the drop. Can currently modify it's name or security setting by passing parameters.

Parameters:

  • opts (Hash) (defaults to: {})

    options paramaters

Options Hash (opts):

  • :name (String)

    for renaming the drop

  • :privacy (Boolean)

    set the drop's privacy

Returns:



172
173
174
# File 'lib/cloudapp/drop.rb', line 172

def update(opts = {})
  self.class.update self.href, opts
end