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(url, name = "") ⇒ CloudApp::Item
Create a new cl.ly item by bookmarking a link.
-
#delete(id) ⇒ CloudApp::Item
Send an item to the trash.
-
#initialize(opts = {}) ⇒ CloudApp::Client
constructor
Creates a new CloudApp::Client instance.
-
#item(id) ⇒ CloudApp::Item
Get metadata about a cl.ly URL like name, type, or view count.
-
#items(opts = {}) ⇒ Array[CloudApp::Item]
Page through your items.
-
#privacy(id, privacy = false) ⇒ CloudApp::Item
Modify an item with a private URL to have a public URL or vice versa.
-
#rename(id, name = "") ⇒ CloudApp::Item
Change the name of an item.
-
#upload(file) ⇒ CloudApp::Item
Create a new cl.ly item 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.
41 42 43 44 45 |
# File 'lib/cloudapp/client.rb', line 41 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.
52 53 54 |
# File 'lib/cloudapp/client.rb', line 52 def authenticate(username, password) Base.authenticate(username, password) end |
#bookmark(url, name = "") ⇒ CloudApp::Item
Create a new cl.ly item by bookmarking a link.
Requires authentication.
87 88 89 |
# File 'lib/cloudapp/client.rb', line 87 def bookmark(url, name = "") Item.create(:bookmark, {:name => name, :redirect_url => url}) end |
#delete(id) ⇒ CloudApp::Item
Send an item to the trash.
Finds the item by it’s slug id, for example “2wr4”.
Requires authentication.
137 138 139 140 |
# File 'lib/cloudapp/client.rb', line 137 def delete(id) item = Item.find(id) item.class == Item ? item.delete : item end |
#item(id) ⇒ CloudApp::Item
Get metadata about a cl.ly URL like name, type, or view count.
Finds the item by it’s slug id, for example “2wr4”.
62 63 64 |
# File 'lib/cloudapp/client.rb', line 62 def item(id) Item.find(id) end |
#items(opts = {}) ⇒ Array[CloudApp::Item]
Page through your items.
Requires authentication.
76 77 78 |
# File 'lib/cloudapp/client.rb', line 76 def items(opts = {}) Item.all(opts) end |
#privacy(id, privacy = false) ⇒ CloudApp::Item
Modify an item with a private URL to have a public URL or vice versa.
Finds the item by it’s slug id, for example “2wr4”.
Requires authentication.
124 125 126 127 |
# File 'lib/cloudapp/client.rb', line 124 def privacy(id, privacy = false) item = Item.find(id) item.class == Item ? item.update(:private => privacy) : item end |
#rename(id, name = "") ⇒ CloudApp::Item
Change the name of an item.
Finds the item by it’s slug id, for example “2wr4”.
Requires authentication.
110 111 112 113 |
# File 'lib/cloudapp/client.rb', line 110 def rename(id, name = "") item = Item.find(id) item.class == Item ? item.update(:name => name) : item end |
#upload(file) ⇒ CloudApp::Item
Create a new cl.ly item by uploading a file.
Requires authentication.
97 98 99 |
# File 'lib/cloudapp/client.rb', line 97 def upload(file) Item.create(:upload, :file => file) end |