Class: CloudApp::Client
- Inherits:
-
Object
- Object
- CloudApp::Client
- Defined in:
- lib/cloudapp/client.rb
Overview
A client interface through which to interract with the CloudApp API.
Instance Method Summary collapse
-
#authenticate(username, password) ⇒ Hash
Sets the authentication credentials in a class variable.
-
#bookmark(*args) ⇒ CloudApp::Drop
Create one or more new bookmark drops.
-
#delete(id) ⇒ CloudApp::Drop
Send the drop to the trash.
-
#drop(id) ⇒ CloudApp::Drop
(also: #item)
Get metadata about a cl.ly URL like name, type, or view count.
-
#drops(opts = {}) ⇒ Array[CloudApp::Drop]
(also: #items)
Page through your drops.
-
#initialize(opts = {}) ⇒ CloudApp::Client
constructor
Creates a new CloudApp::Client instance.
-
#privacy(id, privacy = false) ⇒ CloudApp::Drop
Modify a drop with a private URL to have a public URL or vice versa.
-
#recover(id) ⇒ CloudApp::Drop
Recover a deleted drop from the trash.
-
#rename(id, name = "") ⇒ CloudApp::Drop
Change the name of the drop.
-
#upload(file, opts = {}) ⇒ CloudApp::Drop
Create a new drop by uploading a file.
Constructor Details
#initialize(opts = {}) ⇒ CloudApp::Client
Creates a new CloudApp::Client instance.
You can pass :username
and :password
parameters to the call.
52 53 54 55 56 |
# File 'lib/cloudapp/client.rb', line 52 def initialize(opts = {}) if opts[:username] && opts[:password] Base.authenticate(opts[:username], opts[:password]) end end |
Instance Method Details
#authenticate(username, password) ⇒ Hash
Sets the authentication credentials in a class variable.
63 64 65 |
# File 'lib/cloudapp/client.rb', line 63 def authenticate(username, password) Base.authenticate(username, password) end |
#bookmark(url, name = "") ⇒ CloudApp::Drop #bookmark(opts) ⇒ CloudApp::Drop
Create one or more new bookmark drops.
Requires authentication.
105 106 107 108 109 110 111 112 |
# File 'lib/cloudapp/client.rb', line 105 def bookmark(*args) if args[0].is_a? Array Drop.create(:bookmarks, args) else url, name = args[0], (args[1] || "") Drop.create(:bookmark, {:name => name, :redirect_url => url}) end end |
#delete(id) ⇒ CloudApp::Drop
Send the drop to the trash.
Finds the drop by it’s slug id, for example “2wr4”.
Requires authentication.
162 163 164 165 |
# File 'lib/cloudapp/client.rb', line 162 def delete(id) drop = Drop.find(id) drop.delete end |
#drop(id) ⇒ CloudApp::Drop Also known as: item
Get metadata about a cl.ly URL like name, type, or view count.
Finds the drop by it’s slug id, for example “2wr4”.
73 74 75 |
# File 'lib/cloudapp/client.rb', line 73 def drop(id) Drop.find(id) end |
#drops(opts = {}) ⇒ Array[CloudApp::Drop] Also known as: items
Page through your drops.
Requires authentication.
89 90 91 |
# File 'lib/cloudapp/client.rb', line 89 def drops(opts = {}) Drop.all(opts) end |
#privacy(id, privacy = false) ⇒ CloudApp::Drop
Modify a drop with a private URL to have a public URL or vice versa.
Finds the drop by it’s slug id, for example “2wr4”.
Requires authentication.
149 150 151 152 |
# File 'lib/cloudapp/client.rb', line 149 def privacy(id, privacy = false) drop = Drop.find(id) drop.update(:private => privacy) end |
#recover(id) ⇒ CloudApp::Drop
Recover a deleted drop from the trash.
Finds the drop by it’s slug id, for example “2wr4”.
Requires authentication.
175 176 177 178 |
# File 'lib/cloudapp/client.rb', line 175 def recover(id) drop = Drop.find(id) drop.recover end |
#rename(id, name = "") ⇒ CloudApp::Drop
Change the name of the drop.
Finds the drop by it’s slug id, for example “2wr4”.
Requires authentication.
135 136 137 138 |
# File 'lib/cloudapp/client.rb', line 135 def rename(id, name = "") drop = Drop.find(id) drop.update(:name => name) end |
#upload(file, opts = {}) ⇒ CloudApp::Drop
Create a new drop by uploading a file.
Requires authentication.
122 123 124 |
# File 'lib/cloudapp/client.rb', line 122 def upload(file, opts = {}) Drop.create(:upload, opts.merge(:file => file)) end |