dropio 0.9.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/History.rdoc +3 -0
- data/LICENSE.txt +19 -0
- data/Manifest +22 -0
- data/Rakefile +62 -0
- data/Readme.rdoc +17 -0
- data/Todo.rdoc +5 -0
- data/dropio.gemspec +34 -0
- data/lib/dropio/asset.rb +60 -0
- data/lib/dropio/client/mapper.rb +47 -0
- data/lib/dropio/client/multipart_post.rb +35 -0
- data/lib/dropio/client.rb +321 -0
- data/lib/dropio/comment.rb +15 -0
- data/lib/dropio/drop.rb +54 -0
- data/lib/dropio/resource.rb +9 -0
- data/lib/dropio.rb +35 -0
- data/spec/dropio/asset_spec.rb +59 -0
- data/spec/dropio/client/mapper_spec.rb +169 -0
- data/spec/dropio/client_spec.rb +322 -0
- data/spec/dropio/comment_spec.rb +23 -0
- data/spec/dropio/drop_spec.rb +24 -0
- data/spec/dropio_spec.rb +8 -0
- data/spec/spec.opts +2 -0
- data/spec/spec_helper.rb +42 -0
- metadata +93 -0
data/lib/dropio/drop.rb
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
class Dropio::Drop < Dropio::Resource
|
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, :upload_url, :password, :admin_password, :premium_code
|
6
|
+
|
7
|
+
# Gets a list of assets associated with the Drop. Paginated at
|
8
|
+
def assets(page = 1)
|
9
|
+
Dropio::Client.instance.find_assets(self, page)
|
10
|
+
end
|
11
|
+
|
12
|
+
# Finds a drop with +name+ and optional authorization +token+
|
13
|
+
def self.find(name, token = nil)
|
14
|
+
Dropio::Client.instance.find_drop(name, token)
|
15
|
+
end
|
16
|
+
|
17
|
+
# 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)
|
19
|
+
# Descriptions can be found here: http://groups.google.com/group/dropio-api/web/full-api-documentation
|
20
|
+
def self.create(attributes = {})
|
21
|
+
Dropio::Client.instance.create_drop(attributes)
|
22
|
+
end
|
23
|
+
|
24
|
+
# Saves the Drop.
|
25
|
+
def save
|
26
|
+
Dropio::Client.instance.save_drop(self)
|
27
|
+
end
|
28
|
+
|
29
|
+
# Deletes the Drop from the system including all associated assets.
|
30
|
+
def destroy
|
31
|
+
Dropio::Client.instance.destroy_drop(self)
|
32
|
+
end
|
33
|
+
|
34
|
+
# Adds a file to the Drop given the +file_path+.
|
35
|
+
def add_file(file_path)
|
36
|
+
Dropio::Client.instance.add_file(self, file_path)
|
37
|
+
end
|
38
|
+
|
39
|
+
# Creates a note with a +title+ and +contents+
|
40
|
+
def create_note(title,contents)
|
41
|
+
Dropio::Client.instance.create_note(self, title, contents)
|
42
|
+
end
|
43
|
+
|
44
|
+
# Creates a link with a +url+, +title+, and +description+.
|
45
|
+
def create_link(url, title = nil, description = nil)
|
46
|
+
Dropio::Client.instance.create_link(self, url, title, description)
|
47
|
+
end
|
48
|
+
|
49
|
+
# Generates an authenticated URL that will bypass any login action.
|
50
|
+
def generate_url
|
51
|
+
Dropio::Client.instance.generate_drop_url(self)
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
data/lib/dropio.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
module Dropio
|
2
|
+
VERSION = '0.9.0'
|
3
|
+
|
4
|
+
class MissingResourceError < Exception; end
|
5
|
+
class AuthorizationError < Exception; end
|
6
|
+
class RequestError < Exception; end
|
7
|
+
class ServerError < Exception; end
|
8
|
+
|
9
|
+
class << self
|
10
|
+
attr_accessor :api_key, :base_url, :api_url, :upload_url
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
Dropio.base_url = "http://drop.io"
|
16
|
+
Dropio.api_url = "http://api.drop.io"
|
17
|
+
Dropio.upload_url = "http://assets.drop.io/upload"
|
18
|
+
|
19
|
+
require 'net/http'
|
20
|
+
require 'uri'
|
21
|
+
require 'singleton'
|
22
|
+
require 'rubygems'
|
23
|
+
require 'mime/types'
|
24
|
+
require 'base64'
|
25
|
+
require 'cgi'
|
26
|
+
require 'json'
|
27
|
+
require 'digest/sha1'
|
28
|
+
|
29
|
+
require 'dropio/client'
|
30
|
+
require 'dropio/client/mapper'
|
31
|
+
require 'dropio/client/multipart_post'
|
32
|
+
require 'dropio/resource'
|
33
|
+
require 'dropio/drop'
|
34
|
+
require 'dropio/asset'
|
35
|
+
require 'dropio/comment'
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe Asset do
|
4
|
+
before(:each) do
|
5
|
+
@asset = Asset.new
|
6
|
+
@client = stub(Client)
|
7
|
+
Client.stub!(:instance).and_return(@client)
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should have the attributes of an Asset" do
|
11
|
+
@asset.should respond_to(:name, :type, :title, :description, :filesize,
|
12
|
+
:created_at, :thumbnail, :status, :file,
|
13
|
+
:converted, :hidden_url, :pages, :duration,
|
14
|
+
:artist, :track_title, :height, :width,
|
15
|
+
:contents, :url)
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should have comments" do
|
19
|
+
@comment = stub(Comment)
|
20
|
+
@client.stub!(:find_comments).with(@asset).and_return([@comment])
|
21
|
+
@asset.comments.should == [@comment]
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should create comments" do
|
25
|
+
@comment = stub(Comment)
|
26
|
+
@client.should_receive(:create_comment).with(@asset, "Totally rad asset, bro!").and_return(@comment)
|
27
|
+
@asset.create_comment("Totally rad asset, bro!").should == @comment
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should save itself" do
|
31
|
+
@client.should_receive(:save_asset).with(@asset)
|
32
|
+
@asset.save
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should destroy itself" do
|
36
|
+
@client.should_receive(:destroy_asset).with(@asset)
|
37
|
+
@asset.destroy!
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should be faxable if and only if it's a document" do
|
41
|
+
@asset.type = "Document"
|
42
|
+
@asset.should be_faxable
|
43
|
+
@asset.type = "Video"
|
44
|
+
@asset.should_not be_faxable
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should fax itself to a phone number" do
|
48
|
+
@asset.type = "Document"
|
49
|
+
@client.should_receive(:send_to_fax).with(@asset,"234-567-8901")
|
50
|
+
@asset.send_to_fax("234-567-8901")
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should not fax itself if it's not faxable" do
|
54
|
+
@asset.type = "Video"
|
55
|
+
@client.should_not_receive(:send_to_fax)
|
56
|
+
# TODO: Make this a specific error.
|
57
|
+
lambda { @asset.send_to_fax("234-567-8901") }.should raise_error
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,169 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../spec_helper'
|
2
|
+
|
3
|
+
describe Client::Mapper do
|
4
|
+
it "should parse Drops" do
|
5
|
+
test_drop = Client::Mapper.map_drops <<-RESPONSE
|
6
|
+
{"rss":"http:\/\/drop.io\/k4gpvnty6tw9ho8u3j4w\/b9b2c8f2b8e655679d2fb62b83f8efec4fb4c8af\/test_drop.rss",
|
7
|
+
"voicemail":"646-495-9201 x 02302",
|
8
|
+
"email":"test_drop@drop.io",
|
9
|
+
"admin_token":"A97KQ4Vk7qQU90",
|
10
|
+
"fax":"856-632-1999",
|
11
|
+
"conference":" 218-486-3891 x 915088666",
|
12
|
+
"name":"test_drop",
|
13
|
+
"upload_url":"http:\/\/assets.drop.io\/upload",
|
14
|
+
"guests_can_add":"true",
|
15
|
+
"guests_can_comment":"true",
|
16
|
+
"guests_can_delete":"false",
|
17
|
+
"current_bytes":51488,
|
18
|
+
"max_bytes":104857600.0,
|
19
|
+
"expiration_length":"1_YEAR_FROM_LAST_VIEW",
|
20
|
+
"delete_permission_type":"ALLOWED"}
|
21
|
+
RESPONSE
|
22
|
+
|
23
|
+
test_drop.should be_an_instance_of(Drop)
|
24
|
+
test_drop.rss.should == "http:\/\/drop.io\/k4gpvnty6tw9ho8u3j4w\/b9b2c8f2b8e655679d2fb62b83f8efec4fb4c8af\/test_drop.rss"
|
25
|
+
test_drop.voicemail.should == "646-495-9201 x 02302"
|
26
|
+
test_drop.email.should == "test_drop@drop.io"
|
27
|
+
test_drop.admin_token.should == "A97KQ4Vk7qQU90"
|
28
|
+
test_drop.fax.should == "856-632-1999"
|
29
|
+
test_drop.conference.should == " 218-486-3891 x 915088666"
|
30
|
+
test_drop.name.should == "test_drop"
|
31
|
+
test_drop.upload_url.should == "http:\/\/assets.drop.io\/upload"
|
32
|
+
test_drop.guests_can_add.should == "true"
|
33
|
+
test_drop.guests_can_comment.should == "true"
|
34
|
+
test_drop.guests_can_delete.should == "false"
|
35
|
+
test_drop.current_bytes.should == 51488
|
36
|
+
test_drop.max_bytes.should == 104857600.0
|
37
|
+
test_drop.expiration_length.should == "1_YEAR_FROM_LAST_VIEW"
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should parse lists of Drops" do
|
41
|
+
drops = Client::Mapper.map_drops <<-RESPONSE
|
42
|
+
[{"rss":"http:\/\/drop.io\/k4gpvnty6tw9ho8u3j4w\/b9b2c8f2b8e655679d2fb62b83f8efec4fb4c8af\/test_drop.rss",
|
43
|
+
"voicemail":"646-495-9201 x 02302",
|
44
|
+
"email":"test_drop@drop.io",
|
45
|
+
"admin_token":"A97KQ4Vk7qQU90",
|
46
|
+
"fax":"856-632-1999",
|
47
|
+
"conference":" 218-486-3891 x 915088666",
|
48
|
+
"name":"test_drop",
|
49
|
+
"upload_url":"http:\/\/assets.drop.io\/upload",
|
50
|
+
"guests_can_add":"true",
|
51
|
+
"guests_can_comment":"true",
|
52
|
+
"guests_can_delete":"false",
|
53
|
+
"current_bytes":51488,
|
54
|
+
"max_bytes":104857600.0,
|
55
|
+
"expiration_length":"1_YEAR_FROM_LAST_VIEW"},
|
56
|
+
{"current_bytes":178857,
|
57
|
+
"max_bytes":104857600.0,
|
58
|
+
"voicemail":"646-495-9201 x 72025",
|
59
|
+
"admin_token":"8a8vfzfvs2",
|
60
|
+
"email":"0sdcmz7@drop.io",
|
61
|
+
"upload_url":"http:\/\/assets.drop.io\/upload",
|
62
|
+
"guests_can_add":"true",
|
63
|
+
"guests_can_comment":"true",
|
64
|
+
"guests_can_delete":"false",
|
65
|
+
"conference":" 218-486-3891 x 680277944",
|
66
|
+
"name":"0sdcmz7",
|
67
|
+
"expiration_length":"1_YEAR_FROM_LAST_VIEW",
|
68
|
+
"fax":"856-632-1999",
|
69
|
+
"rss":"http:\/\/drop.io\/no9mbevuq3ttmfi6kqen\/3ec4f87d720032bae579cca40740e5e4b267e090\/0sdcmz7.rss"}]
|
70
|
+
RESPONSE
|
71
|
+
|
72
|
+
drops.should be_an_instance_of(Array)
|
73
|
+
drops.each_should be_an_instance_of(Drop)
|
74
|
+
drops[0].name.should == "test_drop"
|
75
|
+
drops[1].name.should == "0sdcmz7"
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should parse Assets" do
|
79
|
+
parent_drop = stub(Drop)
|
80
|
+
audio = Client::Mapper.map_assets parent_drop, <<-RESPONSE
|
81
|
+
{"type":"audio",
|
82
|
+
"thumbnail":"http:\/\/drop.io\/download\/public\/vhahbqybv2dx2vdh0z7c\/8c525895399b8eafcd1621b4bd001ee1797e6679\/1c073ae0-7d29-012b-f659-002241261481\/316995b0-7d2e-012b-b8db-002241261481\/",
|
83
|
+
"status":"converted",
|
84
|
+
"filesize":178857,
|
85
|
+
"name":"audio",
|
86
|
+
"file":"http:\/\/drop.io\/download\/48f660ba\/b3c057eb4ce606f2f9f478379ea94ab703416ab3\/1c073ae0-7d29-012b-f659-002241261481\/316995b0-7d2e-012b-b8db-002241261481\/audio.mp3\/audio.mp3",
|
87
|
+
"duration":11,
|
88
|
+
"track_title":"Unknown",
|
89
|
+
"artist":"Unknown",
|
90
|
+
"created_at":"2008/10/15 21:28:55 +0000",
|
91
|
+
"converted":"http:\/\/drop.io\/download\/48f660ba\/26f6688a110f481b169daaa0a023656d4688dac0\/1c073ae0-7d29-012b-f659-002241261481\/316995b0-7d2e-012b-b8db-002241261481\/converted-audio_converted.mp3"}
|
92
|
+
RESPONSE
|
93
|
+
|
94
|
+
audio.should be_an_instance_of(Asset)
|
95
|
+
audio.drop.should == parent_drop
|
96
|
+
audio.type.should == "audio"
|
97
|
+
audio.thumbnail.should == "http:\/\/drop.io\/download\/public\/vhahbqybv2dx2vdh0z7c\/8c525895399b8eafcd1621b4bd001ee1797e6679\/1c073ae0-7d29-012b-f659-002241261481\/316995b0-7d2e-012b-b8db-002241261481\/"
|
98
|
+
audio.status.should == "converted"
|
99
|
+
audio.filesize.should == 178857
|
100
|
+
audio.name.should == "audio"
|
101
|
+
audio.file.should == "http:\/\/drop.io\/download\/48f660ba\/b3c057eb4ce606f2f9f478379ea94ab703416ab3\/1c073ae0-7d29-012b-f659-002241261481\/316995b0-7d2e-012b-b8db-002241261481\/audio.mp3\/audio.mp3"
|
102
|
+
audio.duration.should == 11
|
103
|
+
audio.track_title.should == "Unknown"
|
104
|
+
audio.artist.should == "Unknown"
|
105
|
+
audio.created_at.should == "2008/10/15 21:28:55 +0000"
|
106
|
+
audio.converted.should == "http:\/\/drop.io\/download\/48f660ba\/26f6688a110f481b169daaa0a023656d4688dac0\/1c073ae0-7d29-012b-f659-002241261481\/316995b0-7d2e-012b-b8db-002241261481\/converted-audio_converted.mp3"
|
107
|
+
end
|
108
|
+
|
109
|
+
it "should parse lists of Assets" do
|
110
|
+
parent_drop = stub(Drop)
|
111
|
+
assets = Client::Mapper.map_assets parent_drop, <<-RESPONSE
|
112
|
+
[{"type":"note",
|
113
|
+
"status":"converted",
|
114
|
+
"filesize":109,
|
115
|
+
"name":"about-these-files",
|
116
|
+
"contents":"These files are vital to our mission. <strong>Please<\/strong> do not delete them.<br \/><br \/>Thank you.",
|
117
|
+
"title":"About these files",
|
118
|
+
"created_at":"2008/10/15 21:21:49 +0000"},
|
119
|
+
{"type":"audio",
|
120
|
+
"thumbnail":"http:\/\/drop.io\/download\/public\/vhahbqybv2dx2vdh0z7c\/8c525895399b8eafcd1621b4bd001ee1797e6679\/1c073ae0-7d29-012b-f659-002241261481\/316995b0-7d2e-012b-b8db-002241261481\/",
|
121
|
+
"status":"converted",
|
122
|
+
"filesize":178857,
|
123
|
+
"name":"audio",
|
124
|
+
"file":"http:\/\/drop.io\/download\/48f660ba\/b3c057eb4ce606f2f9f478379ea94ab703416ab3\/1c073ae0-7d29-012b-f659-002241261481\/316995b0-7d2e-012b-b8db-002241261481\/audio.mp3\/audio.mp3",
|
125
|
+
"duration":11,
|
126
|
+
"track_title":"Unknown",
|
127
|
+
"artist":"Unknown",
|
128
|
+
"created_at":"2008/10/15 21:28:55 +0000",
|
129
|
+
"converted":"http:\/\/drop.io\/download\/48f660ba\/26f6688a110f481b169daaa0a023656d4688dac0\/1c073ae0-7d29-012b-f659-002241261481\/316995b0-7d2e-012b-b8db-002241261481\/converted-audio_converted.mp3"}]
|
130
|
+
RESPONSE
|
131
|
+
|
132
|
+
assets.should be_an_instance_of(Array)
|
133
|
+
assets.each_should be_an_instance_of(Asset)
|
134
|
+
assets[0].name.should == "about-these-files"
|
135
|
+
assets[1].name.should == "audio"
|
136
|
+
end
|
137
|
+
|
138
|
+
it "should parse Comments" do
|
139
|
+
parent_asset = stub(Asset)
|
140
|
+
comment = Client::Mapper.map_comments parent_asset, <<-RESPONSE
|
141
|
+
{"created_at":"2008/09/17 20:47:47 +0000",
|
142
|
+
"id":1,
|
143
|
+
"contents":"This is my comment content."}
|
144
|
+
RESPONSE
|
145
|
+
|
146
|
+
comment.should be_an_instance_of(Comment)
|
147
|
+
comment.asset.should == parent_asset
|
148
|
+
comment.created_at.should == "2008/09/17 20:47:47 +0000"
|
149
|
+
comment.id.should == 1
|
150
|
+
comment.contents.should == "This is my comment content."
|
151
|
+
end
|
152
|
+
|
153
|
+
it "should parse lists of Comments" do
|
154
|
+
parent_asset = stub(Asset)
|
155
|
+
comments = Client::Mapper.map_comments parent_asset, <<-RESPONSE
|
156
|
+
[{"contents":"Really? Looks like a waste of space to me. I'm going to delete some of these...",
|
157
|
+
"created_at":"2008/10/15 21:44:24 +0000",
|
158
|
+
"id":1},
|
159
|
+
{"contents":"DON'T DO IT!!",
|
160
|
+
"created_at":"2008/10/15 21:44:36 +0000",
|
161
|
+
"id":2}]
|
162
|
+
RESPONSE
|
163
|
+
|
164
|
+
comments.should be_an_instance_of(Array)
|
165
|
+
comments.each_should be_an_instance_of(Comment)
|
166
|
+
comments[0].contents.should =~ /waste of space/
|
167
|
+
comments[1].contents.should =~ /DON'T/
|
168
|
+
end
|
169
|
+
end
|
@@ -0,0 +1,322 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe Client do
|
4
|
+
def mock_http(method, path, response, form_data = nil)
|
5
|
+
request_klass = { :get => Net::HTTP::Get,
|
6
|
+
:post => Net::HTTP::Post,
|
7
|
+
:put => Net::HTTP::Put,
|
8
|
+
:delete => Net::HTTP::Delete }[method]
|
9
|
+
raise "Don't know how to mock a #{method.inspect} HTTP call." if request_klass.nil?
|
10
|
+
request = mock(request_klass)
|
11
|
+
request.should_receive(:set_form_data).with(form_data) if form_data
|
12
|
+
request_klass.stub!(:new).with(path, Client::DEFAULT_HEADER).and_return(request)
|
13
|
+
|
14
|
+
http = mock(Net::HTTP)
|
15
|
+
Net::HTTP.stub!(:new).with("api.drop.io").and_return(http)
|
16
|
+
http.stub!(:start).and_yield(http)
|
17
|
+
http.stub!(:request).with(request).and_return(response)
|
18
|
+
end
|
19
|
+
|
20
|
+
def stub_asset(more_stubs={})
|
21
|
+
stub Asset, [:drop, :name, :type, :title, :description, :filesize, :created_at,
|
22
|
+
:thumbnail, :status, :file, :converted, :hidden_url, :pages,
|
23
|
+
:duration, :artist, :track_title, :height, :width, :contents, :url].
|
24
|
+
inject({}) { |stubs, key| stubs[key] = nil; stubs }.merge(more_stubs)
|
25
|
+
end
|
26
|
+
|
27
|
+
before(:each) do
|
28
|
+
# Don't allow HTTPRequests to be created without being
|
29
|
+
# specifically stubbed, typically with mock_http above.
|
30
|
+
[Net::HTTP::Get, Net::HTTP::Post, Net::HTTP::Put, Net::HTTP::Delete].each do |request_klass|
|
31
|
+
request_klass.stub!(:new).with do |*args|
|
32
|
+
raise "Created an unexpected #{request_klass}!\n#{request_klass}.new(#{args.map { |e| e.inspect }.join(", ")})"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
Dropio.api_url = "http://api.drop.io"
|
37
|
+
Dropio.api_key = "43myapikey13"
|
38
|
+
|
39
|
+
@api_response_body = stub("API Response Body")
|
40
|
+
@api_response = stub(Net::HTTPSuccess, :body => @api_response_body)
|
41
|
+
|
42
|
+
@mydrop = stub(Drop, :name => 'mydrop', :admin_token => '93mydroptoken97')
|
43
|
+
@note = stub_asset(:drop => @mydrop, :name => 'a-note', :contents => "My thoughts on life.")
|
44
|
+
@link = stub_asset(:drop => @mydrop, :name => 'a-link', :url => "http://google.com/")
|
45
|
+
@file_asset = stub_asset(:drop => @mydrop, :name => 'some-video')
|
46
|
+
@comment = stub(Comment, :asset => @file_asset, :id => 1, :contents => "I remember that day.")
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should create drops" do
|
50
|
+
settings = {:name => "mynewdrop",
|
51
|
+
:admin_password => "niftieradminpassword",
|
52
|
+
:password => "niftyguestpassword",
|
53
|
+
:guests_can_comment => true,
|
54
|
+
:guests_can_add => true,
|
55
|
+
:guests_can_delete => false,
|
56
|
+
:expiration_length => "1_WEEK_FROM_NOW",
|
57
|
+
:premium_code => "yeswecan"}
|
58
|
+
|
59
|
+
mock_http(:post, "/drops/", @api_response, settings.merge(:api_key => "43myapikey13", :format => "json", :version => "1.0"))
|
60
|
+
Client::Mapper.stub!(:map_drops).with(@api_response_body).and_return(@mydrop)
|
61
|
+
Client.instance.create_drop(settings).should == @mydrop
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should create notes" do
|
65
|
+
mock_http(:post, "/drops/mydrop/assets/", @api_response, :title => "Just a Note",
|
66
|
+
:contents => "This is just to say",
|
67
|
+
:token => "93mydroptoken97",
|
68
|
+
:api_key => "43myapikey13",
|
69
|
+
:format => "json",
|
70
|
+
:version => "1.0")
|
71
|
+
Client::Mapper.stub!(:map_assets).with(@mydrop, @api_response_body).and_return(@note)
|
72
|
+
Client.instance.create_note(@mydrop, "Just a Note", "This is just to say").should == @note
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should create links" do
|
76
|
+
mock_http(:post, "/drops/mydrop/assets/", @api_response, :url => "http://drop.io/",
|
77
|
+
:title => "Drop.io",
|
78
|
+
:description => "An awesome sharing site.",
|
79
|
+
:token => "93mydroptoken97",
|
80
|
+
:api_key => "43myapikey13",
|
81
|
+
:format => "json",
|
82
|
+
:version => "1.0")
|
83
|
+
Client::Mapper.stub!(:map_assets).with(@mydrop, @api_response_body).and_return(@link)
|
84
|
+
Client.instance.create_link(@mydrop, "http://drop.io/", "Drop.io", "An awesome sharing site.").should == @link
|
85
|
+
end
|
86
|
+
|
87
|
+
it "should add files" do
|
88
|
+
file = stub(File)
|
89
|
+
File.stub!(:open).with("/path/to/video.avi", "r").and_yield(file)
|
90
|
+
|
91
|
+
path = "/upload"
|
92
|
+
form_data = {:drop_name => "mydrop",
|
93
|
+
:file => file,
|
94
|
+
:token => "93mydroptoken97",
|
95
|
+
:api_key => "43myapikey13",
|
96
|
+
:format => "json",
|
97
|
+
:version => "1.0"}
|
98
|
+
|
99
|
+
# We can't use mock_http here because the host is different and we're using multipart.
|
100
|
+
request = mock(Net::HTTP::Post)
|
101
|
+
request.should_receive(:multipart_params=).with(form_data) if form_data
|
102
|
+
Net::HTTP::Post.stub!(:new).with(path, Client::DEFAULT_HEADER).and_return(request)
|
103
|
+
|
104
|
+
http = mock(Net::HTTP)
|
105
|
+
Net::HTTP.stub!(:new).with("assets.drop.io").and_return(http)
|
106
|
+
http.stub!(:start).and_yield(http)
|
107
|
+
http.stub!(:request).with(request).and_return(@api_response)
|
108
|
+
|
109
|
+
Client::Mapper.stub!(:map_assets).with(@mydrop, @api_response_body).and_return(@file_asset)
|
110
|
+
Client.instance.add_file(@mydrop, "/path/to/video.avi").should == @file_asset
|
111
|
+
end
|
112
|
+
|
113
|
+
it "should create comments" do
|
114
|
+
comment = stub(Comment)
|
115
|
+
mock_http(:post, "/drops/mydrop/assets/some-video/comments/", @api_response,
|
116
|
+
:contents => "What a cool video!",
|
117
|
+
:token => "93mydroptoken97",
|
118
|
+
:api_key => "43myapikey13",
|
119
|
+
:format => "json",
|
120
|
+
:version => "1.0")
|
121
|
+
Client::Mapper.stub!(:map_comments).with(@file_asset, @api_response_body).and_return(comment)
|
122
|
+
Client.instance.create_comment(@file_asset, "What a cool video!").should == comment
|
123
|
+
end
|
124
|
+
|
125
|
+
it "should find drops" do
|
126
|
+
mock_http(:get, "/drops/mydrop?api_key=43myapikey13&token=93mydroptoken97&version=1.0&format=json", @api_response)
|
127
|
+
Client::Mapper.stub!(:map_drops).with(@api_response_body).and_return(@mydrop)
|
128
|
+
Client.instance.find_drop("mydrop", "93mydroptoken97").should == @mydrop
|
129
|
+
end
|
130
|
+
|
131
|
+
it "should find assets" do
|
132
|
+
mock_http(:get, %r|^/drops/mydrop/assets/\?api_key=43myapikey13&token=93mydroptoken97&version=1.0&format=json|, @api_response)
|
133
|
+
Client::Mapper.stub!(:map_assets).with(@mydrop, @api_response_body).and_return([@file_asset])
|
134
|
+
Client.instance.find_assets(@mydrop).should == [@file_asset]
|
135
|
+
end
|
136
|
+
|
137
|
+
it "should find comments" do
|
138
|
+
mock_http(:get, %r|^/drops/mydrop/assets/some-video/comments/\?api_key=43myapikey13&token=93mydroptoken97&version=1.0&format=json|, @api_response)
|
139
|
+
Client::Mapper.stub!(:map_comments).with(@file_asset, @api_response_body).and_return([@comment])
|
140
|
+
Client.instance.find_comments(@file_asset).should == [@comment]
|
141
|
+
end
|
142
|
+
|
143
|
+
it "should save drops" do
|
144
|
+
@mydrop.stub!(:guests_can_comment => true,
|
145
|
+
:guests_can_add => false,
|
146
|
+
:guests_can_delete => false,
|
147
|
+
:expiration_length => "1_WEEK_FROM_LAST_VIEW",
|
148
|
+
:password => "mazda",
|
149
|
+
:admin_password => "foo64bar",
|
150
|
+
:premium_code => "yeswecan")
|
151
|
+
|
152
|
+
mock_http(:put, "/drops/mydrop", @api_response,
|
153
|
+
:guests_can_comment => true,
|
154
|
+
:guests_can_add => false,
|
155
|
+
:guests_can_delete => false,
|
156
|
+
:expiration_length => "1_WEEK_FROM_LAST_VIEW",
|
157
|
+
:password => "mazda",
|
158
|
+
:admin_password => "foo64bar",
|
159
|
+
:premium_code => "yeswecan",
|
160
|
+
:token => "93mydroptoken97",
|
161
|
+
:api_key => "43myapikey13",
|
162
|
+
:format => "json",
|
163
|
+
:version => "1.0")
|
164
|
+
|
165
|
+
new_drop = stub(Drop)
|
166
|
+
Client::Mapper.stub!(:map_drops).with(@api_response_body).and_return(new_drop)
|
167
|
+
Client.instance.save_drop(@mydrop).should == new_drop
|
168
|
+
end
|
169
|
+
|
170
|
+
it "should save note assets" do
|
171
|
+
@note.stub!(:title => "Just a Note",
|
172
|
+
:contents => "This is just to say")
|
173
|
+
|
174
|
+
mock_http(:put, "/drops/mydrop/assets/a-note", @api_response,
|
175
|
+
:title => "Just a Note",
|
176
|
+
:description => nil,
|
177
|
+
:url => nil,
|
178
|
+
:contents => "This is just to say",
|
179
|
+
:token => "93mydroptoken97",
|
180
|
+
:api_key => "43myapikey13",
|
181
|
+
:format => "json",
|
182
|
+
:version => "1.0")
|
183
|
+
|
184
|
+
new_note = stub_asset
|
185
|
+
Client::Mapper.stub!(:map_assets).with(@mydrop, @api_response_body).and_return(new_note)
|
186
|
+
Client.instance.save_asset(@note).should == new_note
|
187
|
+
end
|
188
|
+
|
189
|
+
it "should save link assets" do
|
190
|
+
@link.stub!(:url => "http://drop.io/",
|
191
|
+
:title => "Drop.io",
|
192
|
+
:description => "An awesome sharing site.")
|
193
|
+
|
194
|
+
mock_http(:put, "/drops/mydrop/assets/a-link", @api_response,
|
195
|
+
:title => "Drop.io",
|
196
|
+
:description => "An awesome sharing site.",
|
197
|
+
:url => "http://drop.io/",
|
198
|
+
:contents => nil,
|
199
|
+
:token => "93mydroptoken97",
|
200
|
+
:api_key => "43myapikey13",
|
201
|
+
:format => "json",
|
202
|
+
:version => "1.0")
|
203
|
+
|
204
|
+
new_link = stub_asset
|
205
|
+
Client::Mapper.stub!(:map_assets).with(@mydrop, @api_response_body).and_return(new_link)
|
206
|
+
Client.instance.save_asset(@link).should == new_link
|
207
|
+
end
|
208
|
+
|
209
|
+
it "should save file assets" do
|
210
|
+
@file_asset.stub!(:title => "Snowboarding in March",
|
211
|
+
:description => "This was really fun.")
|
212
|
+
|
213
|
+
mock_http(:put, "/drops/mydrop/assets/some-video", @api_response,
|
214
|
+
:title => "Snowboarding in March",
|
215
|
+
:description => "This was really fun.",
|
216
|
+
:url => nil,
|
217
|
+
:contents => nil,
|
218
|
+
:token => "93mydroptoken97",
|
219
|
+
:api_key => "43myapikey13",
|
220
|
+
:format => "json",
|
221
|
+
:version => "1.0")
|
222
|
+
|
223
|
+
new_file_asset = stub_asset
|
224
|
+
Client::Mapper.stub!(:map_assets).with(@mydrop, @api_response_body).and_return(new_file_asset)
|
225
|
+
Client.instance.save_asset(@file_asset).should == new_file_asset
|
226
|
+
end
|
227
|
+
|
228
|
+
it "should save comments" do
|
229
|
+
@comment.stub!(:contents => "I remember that day.")
|
230
|
+
|
231
|
+
mock_http(:put, "/drops/mydrop/assets/some-video/comments/1", @api_response,
|
232
|
+
:contents => "I remember that day.",
|
233
|
+
:token => "93mydroptoken97",
|
234
|
+
:api_key => "43myapikey13",
|
235
|
+
:format => "json",
|
236
|
+
:version => "1.0")
|
237
|
+
|
238
|
+
new_comment = stub(Comment)
|
239
|
+
|
240
|
+
Client::Mapper.stub!(:map_comments).with(@file_asset, @api_response_body).and_return(new_comment)
|
241
|
+
Client.instance.save_comment(@comment).should == new_comment
|
242
|
+
end
|
243
|
+
|
244
|
+
it "should destroy drops" do
|
245
|
+
mock_http(:delete, "/drops/mydrop", @api_response, :token => "93mydroptoken97",
|
246
|
+
:api_key => "43myapikey13",
|
247
|
+
:format => "json",
|
248
|
+
:version => "1.0")
|
249
|
+
|
250
|
+
Client.instance.destroy_drop(@mydrop).should be_true
|
251
|
+
end
|
252
|
+
|
253
|
+
it "should destroy assets" do
|
254
|
+
mock_http(:delete, "/drops/mydrop/assets/some-video", @api_response,
|
255
|
+
:token => "93mydroptoken97",
|
256
|
+
:api_key => "43myapikey13",
|
257
|
+
:format => "json",
|
258
|
+
:version => "1.0")
|
259
|
+
|
260
|
+
Client.instance.destroy_asset(@file_asset).should be_true
|
261
|
+
end
|
262
|
+
|
263
|
+
it "should destroy comments" do
|
264
|
+
mock_http(:delete, "/drops/mydrop/assets/some-video/comments/1", @api_response,
|
265
|
+
:token => "93mydroptoken97",
|
266
|
+
:api_key => "43myapikey13",
|
267
|
+
:format => "json",
|
268
|
+
:version => "1.0")
|
269
|
+
|
270
|
+
Client.instance.destroy_comment(@comment).should be_true
|
271
|
+
end
|
272
|
+
|
273
|
+
it "should send assets by fax" do
|
274
|
+
mock_http(:post, "/drops/mydrop/assets/some-video/send_to",
|
275
|
+
@api_response,
|
276
|
+
:medium => "fax",
|
277
|
+
:fax_number => "12345678901",
|
278
|
+
:token => "93mydroptoken97",
|
279
|
+
:api_key => "43myapikey13",
|
280
|
+
:format => "json",
|
281
|
+
:version => "1.0")
|
282
|
+
|
283
|
+
Client.instance.send_to_fax(@file_asset, "12345678901").should be_true
|
284
|
+
end
|
285
|
+
|
286
|
+
it "should send assets by email" do
|
287
|
+
mock_http(:post, "/drops/mydrop/assets/some-video/send_to",
|
288
|
+
@api_response,
|
289
|
+
:medium => "email",
|
290
|
+
:emails => "joe@broomtown.com,bill@vaccsrus.com",
|
291
|
+
:message => "Check this out!",
|
292
|
+
:token => "93mydroptoken97",
|
293
|
+
:api_key => "43myapikey13",
|
294
|
+
:format => "json",
|
295
|
+
:version => "1.0")
|
296
|
+
|
297
|
+
Client.instance.send_to_emails(@file_asset,
|
298
|
+
["joe@broomtown.com", "bill@vaccsrus.com"],
|
299
|
+
"Check this out!").should be_true
|
300
|
+
end
|
301
|
+
|
302
|
+
it "should send assets to drops" do
|
303
|
+
mock_http(:post, "/drops/mydrop/assets/some-video/send_to",
|
304
|
+
@api_response,
|
305
|
+
:medium => "drop",
|
306
|
+
:drop_name => "myotherdrop",
|
307
|
+
:token => "93mydroptoken97",
|
308
|
+
:api_key => "43myapikey13",
|
309
|
+
:format => "json",
|
310
|
+
:version => "1.0")
|
311
|
+
|
312
|
+
Client.instance.send_to_drop(@file_asset, "myotherdrop").should be_true
|
313
|
+
end
|
314
|
+
|
315
|
+
it "should generate drop urls" do
|
316
|
+
Client.instance.generate_drop_url(@mydrop).should =~ %r|http://drop.io/mydrop/from_api\?expires=\d+&signature=[0-9a-f]+|
|
317
|
+
end
|
318
|
+
|
319
|
+
it "should generate asset urls" do
|
320
|
+
Client.instance.generate_asset_url(@file_asset).should =~ %r|http://drop.io/mydrop/asset/some-video/from_api\?expires=\d+&signature=[0-9a-f]+|
|
321
|
+
end
|
322
|
+
end
|