dropio 0.9.1 → 1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.rdoc +12 -0
- data/LICENSE.txt +1 -1
- data/Manifest +4 -3
- data/Rakefile +3 -3
- data/Readme.rdoc +1 -1
- data/dropio.gemspec +13 -10
- data/lib/dropio/api.rb +169 -0
- data/lib/dropio/asset.rb +40 -20
- data/lib/dropio/client.rb +159 -261
- data/lib/dropio/comment.rb +3 -3
- data/lib/dropio/drop.rb +58 -17
- data/lib/dropio/resource.rb +4 -0
- data/lib/dropio/subscription.rb +15 -0
- data/lib/dropio.rb +17 -18
- data/spec/dropio/api_spec.rb +0 -0
- data/spec/dropio/asset_spec.rb +90 -16
- data/spec/dropio/client_spec.rb +0 -322
- data/spec/dropio/comment_spec.rb +22 -7
- data/spec/dropio/drop_spec.rb +138 -12
- data/spec/dropio/subscription_spec.rb +0 -0
- data/spec/dropio_spec.rb +2 -2
- data/spec/spec_helper.rb +3 -0
- metadata +23 -11
- data/lib/dropio/client/mapper.rb +0 -47
- data/lib/dropio/client/multipart_post.rb +0 -35
- data/spec/dropio/client/mapper_spec.rb +0 -169
data/lib/dropio/client.rb
CHANGED
@@ -1,316 +1,214 @@
|
|
1
|
-
require 'rbconfig'
|
2
|
-
|
3
1
|
class Dropio::Client
|
4
|
-
|
2
|
+
attr_accessor :service
|
5
3
|
|
6
|
-
|
7
|
-
|
8
|
-
ruby_version = %w{MAJOR MINOR TEENY}.map { |k| Config::CONFIG[k] }.join(".")
|
9
|
-
"DropioAPI-Ruby/#{Dropio::VERSION} (Ruby #{ruby_version} #{Config::CONFIG["host"]}; +http://dropio.rubyforge.org/)"
|
4
|
+
def initialize
|
5
|
+
self.service = Dropio::Api.new
|
10
6
|
end
|
11
7
|
|
12
|
-
|
13
|
-
|
14
|
-
'User-Agent' => user_agent_string,
|
15
|
-
'Accept' => 'application/json'
|
16
|
-
}
|
17
|
-
|
18
|
-
# Takes a drop name and optional token and returns a +Drop+ or errors.
|
19
|
-
def find_drop(drop_name, token = nil)
|
20
|
-
uri = URI::HTTP.build({:path => drop_path(drop_name), :query => get_request_tokens(token)})
|
21
|
-
req = Net::HTTP::Get.new(uri.request_uri, DEFAULT_HEADER)
|
22
|
-
drop = nil
|
23
|
-
complete_request(req) { |body| drop = Mapper.map_drops(body) }
|
24
|
-
drop
|
8
|
+
def drop(drop_name, token = nil)
|
9
|
+
handle(:drop, self.service.drop(drop_name, token))
|
25
10
|
end
|
26
11
|
|
27
|
-
|
28
|
-
|
29
|
-
token = get_default_token(drop)
|
30
|
-
uri = URI::HTTP.build({:path => asset_path(drop), :query => get_request_tokens(token) + "&page=#{page}"})
|
31
|
-
req = Net::HTTP::Get.new(uri.request_uri, DEFAULT_HEADER)
|
32
|
-
assets = nil
|
33
|
-
complete_request(req) { |body| assets = Mapper.map_assets(drop, body) }
|
34
|
-
assets
|
12
|
+
def generate_drop_url(drop)
|
13
|
+
self.service.generate_drop_url(drop.name,drop.default_token)
|
35
14
|
end
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
token = get_default_token(asset.drop)
|
40
|
-
uri = URI::HTTP.build({:path => comment_path(asset.drop, asset), :query => get_request_tokens(token)})
|
41
|
-
req = Net::HTTP::Get.new(uri.request_uri, DEFAULT_HEADER)
|
42
|
-
comments = nil
|
43
|
-
complete_request(req) { |body| comments = Mapper.map_comments(asset, body) }
|
44
|
-
comments
|
15
|
+
|
16
|
+
def create_drop(params = {})
|
17
|
+
handle(:drop, self.service.create_drop(params))
|
45
18
|
end
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
drop = nil
|
56
|
-
complete_request(req) { |body| drop = Mapper.map_drops(body) }
|
57
|
-
drop
|
19
|
+
|
20
|
+
def update_drop(drop)
|
21
|
+
params = { :description => drop.description, :admin_email => drop.admin_email,
|
22
|
+
:email_key => drop.email_key, :default_view => drop.default_view,
|
23
|
+
:chat_password => drop.chat_password, :guests_can_comment => drop.guests_can_comment,
|
24
|
+
:guests_can_add => drop.guests_can_add, :guests_can_delete => drop.guests_can_delete,
|
25
|
+
:expiration_length => drop.expiration_length, :password => drop.password,
|
26
|
+
:admin_password => drop.admin_password, :premium_code => drop.premium_code }
|
27
|
+
handle(:drop, self.service.update_drop(drop.name,drop.admin_token,params))
|
58
28
|
end
|
59
29
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
token = get_admin_token(drop)
|
64
|
-
form = create_form :token => token,
|
65
|
-
:expiration_length => drop.expiration_length,
|
66
|
-
:guests_can_comment => drop.guests_can_comment,
|
67
|
-
:premium_code => drop.premium_code,
|
68
|
-
:guests_can_add => drop.guests_can_add,
|
69
|
-
:guests_can_delete => drop.guests_can_delete,
|
70
|
-
:password => drop.password,
|
71
|
-
:admin_password => drop.admin_password
|
72
|
-
req = Net::HTTP::Put.new(uri.request_uri, DEFAULT_HEADER)
|
73
|
-
req.set_form_data(form)
|
74
|
-
drop = nil
|
75
|
-
complete_request(req) { |body| drop = Mapper.map_drops(body) }
|
76
|
-
drop
|
30
|
+
def empty_drop(drop)
|
31
|
+
r = handle(:response, self.service.empty_drop(drop.name,drop.admin_token))
|
32
|
+
r["result"]
|
77
33
|
end
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
uri = URI::HTTP.build({:path => drop_path(drop)})
|
83
|
-
form = create_form( { :token => token })
|
84
|
-
req = Net::HTTP::Delete.new(uri.request_uri, DEFAULT_HEADER)
|
85
|
-
req.set_form_data(form)
|
86
|
-
complete_request(req)
|
87
|
-
true
|
34
|
+
|
35
|
+
def delete_drop(drop)
|
36
|
+
r = handle(:response, self.service.delete_drop(drop.name,drop.admin_token))
|
37
|
+
r["result"]
|
88
38
|
end
|
89
39
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
asset = nil
|
94
|
-
|
95
|
-
File.open(file_path, 'r') do |file|
|
96
|
-
uri = URI.parse(Dropio.upload_url)
|
97
|
-
req = Net::HTTP::Post.new(uri.path, DEFAULT_HEADER)
|
98
|
-
form = create_form( { :drop_name => drop.name, :token => token , :file => file } )
|
99
|
-
req.multipart_params = form
|
100
|
-
complete_request(req, uri.host) { |body| asset = Mapper.map_assets(drop, body) }
|
101
|
-
end
|
102
|
-
|
103
|
-
asset
|
40
|
+
def promote_nick(drop,nick)
|
41
|
+
r = handle(:response, self.service.promote_nick(drop.name,nick,drop.admin_token))
|
42
|
+
r["result"]
|
104
43
|
end
|
105
44
|
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
uri = URI::HTTP.build({:path => asset_path(drop)})
|
110
|
-
form = create_form( { :token => token, :title => title, :contents => contents })
|
111
|
-
req = Net::HTTP::Post.new(uri.request_uri, DEFAULT_HEADER)
|
112
|
-
req.set_form_data(form)
|
113
|
-
asset = nil
|
114
|
-
complete_request(req) { |body| asset = Mapper.map_assets(drop, body) }
|
115
|
-
asset
|
45
|
+
def drop_upload_code(drop)
|
46
|
+
r = handle(:response, self.service.drop_upload_code(drop.name,drop.default_token))
|
47
|
+
r["upload_code"]
|
116
48
|
end
|
117
|
-
|
118
|
-
# Creates a link +Asset+
|
49
|
+
|
119
50
|
def create_link(drop, url, title = nil, description = nil)
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
req = Net::HTTP::Post.new(uri.request_uri, DEFAULT_HEADER)
|
124
|
-
req.set_form_data(form)
|
125
|
-
asset = nil
|
126
|
-
complete_request(req) { |body| asset = Mapper.map_assets(drop, body) }
|
127
|
-
asset
|
51
|
+
a = handle(:asset, self.service.create_link(drop.name, url, title, description, drop.default_token))
|
52
|
+
a.drop = drop
|
53
|
+
a
|
128
54
|
end
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
form = create_form( { :token => token, :contents => comment.contents })
|
135
|
-
req = Net::HTTP::Put.new(uri.request_uri, DEFAULT_HEADER)
|
136
|
-
req.set_form_data(form)
|
137
|
-
complete_request(req) { |body| comment = Mapper.map_comments(comment.asset, body) }
|
138
|
-
comment
|
55
|
+
|
56
|
+
def create_note(drop, contents, title = nil)
|
57
|
+
a = handle(:asset, self.service.create_note(drop.name, contents, title, drop.default_token))
|
58
|
+
a.drop = drop
|
59
|
+
a
|
139
60
|
end
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
form = create_form( { :token => token })
|
146
|
-
req = Net::HTTP::Delete.new(uri.request_uri, DEFAULT_HEADER)
|
147
|
-
req.set_form_data(form)
|
148
|
-
complete_request(req)
|
149
|
-
true
|
61
|
+
|
62
|
+
def add_file(drop, file_path, comment = nil)
|
63
|
+
a = handle(:asset, self.service.add_file(drop.name, file_path, drop.default_token, comment))
|
64
|
+
a.drop = drop
|
65
|
+
a
|
150
66
|
end
|
151
67
|
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
form = create_form( { :token => token, :contents => contents })
|
157
|
-
req = Net::HTTP::Post.new(uri.request_uri, DEFAULT_HEADER)
|
158
|
-
req.set_form_data(form)
|
159
|
-
comment = nil
|
160
|
-
complete_request(req) { |body| comment = Mapper.map_comments(asset, body) }
|
161
|
-
comment
|
68
|
+
def add_file_from_url(drop, url)
|
69
|
+
a = handle(:asset, self.service.add_file_from_url(drop.name, url, drop.default_token))
|
70
|
+
a.drop = drop
|
71
|
+
a
|
162
72
|
end
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
73
|
+
|
74
|
+
def assets(drop, page = 1, order = :oldest)
|
75
|
+
assets = handle(:assets, self.service.assets(drop.name,page,order,drop.default_token))
|
76
|
+
assets.each{|a| a.drop = drop}
|
77
|
+
assets
|
168
78
|
end
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
79
|
+
|
80
|
+
def asset(drop, asset_name)
|
81
|
+
a = handle(:asset, self.service.asset(drop.name,asset_name,drop.default_token))
|
82
|
+
a.drop = drop
|
83
|
+
a
|
174
84
|
end
|
175
85
|
|
176
|
-
|
177
|
-
|
178
|
-
params = { :medium => "drop", :drop_name => drop_name }
|
179
|
-
send_asset(asset,params)
|
86
|
+
def generate_asset_url(asset)
|
87
|
+
self.service.generate_drop_url(asset.drop.name, asset.name, asset.drop.default_token)
|
180
88
|
end
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
uri = URI::HTTP.build({:path => asset_path(asset.drop, asset)})
|
186
|
-
form = create_form({ :token => token,
|
187
|
-
:title => asset.title,
|
188
|
-
:url => asset.url,
|
189
|
-
:description => asset.description,
|
190
|
-
:contents => asset.contents })
|
191
|
-
req = Net::HTTP::Put.new(uri.request_uri, DEFAULT_HEADER)
|
192
|
-
req.set_form_data(form)
|
193
|
-
complete_request(req) { |body| asset = Mapper.map_assets(asset.drop, body)}
|
194
|
-
asset
|
89
|
+
|
90
|
+
def asset_embed_code(asset)
|
91
|
+
r = handle(:response, self.service.asset_embed_code(asset.drop.name,asset.name,asset.drop.default_token))
|
92
|
+
r["embed_code"]
|
195
93
|
end
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
req = Net::HTTP::Delete.new(uri.request_uri, DEFAULT_HEADER)
|
203
|
-
req.set_form_data(form)
|
204
|
-
complete_request(req)
|
205
|
-
true
|
94
|
+
|
95
|
+
def update_asset(asset)
|
96
|
+
params = { :title => asset.title, :description => asset.description, :url => asset.url, :contents => asset.contents }
|
97
|
+
a = handle(:asset, self.service.update_asset(asset.drop.name,asset.name,params,asset.drop.default_token))
|
98
|
+
a.drop = asset.drop
|
99
|
+
a
|
206
100
|
end
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
101
|
+
|
102
|
+
def delete_asset(asset)
|
103
|
+
r = handle(:response, self.service.delete_asset(asset.drop.name,asset.name,asset.drop.default_token))
|
104
|
+
r["result"]
|
211
105
|
end
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
106
|
+
|
107
|
+
def send_asset_to_drop(asset, target_drop)
|
108
|
+
r = handle(:response, self.service.send_asset_to_drop(asset.drop.name, asset.name, target_drop.name, target_drop.default_token, asset.drop.default_token))
|
109
|
+
r["result"]
|
216
110
|
end
|
217
111
|
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
def signed_url(drop, asset = nil)
|
222
|
-
# 10 minute window.
|
223
|
-
expires = (Time.now.utc + 10*60).to_i
|
224
|
-
token = get_default_token(drop)
|
225
|
-
path = Dropio.base_url + "/#{drop.name}"
|
226
|
-
path += "/asset/#{asset.name}" if asset
|
227
|
-
path += "/from_api"
|
228
|
-
sig = Digest::SHA1.hexdigest("#{expires}+#{token}+#{drop.name}")
|
229
|
-
path + "?expires=#{expires}&signature=#{sig}"
|
112
|
+
def send_asset_to_fax(asset, fax_number)
|
113
|
+
r = handle(:response, self.service.send_asset_to_fax(asset.drop.name, asset.name, fax_number, asset.drop.default_token))
|
114
|
+
r["result"]
|
230
115
|
end
|
231
116
|
|
232
|
-
def
|
233
|
-
|
117
|
+
def send_asset_to_emails(asset, emails, message)
|
118
|
+
r = handle(:response, self.service.send_asset_to_emails(asset.drop.name, asset.name, emails, message, asset.drop.default_token))
|
119
|
+
r["result"]
|
234
120
|
end
|
235
121
|
|
236
|
-
def
|
237
|
-
|
238
|
-
|
239
|
-
form = create_form( { :token => token }.merge(params) )
|
240
|
-
req = Net::HTTP::Post.new(uri.request_uri, DEFAULT_HEADER)
|
241
|
-
req.set_form_data(form)
|
242
|
-
complete_request(req)
|
243
|
-
true
|
122
|
+
def copy_asset(asset,target_drop)
|
123
|
+
r = handle(:response, self.service.copy_asset(asset.drop.name,asset.name,target_drop.name,target_drop.default_token,asset.drop.default_token))
|
124
|
+
r["result"]
|
244
125
|
end
|
245
|
-
|
246
|
-
def
|
247
|
-
|
126
|
+
|
127
|
+
def move_asset(asset,target_drop)
|
128
|
+
r = handle(:response, self.service.move_asset(asset.drop.name,asset.name,target_drop.name,target_drop.default_token,asset.drop.default_token))
|
129
|
+
r["result"]
|
248
130
|
end
|
249
|
-
|
250
|
-
def
|
251
|
-
|
131
|
+
|
132
|
+
def comments(asset)
|
133
|
+
comments = handle(:comments, self.service.comments(asset.drop.name,asset.name,asset.drop.default_token))
|
134
|
+
comments.each{|c| c.asset = asset}
|
135
|
+
comments
|
136
|
+
end
|
137
|
+
|
138
|
+
def create_comment(asset, contents)
|
139
|
+
c = handle(:comment, self.service.create_comment(asset.drop.name,asset.name,contents,asset.drop.default_token))
|
140
|
+
c.asset = asset
|
141
|
+
c
|
142
|
+
end
|
143
|
+
|
144
|
+
def comment(asset, comment_id)
|
145
|
+
c = handle(:comment, self.service.comment(asset.drop.name,asset.name,comment_id,asset.drop.default_token))
|
146
|
+
c.asset = asset
|
147
|
+
c
|
148
|
+
end
|
149
|
+
|
150
|
+
def update_comment(comment)
|
151
|
+
c = handle(:comment, self.service.update_comment(comment.asset.drop.name,comment.asset.name,comment.id,comment.contents,comment.asset.drop.admin_token))
|
152
|
+
c.asset = comment.asset
|
153
|
+
c
|
154
|
+
end
|
155
|
+
|
156
|
+
def delete_comment(comment)
|
157
|
+
r = handle(:response, self.service.delete_comment(comment.asset.drop.name,comment.asset.name,comment.id,comment.asset.drop.admin_token))
|
158
|
+
r["result"]
|
252
159
|
end
|
253
160
|
|
254
|
-
def
|
255
|
-
|
161
|
+
def create_twitter_subscription(drop, username,password, message, events)
|
162
|
+
s = handle(:subscription, self.service.create_twitter_subscription(drop.name, username, password, message, events, drop.default_token))
|
163
|
+
s.drop = drop
|
164
|
+
s
|
256
165
|
end
|
257
166
|
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
167
|
+
def create_email_subscription(drop, emails, welcome_message, welcome_subject, welcome_from, message, events)
|
168
|
+
s = handle(:subscription, self.service.create_email_subscription(drop.name, emails, welcome_message, welcome_subject, welcome_from, message, events, drop.default_token))
|
169
|
+
s.drop = drop
|
170
|
+
s
|
262
171
|
end
|
263
172
|
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
173
|
+
def subscriptions(drop)
|
174
|
+
subscriptions = handle(:subscriptions, self.service.subscriptions(drop.name, drop.admin_token))
|
175
|
+
subscriptions.each{|s| s.drop = drop}
|
176
|
+
subscriptions
|
268
177
|
end
|
269
178
|
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
when String
|
276
|
-
drop
|
277
|
-
when nil
|
278
|
-
''
|
279
|
-
else
|
280
|
-
raise ArgumentError, "Client#drop_path takes a Drop or a String, got #{drop.inspect}"
|
179
|
+
private
|
180
|
+
|
181
|
+
def handle(type, response)
|
182
|
+
if response.code != 200
|
183
|
+
parse_response(response)
|
281
184
|
end
|
282
185
|
|
283
|
-
|
186
|
+
case type
|
187
|
+
when :drop then return Dropio::Drop.new(response)
|
188
|
+
when :asset then return Dropio::Asset.new(response)
|
189
|
+
when :assets then return response.collect{|a| Dropio::Asset.new(a)}
|
190
|
+
when :comment then return Comment.new(response)
|
191
|
+
when :comments then return response.collect{|c| Dropio::Comment.new(c)}
|
192
|
+
when :subscription then return Dropio::Subscription.new(response)
|
193
|
+
when :subscriptions then return response.collect{|s| Dropio::Subscription.new(s)}
|
194
|
+
when :response then return parse_response(response)
|
195
|
+
end
|
284
196
|
end
|
285
197
|
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
# http.set_debug_output $stderr
|
296
|
-
response = http.start { |http| http.request(request) }
|
297
|
-
|
298
|
-
case response
|
299
|
-
when Net::HTTPSuccess then yield response.body if block_given?
|
300
|
-
when Net::HTTPBadRequest then raise Dropio::RequestError, parse_error_message(response)
|
301
|
-
when Net::HTTPForbidden then raise Dropio::AuthorizationError, parse_error_message(response)
|
302
|
-
when Net::HTTPNotFound then raise Dropio::MissingResourceError, parse_error_message(response)
|
303
|
-
when Net::HTTPServerError then raise Dropio::ServerError, "There was a problem connecting to Drop.io."
|
304
|
-
else raise "Received an unexpected HTTP response: #{response}"
|
198
|
+
def parse_response(response)
|
199
|
+
case response.code
|
200
|
+
when 200 then return response
|
201
|
+
when 400 then raise Dropio::RequestError, parse_error_message(response)
|
202
|
+
when 403 then raise Dropio::AuthorizationError, parse_error_message(response)
|
203
|
+
when 404 then raise Dropio::MissingResourceError, parse_error_message(response)
|
204
|
+
when 500 then raise Dropio::ServerError, "There was a problem connecting to Drop.io."
|
205
|
+
else
|
206
|
+
raise "Received an unexpected HTTP response: #{response.code} #{response.body}"
|
305
207
|
end
|
306
|
-
|
307
|
-
response.body
|
308
208
|
end
|
309
209
|
|
310
210
|
# Extracts the error message from the response for the exception.
|
311
|
-
def parse_error_message(
|
312
|
-
error_hash = JSON.parse(response.body) rescue nil
|
313
|
-
|
211
|
+
def parse_error_message(error_hash)
|
314
212
|
if (error_hash && error_hash.is_a?(Hash) && error_hash["response"] && error_hash["response"]["message"])
|
315
213
|
return error_hash["response"]["message"]
|
316
214
|
else
|
@@ -318,4 +216,4 @@ class Dropio::Client
|
|
318
216
|
end
|
319
217
|
end
|
320
218
|
|
321
|
-
end
|
219
|
+
end
|
data/lib/dropio/comment.rb
CHANGED
@@ -4,12 +4,12 @@ class Dropio::Comment < Dropio::Resource
|
|
4
4
|
|
5
5
|
# Saves the comment back to drop.io
|
6
6
|
def save
|
7
|
-
Dropio::
|
7
|
+
Dropio::Resource.client.update_comment(self)
|
8
8
|
end
|
9
9
|
|
10
10
|
# Destroys the comment on drop.io. Don't try to use an Comment after destroying it.
|
11
|
-
def destroy
|
12
|
-
Dropio::
|
11
|
+
def destroy!
|
12
|
+
Dropio::Resource.client.delete_comment(self)
|
13
13
|
end
|
14
14
|
|
15
15
|
end
|
data/lib/dropio/drop.rb
CHANGED
@@ -1,54 +1,95 @@
|
|
1
1
|
class Dropio::Drop < Dropio::Resource
|
2
2
|
|
3
|
-
attr_accessor :name, :email, :voicemail, :conference, :fax, :rss, :guest_token,
|
4
|
-
:admin_token, :expiration_length, :guests_can_comment, :guests_can_add, :guests_can_delete,
|
5
|
-
:max_bytes, :current_bytes, :hidden_upload_url, :
|
3
|
+
attr_accessor :name, :email, :voicemail, :conference, :fax, :rss, :guest_token, :description,
|
4
|
+
:admin_token, :expires_at, :expiration_length, :guests_can_comment, :guests_can_add, :guests_can_delete,
|
5
|
+
:max_bytes, :current_bytes, :hidden_upload_url, :asset_count, :chat_password, :default_view,
|
6
|
+
:password, :admin_password, :premium_code, :admin_email, :email_key
|
7
|
+
|
8
|
+
# Gets the default token to be used, prefers the admin token.
|
9
|
+
def default_token
|
10
|
+
self.admin_token || self.guest_token
|
11
|
+
end
|
6
12
|
|
7
13
|
# Gets a list of assets associated with the Drop. Paginated at
|
8
|
-
def assets(page = 1)
|
9
|
-
Dropio::
|
14
|
+
def assets(page = 1, order = :oldest)
|
15
|
+
Dropio::Resource.client.assets(self, page, order)
|
10
16
|
end
|
11
17
|
|
12
18
|
# Finds a drop with +name+ and optional authorization +token+
|
13
19
|
def self.find(name, token = nil)
|
14
|
-
Dropio::
|
20
|
+
Dropio::Resource.client.drop(name, token)
|
15
21
|
end
|
16
22
|
|
17
23
|
# Creates a drop with an +attributes+ hash.
|
18
|
-
# Valid attributes: name (string), guests_can_comment (boolean), guests_can_add (boolean), guests_can_delete (boolean), expiration_length (string), password (string), admin_password (string), and premium_code (string)
|
24
|
+
# Valid attributes: name (string), default_view (string), guests_can_comment (boolean), guests_can_add (boolean), guests_can_delete (boolean), expiration_length (string), password (string), admin_password (string), and premium_code (string)
|
19
25
|
# Descriptions can be found here: http://groups.google.com/group/dropio-api/web/full-api-documentation
|
20
26
|
def self.create(attributes = {})
|
21
|
-
Dropio::
|
27
|
+
Dropio::Resource.client.create_drop(attributes)
|
28
|
+
end
|
29
|
+
|
30
|
+
# Gets the drop's embeddable uploader code
|
31
|
+
def upload_code
|
32
|
+
Dropio::Resource.client.drop_upload_code(self)
|
33
|
+
end
|
34
|
+
|
35
|
+
# Empties the drop, including it's assets.
|
36
|
+
def empty
|
37
|
+
Dropio::Resource.client.empty_drop(self)
|
38
|
+
end
|
39
|
+
|
40
|
+
# Promotes a nickname in the drop chat to admin.
|
41
|
+
def promote(nick)
|
42
|
+
Dropio::Resource.client.promote_nick(self,nick)
|
22
43
|
end
|
23
44
|
|
24
45
|
# Saves the Drop.
|
25
46
|
def save
|
26
|
-
Dropio::
|
47
|
+
Dropio::Resource.client.update_drop(self)
|
27
48
|
end
|
28
49
|
|
29
50
|
# Deletes the Drop from the system including all associated assets.
|
30
|
-
def destroy
|
31
|
-
Dropio::
|
51
|
+
def destroy!
|
52
|
+
Dropio::Resource.client.delete_drop(self)
|
53
|
+
end
|
54
|
+
|
55
|
+
# Adds a file to the Drop from a given +url+
|
56
|
+
def add_file_from_url(url)
|
57
|
+
Dropio::Resource.client.add_file_from_url(self,url)
|
32
58
|
end
|
33
59
|
|
34
60
|
# Adds a file to the Drop given the +file_path+.
|
35
|
-
def add_file(file_path)
|
36
|
-
Dropio::
|
61
|
+
def add_file(file_path, comment = nil)
|
62
|
+
Dropio::Resource.client.add_file(self, file_path, comment)
|
37
63
|
end
|
38
64
|
|
39
65
|
# Creates a note with a +title+ and +contents+
|
40
|
-
def create_note(title
|
41
|
-
Dropio::
|
66
|
+
def create_note(contents, title = nil)
|
67
|
+
Dropio::Resource.client.create_note(self, contents, title)
|
42
68
|
end
|
43
69
|
|
44
70
|
# Creates a link with a +url+, +title+, and +description+.
|
45
71
|
def create_link(url, title = nil, description = nil)
|
46
|
-
Dropio::
|
72
|
+
Dropio::Resource.client.create_link(self, url, title, description)
|
73
|
+
end
|
74
|
+
|
75
|
+
# Creates a Twitter Subscription
|
76
|
+
def create_twitter_subscription(username,password,message = nil, events = {})
|
77
|
+
Dropio::Resource.client.create_twitter_subscription(self,username,password,message,events)
|
78
|
+
end
|
79
|
+
|
80
|
+
# Creates an email Subscription
|
81
|
+
def create_email_subscription(email, message = nil, welcome_message = nil, welcome_subject = nil, welcome_from = nil, events = {})
|
82
|
+
Dropio::Resource.client.create_email_subscription(self,email,message,welcome_message,welcome_subject,welcome_from, events)
|
83
|
+
end
|
84
|
+
|
85
|
+
# Gets a list of Subscription objects.
|
86
|
+
def subscriptions
|
87
|
+
Dropio::Resource.client.subscriptions(self)
|
47
88
|
end
|
48
89
|
|
49
90
|
# Generates an authenticated URL that will bypass any login action.
|
50
91
|
def generate_url
|
51
|
-
Dropio::
|
92
|
+
Dropio::Resource.client.generate_drop_url(self)
|
52
93
|
end
|
53
94
|
|
54
95
|
end
|
data/lib/dropio/resource.rb
CHANGED
@@ -0,0 +1,15 @@
|
|
1
|
+
class Dropio::Subscription < Dropio::Resource
|
2
|
+
attr_accessor :id, :username, :message, :type
|
3
|
+
|
4
|
+
# Fetches a single Subscription
|
5
|
+
def self.find(id)
|
6
|
+
Dropio::Resource.client.subscription(id)
|
7
|
+
end
|
8
|
+
|
9
|
+
# Destroys the given subscription. Admin +token+ required
|
10
|
+
def destroy!(token)
|
11
|
+
Dropio::Resource.client.delete_subscription(self,token)
|
12
|
+
nil
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|