cloudapp_api 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +85 -45
- data/VERSION +1 -1
- data/cloudapp_api.gemspec +21 -11
- data/lib/cloudapp/account.rb +65 -31
- data/lib/cloudapp/base.rb +3 -3
- data/lib/cloudapp/client.rb +85 -47
- data/lib/cloudapp/core_ext.rb +16 -0
- data/lib/cloudapp/drop.rb +197 -0
- data/lib/cloudapp/gift_card.rb +64 -0
- data/lib/cloudapp_api.rb +5 -5
- data/spec/cloudapp_account_spec.rb +27 -2
- data/spec/cloudapp_client_spec.rb +55 -28
- data/spec/cloudapp_drop_spec.rb +258 -0
- data/spec/cloudapp_gift_card_spec.rb +67 -0
- data/spec/cloudapp_item_spec.rb +73 -7
- data/spec/fakeweb_helper.rb +15 -10
- data/spec/stubs/account/stats +8 -0
- data/spec/stubs/{item → drop}/create +0 -0
- data/spec/stubs/{item → drop}/delete +0 -0
- data/spec/stubs/{item → drop}/index +0 -0
- data/spec/stubs/{item → drop}/new +3 -1
- data/spec/stubs/drop/new-private +17 -0
- data/spec/stubs/{item → drop}/show +0 -0
- data/spec/stubs/drop/show-private +19 -0
- data/spec/stubs/{item → drop}/update +0 -0
- data/spec/stubs/gift_card/redeem +16 -0
- data/spec/stubs/gift_card/show +16 -0
- metadata +64 -55
- data/lib/cloudapp/item.rb +0 -154
data/lib/cloudapp/item.rb
DELETED
@@ -1,154 +0,0 @@
|
|
1
|
-
module CloudApp
|
2
|
-
|
3
|
-
# An ActiveResource-like interface through which to interract with the CloudApp API.
|
4
|
-
#
|
5
|
-
# @example Gets started by Authenticating
|
6
|
-
# CloudApp.authenticate "username", "password"
|
7
|
-
#
|
8
|
-
# @example Usage via the Item class
|
9
|
-
# # Find a single item by it's slug
|
10
|
-
# item = CloudApp::Item.find "2wr4"
|
11
|
-
#
|
12
|
-
# # Get a list of all items
|
13
|
-
# items = CloudApp::Item.all
|
14
|
-
#
|
15
|
-
# # Create a new bookmark
|
16
|
-
# item = CloudApp::Item.create :bookmark, :name => "CloudApp", :redirect_url => "http://getcloudapp.com"
|
17
|
-
#
|
18
|
-
# # Upload a file
|
19
|
-
# item = CloudApp::Item.create :upload, :file => "/path/to/image.png"
|
20
|
-
#
|
21
|
-
# # Rename a file
|
22
|
-
# CloudApp::Item.update "http://my.cl.ly/items/1912565", :name => "Big Screenshot"
|
23
|
-
#
|
24
|
-
# # Set an items privacy
|
25
|
-
# CloudApp::Item.update "http://my.cl.ly/items/1912565", :private => true
|
26
|
-
#
|
27
|
-
# # Delete an item
|
28
|
-
# CloudApp::Item.delete "http://my.cl.ly/items/1912565"
|
29
|
-
#
|
30
|
-
# @example Usage via the class instance
|
31
|
-
# # Rename a file
|
32
|
-
# @item.update :name => "Big Screenshot"
|
33
|
-
#
|
34
|
-
# # Set an items privacy
|
35
|
-
# @item.update :private => true
|
36
|
-
#
|
37
|
-
# # Delete an item
|
38
|
-
# @tem.delete
|
39
|
-
#
|
40
|
-
class Item < Base
|
41
|
-
|
42
|
-
# Get metadata about a cl.ly URL like name, type, or view count.
|
43
|
-
#
|
44
|
-
# Finds the item by it's slug id, for example "2wr4".
|
45
|
-
#
|
46
|
-
# @param [String] id cl.ly slug id
|
47
|
-
# @return [CloudApp::Item]
|
48
|
-
def self.find(id)
|
49
|
-
res = get "http://cl.ly/#{id}"
|
50
|
-
res.ok? ? Item.new(res) : res
|
51
|
-
end
|
52
|
-
|
53
|
-
# Page through your items.
|
54
|
-
#
|
55
|
-
# Requires authentication.
|
56
|
-
#
|
57
|
-
# @param [Hash] opts options parameters
|
58
|
-
# @option opts [Integer] :page Page number starting at 1
|
59
|
-
# @option opts [Integer] :per_page Number of items per page
|
60
|
-
# @option opts [String] :type Filter items by type (image, bookmark, text, archive, audio, video, or unknown)
|
61
|
-
# @option opts [Boolean] :deleted Show trashed items
|
62
|
-
# @return [Array[CloudApp::Item]]
|
63
|
-
def self.all(opts = {})
|
64
|
-
res = get "/items?#{opts.to_params}", :digest_auth => @@auth
|
65
|
-
res.ok? ? res.collect{|i| Item.new(i)} : res
|
66
|
-
end
|
67
|
-
|
68
|
-
# Create a new cl.ly item.
|
69
|
-
#
|
70
|
-
# Requires authentication.
|
71
|
-
#
|
72
|
-
# @param [Symbol] kind type of cl.ly item (can be :bookmark or :upload)
|
73
|
-
# @param [Hash] opts options paramaters
|
74
|
-
# @option opts [String] :name Name of bookmark (only required for +:bookmark+ kind)
|
75
|
-
# @option opts [String] :redirect_url Redirect URL (only required for +:bookmark+ kind)
|
76
|
-
# @option opts [String] :file Path to file (only required for +:upload+ kind)
|
77
|
-
# @return [CloudApp::Item]
|
78
|
-
def self.create(kind, opts = {})
|
79
|
-
case kind
|
80
|
-
when :bookmark
|
81
|
-
res = post "/items", {:body => {:item => opts}, :digest_auth => @@auth}
|
82
|
-
when :upload
|
83
|
-
res = get "/items/new", :digest_auth => @@auth
|
84
|
-
return res unless res.ok?
|
85
|
-
res = post res['url'], Multipart.new(res['params'].merge!(:file => File.new(opts[:file]))).payload.merge!(:digest_auth => @@auth)
|
86
|
-
else
|
87
|
-
# TODO raise an error
|
88
|
-
return false
|
89
|
-
end
|
90
|
-
res.ok? ? Item.new(res) : res
|
91
|
-
end
|
92
|
-
|
93
|
-
# Modify a cl.ly item. Can currently modify it's name or security setting by passing parameters.
|
94
|
-
#
|
95
|
-
# Requires authentication.
|
96
|
-
#
|
97
|
-
# @param [String] href href attribute of cl.ly item
|
98
|
-
# @param [Hash] opts item parameters
|
99
|
-
# @option opts [String] :name for renaming the item
|
100
|
-
# @option opts [Boolean] :privacy set item privacy
|
101
|
-
# @return [CloudApp::Item]
|
102
|
-
def self.update(href, opts = {})
|
103
|
-
res = put href, {:body => {:item => opts}, :digest_auth => @@auth}
|
104
|
-
res.ok? ? Item.new(res) : res
|
105
|
-
end
|
106
|
-
|
107
|
-
# Send an item to the trash.
|
108
|
-
#
|
109
|
-
# Requires authentication.
|
110
|
-
#
|
111
|
-
# @param [String] href href attribute of cl.ly item
|
112
|
-
# @return [CloudApp::Item]
|
113
|
-
def self.delete(href)
|
114
|
-
res = Base.delete href, :digest_auth => @@auth
|
115
|
-
res.ok? ? Item.new(res) : res
|
116
|
-
end
|
117
|
-
|
118
|
-
attr_reader :href, :name, :private, :url, :content_url, :item_type, :view_counter,
|
119
|
-
:icon, :remote_url, :redirect_url, :created_at, :updated_at, :deleted_at
|
120
|
-
|
121
|
-
# Create a new CloudApp::Item object.
|
122
|
-
#
|
123
|
-
# Only used internally.
|
124
|
-
#
|
125
|
-
# @param [Hash] attributes
|
126
|
-
# @param [CloudApp::Item]
|
127
|
-
def initialize(attributes = {})
|
128
|
-
load(attributes)
|
129
|
-
end
|
130
|
-
|
131
|
-
# Modify the item. Can currently modify it's name or security setting by passing parameters.
|
132
|
-
#
|
133
|
-
# Requires authentication.
|
134
|
-
#
|
135
|
-
# @param [Hash] opts item parameters
|
136
|
-
# @option opts [String] :name for renaming the item
|
137
|
-
# @option opts [Boolean] :privacy set item privacy
|
138
|
-
# @return [CloudApp::Item]
|
139
|
-
def update(opts = {})
|
140
|
-
self.class.update self.href, opts
|
141
|
-
end
|
142
|
-
|
143
|
-
# Send the item to the trash.
|
144
|
-
#
|
145
|
-
# Requires authentication.
|
146
|
-
#
|
147
|
-
# @return [CloudApp::Item]
|
148
|
-
def delete
|
149
|
-
self.class.delete self.href
|
150
|
-
end
|
151
|
-
|
152
|
-
end
|
153
|
-
|
154
|
-
end
|