cloudapp_api 0.0.3 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +17 -0
- data/Gemfile.lock +53 -0
- data/README.md +79 -44
- data/Rakefile +36 -43
- data/VERSION +1 -1
- data/cloudapp_api.gemspec +79 -35
- data/lib/cloudapp/account.rb +132 -0
- data/lib/cloudapp/base.rb +13 -42
- data/lib/cloudapp/client.rb +88 -2
- data/lib/cloudapp/httparty.rb +14 -9
- data/lib/cloudapp/item.rb +147 -0
- data/lib/cloudapp/multipart.rb +8 -7
- data/lib/cloudapp_api.rb +10 -2
- data/spec/cloudapp_account_spec.rb +162 -0
- data/spec/cloudapp_api_spec.rb +20 -0
- data/spec/cloudapp_client_spec.rb +65 -0
- data/spec/cloudapp_item_spec.rb +195 -0
- data/spec/fakeweb_helper.rb +43 -0
- data/spec/spec_helper.rb +13 -0
- data/spec/stubs/account/create +16 -0
- data/spec/stubs/account/show +16 -0
- data/spec/stubs/account/update +16 -0
- data/spec/stubs/item/create +19 -0
- data/spec/stubs/item/delete +19 -0
- data/spec/stubs/item/index +47 -0
- data/spec/stubs/item/new +15 -0
- data/spec/stubs/item/show +19 -0
- data/spec/stubs/item/update +19 -0
- metadata +208 -29
- data/.gitignore +0 -23
- data/lib/cloudapp/monkey_patch/httparty.rb +0 -34
- data/lib/cloudapp/monkey_patch/net_digest_auth.rb +0 -35
- data/test/helper.rb +0 -24
- data/test/helper/faking_setup.rb +0 -15
- data/test/helper/methods.rb +0 -81
- data/test/test_base.rb +0 -19
- data/test/test_cloudapp_api.rb +0 -38
data/lib/cloudapp/multipart.rb
CHANGED
@@ -2,9 +2,10 @@ require "mime/types"
|
|
2
2
|
|
3
3
|
module CloudApp
|
4
4
|
|
5
|
-
|
5
|
+
# TODO - Document the Multipart Class
|
6
|
+
class Multipart #:nodoc:
|
6
7
|
|
7
|
-
EOL = "\r\n"
|
8
|
+
EOL = "\r\n" #:nodoc:
|
8
9
|
|
9
10
|
def initialize(params)
|
10
11
|
@params = params
|
@@ -19,28 +20,28 @@ module CloudApp
|
|
19
20
|
@body += EOL + bound + "--#{EOL}"
|
20
21
|
end
|
21
22
|
|
22
|
-
def payload
|
23
|
+
def payload #:nodoc:
|
23
24
|
{
|
24
25
|
:headers => {"Content-Type" => "multipart/form-data; boundary=#{boundary}"},
|
25
26
|
:body => @body
|
26
27
|
}
|
27
28
|
end
|
28
29
|
|
29
|
-
def boundary
|
30
|
+
def boundary #:nodoc:
|
30
31
|
@boundary ||= "#{HEADERS["User-Agent"]}.#{Array.new(16/2) { rand(256) }.pack("C*").unpack("H*").first}"
|
31
32
|
end
|
32
33
|
|
33
|
-
def create_regular_field(key, val)
|
34
|
+
def create_regular_field(key, val) #:nodoc:
|
34
35
|
%Q{Content-Disposition: form-data; name="#{key}"} + EOL + EOL + val
|
35
36
|
end
|
36
37
|
|
37
|
-
def create_file_field(file)
|
38
|
+
def create_file_field(file) #:nodoc:
|
38
39
|
%Q{Content-Disposition: form-data; name="file"; filename="#{File.basename(file.path)}"} + EOL +
|
39
40
|
"Content-Type: #{mime_for(file.path)}" + EOL + EOL +
|
40
41
|
file.read
|
41
42
|
end
|
42
43
|
|
43
|
-
def mime_for(path)
|
44
|
+
def mime_for(path) #:nodoc:
|
44
45
|
(MIME::Types.type_for(path)[0] || MIME::Types["application/octet-stream"][0]).simplified
|
45
46
|
end
|
46
47
|
|
data/lib/cloudapp_api.rb
CHANGED
@@ -1,13 +1,21 @@
|
|
1
1
|
require "httparty"
|
2
2
|
|
3
|
-
["base", "client", "multipart", "httparty"].each do |inc|
|
3
|
+
["base", "item", "account", "client", "multipart", "httparty"].each do |inc|
|
4
4
|
require File.join(File.dirname(__FILE__), "cloudapp", inc)
|
5
5
|
end
|
6
6
|
|
7
|
+
# A simple Ruby wrapper for the CloudApp API. Uses HTTParty and provides
|
8
|
+
# two alternative interfaces for interracting with the API.
|
9
|
+
# An ActiveResource-like interface is provided alongside a simple client interface.
|
7
10
|
module CloudApp
|
8
11
|
|
9
|
-
|
12
|
+
# Version number
|
13
|
+
VERSION = "0.1.0"
|
10
14
|
|
15
|
+
# Sets the authentication credentials in a class variable
|
16
|
+
# @param [String] cl.ly username
|
17
|
+
# @param [String] cl.ly password
|
18
|
+
# @return [Hash] authentication credentials
|
11
19
|
def CloudApp.authenticate(username, password)
|
12
20
|
Base.authenticate(username, password)
|
13
21
|
end
|
@@ -0,0 +1,162 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe CloudApp::Account do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
fake_it_all
|
7
|
+
CloudApp.authenticate "testuser@test.com", "password"
|
8
|
+
@account = CloudApp::Account.find
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should be a Account object" do
|
12
|
+
@account.should be_a_kind_of CloudApp::Account
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should return an id" do
|
16
|
+
@account.id.should == 1
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should return an email" do
|
20
|
+
@account.email.should == "arthur@dent.com"
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should return a blank domain" do
|
24
|
+
@account.domain.should == nil
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should return a blank domain home page" do
|
28
|
+
@account.domain_home_page.should == nil
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should return a private items booleans" do
|
32
|
+
@account.private_items.should == true
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should return a subscribed boolean" do
|
36
|
+
@account.subscribed.should == false
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should return a alpha boolean" do
|
40
|
+
@account.alpha.should == false
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should return timestamps" do
|
44
|
+
@account.created_at.should be_a_kind_of Time
|
45
|
+
@account.updated_at.should be_a_kind_of Time
|
46
|
+
@account.activated_at.should be_a_kind_of Time
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
describe "Change default security" do
|
53
|
+
|
54
|
+
before(:each) do
|
55
|
+
fake_it_all
|
56
|
+
CloudApp.authenticate "testuser@test.com", "password"
|
57
|
+
@account = CloudApp::Account.update :private_items => false
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should be a Account object" do
|
61
|
+
@account.should be_a_kind_of CloudApp::Account
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should have private items set to false" do
|
65
|
+
@account.private_items.should == false
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
|
71
|
+
describe "Change email" do
|
72
|
+
|
73
|
+
before(:each) do
|
74
|
+
fake_it_all
|
75
|
+
CloudApp.authenticate "testuser@test.com", "password"
|
76
|
+
@email = "ford@prefect.com"
|
77
|
+
@account = CloudApp::Account.update :email => @email, :current_password => "towel"
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should be a Account object" do
|
81
|
+
@account.should be_a_kind_of CloudApp::Account
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should have the new email address" do
|
85
|
+
@account.email.should == @email
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
89
|
+
|
90
|
+
|
91
|
+
describe "Change password" do
|
92
|
+
|
93
|
+
before(:each) do
|
94
|
+
fake_it_all
|
95
|
+
CloudApp.authenticate "testuser@test.com", "password"
|
96
|
+
@account = CloudApp::Account.update :password => "hoopy frood", :current_password => "towel"
|
97
|
+
end
|
98
|
+
|
99
|
+
it "should be a Account object" do
|
100
|
+
@account.should be_a_kind_of CloudApp::Account
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|
104
|
+
|
105
|
+
|
106
|
+
describe "Reset password" do
|
107
|
+
|
108
|
+
before(:each) do
|
109
|
+
fake_it_all
|
110
|
+
@response = CloudApp::Account.reset :email => "arthur@dent.com"
|
111
|
+
end
|
112
|
+
|
113
|
+
it "should return true" do
|
114
|
+
@response.should == true
|
115
|
+
end
|
116
|
+
|
117
|
+
end
|
118
|
+
|
119
|
+
|
120
|
+
describe "Register account" do
|
121
|
+
|
122
|
+
before(:each) do
|
123
|
+
fake_it_all
|
124
|
+
@email = "arthur@dent.com"
|
125
|
+
@account = CloudApp::Account.create :email => @email, :current_password => "towel"
|
126
|
+
end
|
127
|
+
|
128
|
+
it "should be a Account object" do
|
129
|
+
@account.should be_a_kind_of CloudApp::Account
|
130
|
+
end
|
131
|
+
|
132
|
+
it "should do something" do
|
133
|
+
@account.email.should == @email
|
134
|
+
end
|
135
|
+
|
136
|
+
end
|
137
|
+
|
138
|
+
|
139
|
+
describe "Set custom domain" do
|
140
|
+
|
141
|
+
before(:each) do
|
142
|
+
fake_it_all
|
143
|
+
CloudApp.authenticate "testuser@test.com", "password"
|
144
|
+
@domain = "dent.com"
|
145
|
+
@dhp = "http://hhgproject.org"
|
146
|
+
@account = CloudApp::Account.update :domain => @domain, :domain_home_page => @dhp
|
147
|
+
end
|
148
|
+
|
149
|
+
it "should be a Account object" do
|
150
|
+
@account.should be_a_kind_of CloudApp::Account
|
151
|
+
end
|
152
|
+
|
153
|
+
it "should have the same domain" do
|
154
|
+
@account.domain.should == @domain
|
155
|
+
end
|
156
|
+
|
157
|
+
it "should have the same domain home page" do
|
158
|
+
@account.domain_home_page.should == @dhp
|
159
|
+
end
|
160
|
+
|
161
|
+
end
|
162
|
+
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe CloudApp do
|
4
|
+
|
5
|
+
it "should set correct headers" do
|
6
|
+
CloudApp::HEADERS['User-Agent'].should == "Ruby.CloudApp.API"
|
7
|
+
CloudApp::HEADERS['Accept'].should == "application/json"
|
8
|
+
CloudApp::HEADERS['Content-Type'].should == "application/json"
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should be authenticatable" do
|
12
|
+
auth = {
|
13
|
+
:username => "testuser@test.com",
|
14
|
+
:password => "password"
|
15
|
+
}
|
16
|
+
CloudApp.authenticate(auth[:username], auth[:password]).should == auth
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe CloudApp::Client do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
fake_it_all
|
7
|
+
CloudApp.authenticate "testuser@test.com", "password"
|
8
|
+
@client = CloudApp::Client.new
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should be reautheticatable" do
|
12
|
+
username = "joe.bloggs@testing.com"
|
13
|
+
password = "password"
|
14
|
+
auth = @client.authenticate username, password
|
15
|
+
auth[:username].should == username
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should find an item" do
|
19
|
+
item = @client.item "2wr4"
|
20
|
+
item.should be_a_kind_of CloudApp::Item
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should list all items" do
|
24
|
+
items = @client.items
|
25
|
+
items.should be_a_kind_of Array
|
26
|
+
items.each do |item|
|
27
|
+
item.should be_a_kind_of CloudApp::Item
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should bookmark an item" do
|
32
|
+
name = "CloudApp"
|
33
|
+
item = @client.bookmark "http://getcloudapp.com", name
|
34
|
+
item.should be_a_kind_of CloudApp::Item
|
35
|
+
item.name.should == name
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should upload a file" do
|
39
|
+
item = @client.upload "README.md"
|
40
|
+
item.should be_a_kind_of CloudApp::Item
|
41
|
+
item.item_type.should == "image"
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should rename an item" do
|
45
|
+
name = "CloudApp"
|
46
|
+
item = @client.rename "2wr4", name
|
47
|
+
item.should be_a_kind_of CloudApp::Item
|
48
|
+
item.name.should == name
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should set an items privacy" do
|
52
|
+
item = @client.privacy "2wr4", false
|
53
|
+
item.should be_a_kind_of CloudApp::Item
|
54
|
+
item.private.should == false
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should delete an item" do
|
58
|
+
item = @client.delete "2wr4"
|
59
|
+
item.should be_a_kind_of CloudApp::Item
|
60
|
+
item.deleted_at.should be_a_kind_of Time
|
61
|
+
end
|
62
|
+
|
63
|
+
|
64
|
+
end
|
65
|
+
|
@@ -0,0 +1,195 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe CloudApp::Item do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
fake_it_all
|
7
|
+
@item = CloudApp::Item.find "2wr4"
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should be a Item object" do
|
11
|
+
@item.should be_a_kind_of CloudApp::Item
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should return a name" do
|
15
|
+
@item.name.should == "CloudApp Logo.png"
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should return an href" do
|
19
|
+
@item.href.should == "http://my.cl.ly/items/1912559"
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should return a privacy boolean" do
|
23
|
+
@item.private.should == false
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should return a url" do
|
27
|
+
@item.url.should == "http://cl.ly/2wr4"
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should return a content url" do
|
31
|
+
@item.content_url.should == "http://cl.ly/2wr4/CloudApp_Logo.png"
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should return a item type" do
|
35
|
+
@item.item_type.should == "image"
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should return a view counter" do
|
39
|
+
@item.view_counter.should == 42
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should return an icon url" do
|
43
|
+
@item.icon.should == "http://my.cl.ly/images/item_types/image.png"
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should return a remote url" do
|
47
|
+
@item.remote_url == "http://f.cl.ly/items/7c7aea1395c3db0aee18/CloudApp%20Logo.png"
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should not return a redirect url" do
|
51
|
+
@item.redirect_url == nil
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should return timestamps" do
|
55
|
+
@item.created_at.should be_a_kind_of Time
|
56
|
+
@item.updated_at.should be_a_kind_of Time
|
57
|
+
@item.deleted_at.should == nil
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
|
63
|
+
describe "Bookmark link" do
|
64
|
+
|
65
|
+
before(:each) do
|
66
|
+
fake_it_all
|
67
|
+
CloudApp.authenticate "testuser@test.com", "password"
|
68
|
+
@name = "CloudApp"
|
69
|
+
@redirect_url = "http://getcloudapp.com"
|
70
|
+
@item = CloudApp::Item.create :bookmark, {:name => @name, :redirect_url => @redirect_url}
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should be a Item object" do
|
74
|
+
@item.should be_a_kind_of CloudApp::Item
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should return the same name" do
|
78
|
+
@item.name.should == @name
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should return the same redirect_url" do
|
82
|
+
@item.redirect_url.should == @redirect_url
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
86
|
+
|
87
|
+
|
88
|
+
describe "Change security of an item" do
|
89
|
+
|
90
|
+
before(:each) do
|
91
|
+
fake_it_all
|
92
|
+
CloudApp.authenticate "testuser@test.com", "password"
|
93
|
+
@item = CloudApp::Item.update "http://my.cl.ly/items/1912565", {:private => false}
|
94
|
+
end
|
95
|
+
|
96
|
+
it "should be an Item object" do
|
97
|
+
@item.should be_a_kind_of CloudApp::Item
|
98
|
+
end
|
99
|
+
|
100
|
+
it "should not be private" do
|
101
|
+
@item.private.should == false
|
102
|
+
end
|
103
|
+
|
104
|
+
end
|
105
|
+
|
106
|
+
|
107
|
+
|
108
|
+
describe "Delete an item" do
|
109
|
+
|
110
|
+
before(:each) do
|
111
|
+
fake_it_all
|
112
|
+
CloudApp.authenticate "testuser@test.com", "password"
|
113
|
+
@item = CloudApp::Item.delete "http://my.cl.ly/items/1912565"
|
114
|
+
end
|
115
|
+
|
116
|
+
it "should be an Item object" do
|
117
|
+
@item.should be_a_kind_of CloudApp::Item
|
118
|
+
end
|
119
|
+
|
120
|
+
it "should have a deleted_at timestamp" do
|
121
|
+
@item.deleted_at.should be_a_kind_of Time
|
122
|
+
end
|
123
|
+
|
124
|
+
end
|
125
|
+
|
126
|
+
|
127
|
+
describe "Empty trash" do
|
128
|
+
end
|
129
|
+
|
130
|
+
|
131
|
+
describe "List items" do
|
132
|
+
|
133
|
+
before(:each) do
|
134
|
+
fake_it_all
|
135
|
+
CloudApp.authenticate "testuser@test.com", "password"
|
136
|
+
@items = CloudApp::Item.all
|
137
|
+
end
|
138
|
+
|
139
|
+
it "should be an Array" do
|
140
|
+
@items.should be_a_kind_of Array
|
141
|
+
end
|
142
|
+
|
143
|
+
it "should contain Item objects" do
|
144
|
+
@items.each do |item|
|
145
|
+
item.should be_a_kind_of CloudApp::Item
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
end
|
150
|
+
|
151
|
+
|
152
|
+
describe "Recover deleted item" do
|
153
|
+
end
|
154
|
+
|
155
|
+
|
156
|
+
describe "Rename item" do
|
157
|
+
|
158
|
+
before(:each) do
|
159
|
+
fake_it_all
|
160
|
+
CloudApp.authenticate "testuser@test.com", "password"
|
161
|
+
@name = "CloudApp"
|
162
|
+
@item = CloudApp::Item.update "http://my.cl.ly/items/1912565", {:name => @name}
|
163
|
+
end
|
164
|
+
|
165
|
+
it "should be an Item object" do
|
166
|
+
@item.should be_a_kind_of CloudApp::Item
|
167
|
+
end
|
168
|
+
|
169
|
+
it "should be have the same name" do
|
170
|
+
@item.name.should == @name
|
171
|
+
end
|
172
|
+
|
173
|
+
end
|
174
|
+
|
175
|
+
|
176
|
+
describe "Upload file" do
|
177
|
+
|
178
|
+
before(:each) do
|
179
|
+
fake_it_all
|
180
|
+
CloudApp.authenticate "testuser@test.com", "password"
|
181
|
+
@item = CloudApp::Item.create :upload, {:file => "README.md"}
|
182
|
+
end
|
183
|
+
|
184
|
+
it "should be an Item object" do
|
185
|
+
@item.should be_a_kind_of CloudApp::Item
|
186
|
+
end
|
187
|
+
|
188
|
+
it "should return a item type" do
|
189
|
+
@item.item_type.should == "image"
|
190
|
+
end
|
191
|
+
|
192
|
+
end
|
193
|
+
|
194
|
+
|
195
|
+
|