cloudpt-api 0.0.1 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +3 -1
- data/README.markdown +35 -48
- data/lib/cloudpt-api/client.rb +11 -2
- data/lib/cloudpt-api/client/files.rb +14 -6
- data/lib/cloudpt-api/client/raw.rb +18 -18
- data/lib/cloudpt-api/connection/requests.rb +11 -2
- data/lib/cloudpt-api/objects/file.rb +10 -0
- data/lib/cloudpt-api/objects/fileops.rb +4 -4
- data/lib/cloudpt-api/util/config.rb +3 -3
- data/lib/cloudpt-api/util/error.rb +1 -1
- data/lib/cloudpt-api/util/oauth.rb +3 -3
- data/lib/cloudpt-api/util/util.rb +4 -0
- data/lib/cloudpt-api/version.rb +1 -1
- data/spec/lib/cloudpt-api/client_spec.rb +42 -21
- data/spec/lib/cloudpt-api/connection_spec.rb +1 -1
- data/spec/lib/cloudpt-api/dir_spec.rb +11 -4
- data/spec/lib/cloudpt-api/file_spec.rb +15 -11
- data/spec/lib/cloudpt-api/thumbnail_spec.rb +4 -2
- metadata +2 -2
data/LICENSE
CHANGED
@@ -19,4 +19,6 @@ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
19
19
|
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
20
20
|
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
21
21
|
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
22
|
-
OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
23
|
+
|
24
|
+
Adapted to CloudPT service by Fábio Batista, Webreakstuff Lda. Copyright (c) 2013
|
data/README.markdown
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
Cloudpt::API - Cloudpt Ruby API client
|
2
|
-
|
2
|
+
======================================
|
3
3
|
|
4
4
|
A Ruby client for the Cloudpt REST API.
|
5
5
|
|
@@ -11,8 +11,8 @@ Current state:
|
|
11
11
|
|
12
12
|
First release, whole API covered.
|
13
13
|
|
14
|
-
Installation
|
15
|
-
|
14
|
+
Step 1: Installation
|
15
|
+
--------------------
|
16
16
|
|
17
17
|
Cloudpt::API is available on RubyGems, so:
|
18
18
|
|
@@ -26,8 +26,8 @@ Or in your Gemfile:
|
|
26
26
|
gem "cloudpt-api"
|
27
27
|
```
|
28
28
|
|
29
|
-
Configuration
|
30
|
-
|
29
|
+
Step 2: Configuration
|
30
|
+
---------------------
|
31
31
|
|
32
32
|
In order to use this client, you need to have an app created on https://www.Cloudpt.com/developers/apps.
|
33
33
|
|
@@ -39,8 +39,8 @@ Cloudpt::API::Config.app_secret = YOUR_APP_SECRET
|
|
39
39
|
Cloudpt::API::Config.mode = "sandbox" # if you have a single-directory app or "Cloudpt" if it has access to the whole Cloudpt
|
40
40
|
```
|
41
41
|
|
42
|
-
|
43
|
-
|
42
|
+
Step 3a: Authorization
|
43
|
+
----------------------
|
44
44
|
|
45
45
|
The client is the base for all communication with the API and wraps around almost all calls
|
46
46
|
available in the API.
|
@@ -52,20 +52,25 @@ on how to do this:
|
|
52
52
|
```ruby
|
53
53
|
consumer = Cloudpt::API::OAuth.consumer(:authorize)
|
54
54
|
request_token = consumer.get_request_token
|
55
|
-
|
56
|
-
|
57
|
-
#
|
58
|
-
request_token.
|
55
|
+
# if you have a callback url
|
56
|
+
authorize_url = request_token.authorize_url(:oauth_callback => 'http://yoursite.com/callback')
|
57
|
+
# if you're running an "out of band app"
|
58
|
+
authorize_url = request_token.authorize_url
|
59
|
+
# Here the user goes to Cloudpt (following the authorize_url), authorizes the app and is redirected to oauth_callback, or is shown a pin (oauth_verifier).
|
60
|
+
# on the redirect case, the oauth_token (to be used as oauth_verifier on the next line) will be available in the params.
|
61
|
+
access_token = request_token.get_access_token(:oauth_verifier => oauth_token)
|
59
62
|
```
|
60
63
|
|
61
|
-
Now that you have the oauth token and secret, you can create a new instance of the Cloudpt::API::Client, like this:
|
64
|
+
Now that you have the oauth token (access_token.token) and secret (access_token.secret), you can create a new instance of the Cloudpt::API::Client, like this:
|
62
65
|
|
63
66
|
```ruby
|
64
|
-
client = Cloudpt::API::Client.new :token => token, :secret => secret
|
67
|
+
client = Cloudpt::API::Client.new :token => access_token.token, :secret => access_token.secret
|
65
68
|
```
|
66
69
|
|
67
|
-
|
68
|
-
|
70
|
+
Note: this token and secret are the ones you'll want to use if you're trying to run the Rspec tests (step 4).
|
71
|
+
|
72
|
+
Step 3b: Rake-based authorization
|
73
|
+
---------------------------------
|
69
74
|
|
70
75
|
Cloudpt::API supplies you with a helper rake which will authorize a single client. This is useful for development and testing.
|
71
76
|
|
@@ -84,30 +89,26 @@ Simply go to that url, authorize the app, then press enter in the console.
|
|
84
89
|
|
85
90
|
The rake task will output valid ruby code which you can use to create a client.
|
86
91
|
|
87
|
-
|
88
|
-
|
92
|
+
Step 4 (optional): Testing
|
93
|
+
--------------------------
|
89
94
|
|
90
|
-
|
95
|
+
This assumes you've cloned cloudpt-api repository and you're trying to run the Rspec tests.
|
91
96
|
|
92
|
-
|
93
|
-
* It treats files and directories as Ruby objects with appropriate classes, on which you can perform operations
|
97
|
+
In order to run tests, you need to have an application created and authorized (check step 2 and 3). Put all tokens in spec/connection.yml and you're good to go.
|
94
98
|
|
95
|
-
|
99
|
+
Check out spec/connection.sample.yml for an example.
|
96
100
|
|
97
|
-
|
101
|
+
Just run rspec from the project root.
|
98
102
|
|
99
|
-
```ruby
|
100
|
-
# Because you need the session with the right access token, you need to create one instance per user
|
101
|
-
@session = CloudptSession.new(APP_TOKEN, APP_SECRET)
|
102
|
-
@session.set_access_token(ACCESS_TOKEN, ACCESS_SECRET)
|
103
|
-
@client = CloudptClient.new(@session, :app_folder)
|
104
|
-
# The result is a hash, so we need to call a method on the client, supplying the right key from the hash
|
105
|
-
@client.search('/', 'test.txt').each do |hash|
|
106
|
-
@client.file_copy(hash['path'], hash['path'] + ".old")
|
107
|
-
end
|
108
103
|
```
|
104
|
+
$ rspec
|
105
|
+
```
|
106
|
+
|
107
|
+
|
108
|
+
Step 5: Usage
|
109
|
+
-------------
|
109
110
|
|
110
|
-
|
111
|
+
First you put the app token and secret in a config or initializer file:
|
111
112
|
|
112
113
|
```ruby
|
113
114
|
Cloudpt::API::Config.app_key = APP_TOKEN
|
@@ -125,13 +126,6 @@ And when you want to use it, just create a new client object with a specific acc
|
|
125
126
|
end
|
126
127
|
```
|
127
128
|
|
128
|
-
What differs this from the Cloudpt gem?
|
129
|
-
--------------------------------------
|
130
|
-
|
131
|
-
Cloudpt::API does not extend the Ruby primitives, like the Cloudpt gem:
|
132
|
-
|
133
|
-
https://github.com/RISCfuture/Cloudpt/tree/master/lib/Cloudpt/extensions
|
134
|
-
|
135
129
|
Cloudpt::API::Client methods
|
136
130
|
----------------------------
|
137
131
|
|
@@ -143,7 +137,7 @@ Returns a simple object with information about the account:
|
|
143
137
|
client.account # => #<Cloudpt::API::Object>
|
144
138
|
```
|
145
139
|
|
146
|
-
For more info, see [https://
|
140
|
+
For more info, see [https://cloudpt.pt/documentation#accountinfo](https://cloudpt.pt/documentation#accountinfo)
|
147
141
|
|
148
142
|
### Cloudpt::API::Client#find
|
149
143
|
|
@@ -309,14 +303,7 @@ Returns a list of files or directorys within that directory
|
|
309
303
|
dir.ls # => [#<Cloudpt::API::File>, #<Cloudpt::API::Dir>]
|
310
304
|
```
|
311
305
|
|
312
|
-
Testing
|
313
|
-
---------
|
314
|
-
|
315
|
-
In order to run tests, you need to have an application created and authorized. Put all tokens in spec/connection.yml and you're good to go.
|
316
|
-
|
317
|
-
Check out spec/connection.sample.yml for an example.
|
318
|
-
|
319
306
|
Copyright
|
320
307
|
---------
|
321
|
-
|
322
308
|
Copyright (c) 2011 Marcin Bunsch, Future Simple Inc. See LICENSE for details.
|
309
|
+
Copyright (c) 2013 Fábio Batista, Webreakstuff.
|
data/lib/cloudpt-api/client.rb
CHANGED
@@ -25,6 +25,9 @@ module Cloudpt
|
|
25
25
|
|
26
26
|
def list(path = '')
|
27
27
|
response = raw.list :path => path
|
28
|
+
results = Cloudpt::API::Object.convert(response, self)
|
29
|
+
results['contents'] = Cloudpt::API::Object.convert(results.delete('contents') || [], self)
|
30
|
+
results
|
28
31
|
end
|
29
32
|
|
30
33
|
def ls(path = '')
|
@@ -37,14 +40,20 @@ module Cloudpt
|
|
37
40
|
|
38
41
|
def mkdir(path)
|
39
42
|
# Remove the characters not allowed by Cloudpt
|
40
|
-
path = path.gsub(/[\\\:\?\*\<\>\"\|]
|
41
|
-
response = raw.create_folder :path => path
|
43
|
+
path = path.gsub(/(^\/)|([\\\:\?\*\<\>\"\|]+)/, '')
|
44
|
+
response = raw.create_folder :path => "/#{path}"
|
42
45
|
Cloudpt::API::Dir.init(response, self)
|
43
46
|
end
|
44
47
|
|
45
48
|
def search(term, options = {})
|
46
49
|
options[:path] ||= ''
|
47
50
|
results = raw.search({ :query => term }.merge(options))
|
51
|
+
#search results have broken paths, fix them here for now
|
52
|
+
results.each do |result|
|
53
|
+
if Cloudpt::API::Config.mode == 'sandbox'
|
54
|
+
result['path'] = result['path'].sub(/^\/([^\/]+)?/, '')
|
55
|
+
end
|
56
|
+
end
|
48
57
|
Cloudpt::API::Object.convert(results, self)
|
49
58
|
end
|
50
59
|
|
@@ -8,19 +8,27 @@ module Cloudpt
|
|
8
8
|
def download(path, options = {})
|
9
9
|
root = options.delete(:root) || Cloudpt::API::Config.mode
|
10
10
|
path = Cloudpt::API::Util.escape(path)
|
11
|
-
url = ["
|
11
|
+
url = ["", "Files", root, path].compact.join('/')
|
12
12
|
connection.get_raw(:content, url)
|
13
13
|
end
|
14
14
|
|
15
15
|
def upload(path, data, options = {})
|
16
16
|
root = options.delete(:root) || Cloudpt::API::Config.mode
|
17
|
+
method = options.delete(:method)
|
17
18
|
query = Cloudpt::API::Util.query(options)
|
18
19
|
path = Cloudpt::API::Util.escape(path)
|
19
|
-
url = ["
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
20
|
+
url = ["", "Files", root, path].compact.join('/')
|
21
|
+
if method == :post
|
22
|
+
response = connection.post(:content, "#{url}?#{query}", data, {
|
23
|
+
'Content-Type' => "application/octet-stream",
|
24
|
+
"Content-Length" => data.length.to_s
|
25
|
+
})
|
26
|
+
else
|
27
|
+
response = connection.put(:content, "#{url}?#{query}", data, {
|
28
|
+
'Content-Type' => "application/octet-stream",
|
29
|
+
"Content-Length" => data.length.to_s
|
30
|
+
})
|
31
|
+
end
|
24
32
|
Cloudpt::API::File.init(response, self)
|
25
33
|
end
|
26
34
|
|
@@ -27,24 +27,24 @@ module Cloudpt
|
|
27
27
|
connection.send(method, endpoint, action, data)
|
28
28
|
end
|
29
29
|
|
30
|
-
add_method :get, "/
|
31
|
-
|
32
|
-
add_method :get, "/
|
33
|
-
add_method :post, "/
|
34
|
-
add_method :get, "/
|
35
|
-
add_method :post, "/
|
36
|
-
add_method :get, "/
|
37
|
-
add_method :post, "/
|
38
|
-
add_method :post, "/
|
39
|
-
|
40
|
-
add_method :get_raw, "/
|
41
|
-
|
42
|
-
add_method :post, "/
|
43
|
-
add_method :get, "/
|
44
|
-
add_method :post, "/
|
45
|
-
add_method :post, "/
|
46
|
-
add_method :post, "/
|
47
|
-
add_method :
|
30
|
+
add_method :get, "/Account/Info", :as => 'account', :root => false
|
31
|
+
|
32
|
+
add_method :get, "/Metadata/:root/:path", :as => 'metadata'
|
33
|
+
add_method :post, "/Delta", :as => 'delta', :root => false
|
34
|
+
add_method :get, "/Revisions/:root/:path", :as => 'revisions'
|
35
|
+
add_method :post, "/Restore/:root/:path", :as => 'restore'
|
36
|
+
add_method :get, "/Search/:root/:path", :as => 'search'
|
37
|
+
add_method :post, "/Shares/:root/:path", :as => 'shares'
|
38
|
+
add_method :post, "/Media/:root/:path", :as => 'media'
|
39
|
+
|
40
|
+
add_method :get_raw, "/Thumbnails/:root/:path", :as => 'thumbnails', :endpoint => :content
|
41
|
+
|
42
|
+
add_method :post, "/Fileops/Copy", :as => "copy"
|
43
|
+
add_method :get, "/CopyRef/:root/:path", :as => 'copy_ref'
|
44
|
+
add_method :post, "/Fileops/CreateFolder", :as => "create_folder"
|
45
|
+
add_method :post, "/Fileops/Delete", :as => "delete"
|
46
|
+
add_method :post, "/Fileops/Move", :as => "move"
|
47
|
+
add_method :get, "/List/:root/:path", :as => "list"
|
48
48
|
|
49
49
|
end
|
50
50
|
|
@@ -9,6 +9,8 @@ module Cloudpt
|
|
9
9
|
response = yield
|
10
10
|
raise Cloudpt::API::Error::ConnectionFailed if !response
|
11
11
|
status = response.code.to_i
|
12
|
+
#puts "STATUS:#{status}"
|
13
|
+
#puts "PAYLOAD:\n#{response.body}"
|
12
14
|
case status
|
13
15
|
when 401
|
14
16
|
raise Cloudpt::API::Error::Unauthorized
|
@@ -23,7 +25,7 @@ module Cloudpt
|
|
23
25
|
when 300..399
|
24
26
|
raise Cloudpt::API::Error::Redirect
|
25
27
|
when 500..599
|
26
|
-
raise Cloudpt::API::Error
|
28
|
+
raise Cloudpt::API::Error::ServerError
|
27
29
|
else
|
28
30
|
options[:raw] ? response.body : MultiJson.decode(response.body)
|
29
31
|
end
|
@@ -33,6 +35,7 @@ module Cloudpt
|
|
33
35
|
|
34
36
|
def get_raw(endpoint, path, data = {}, headers = {})
|
35
37
|
query = Cloudpt::API::Util.query(data)
|
38
|
+
#puts "GET #{Cloudpt::API::Config.prefix}#{path}?#{URI.parse(URI.encode(query))}"
|
36
39
|
request(:raw => true) do
|
37
40
|
token(endpoint).get "#{Cloudpt::API::Config.prefix}#{path}?#{URI.parse(URI.encode(query))}", headers
|
38
41
|
end
|
@@ -40,18 +43,24 @@ module Cloudpt
|
|
40
43
|
|
41
44
|
def get(endpoint, path, data = {}, headers = {})
|
42
45
|
query = Cloudpt::API::Util.query(data)
|
46
|
+
query = "?#{URI.parse(URI.encode(query))}" unless query.empty?
|
47
|
+
#puts "GET #{Cloudpt::API::Config.prefix}#{path}#{query}"
|
43
48
|
request do
|
44
|
-
token(endpoint).get "#{Cloudpt::API::Config.prefix}#{path}
|
49
|
+
token(endpoint).get "#{Cloudpt::API::Config.prefix}#{path}#{query}", headers
|
45
50
|
end
|
46
51
|
end
|
47
52
|
|
48
53
|
def post(endpoint, path, data = {}, headers = {})
|
54
|
+
#puts "POST #{Cloudpt::API::Config.prefix}#{path}"
|
55
|
+
#puts "BODY:\n#{data}"
|
49
56
|
request do
|
50
57
|
token(endpoint).post "#{Cloudpt::API::Config.prefix}#{path}", data, headers
|
51
58
|
end
|
52
59
|
end
|
53
60
|
|
54
61
|
def put(endpoint, path, data = {}, headers = {})
|
62
|
+
#puts "PUT #{Cloudpt::API::Config.prefix}#{path}"
|
63
|
+
#puts "BODY:\n#{data}"
|
55
64
|
request do
|
56
65
|
token(endpoint).put "#{Cloudpt::API::Config.prefix}#{path}", data, headers
|
57
66
|
end
|
@@ -33,6 +33,16 @@ module Cloudpt
|
|
33
33
|
response = client.raw.copy_ref({ :path => self.path }.merge(options))
|
34
34
|
Cloudpt::API::Object.init(response, client)
|
35
35
|
end
|
36
|
+
|
37
|
+
|
38
|
+
#alias_method :old_path, :path
|
39
|
+
#def path
|
40
|
+
# if Cloudpt::API::Config.mode == 'sandbox'
|
41
|
+
# Cloudpt::API::Util.strip_slash(self['path'].sub(/^\/([^\/]+)?/, ''))
|
42
|
+
# else
|
43
|
+
# old_path
|
44
|
+
# end
|
45
|
+
#end
|
36
46
|
|
37
47
|
def download
|
38
48
|
client.download(self.path)
|
@@ -4,22 +4,22 @@ module Cloudpt
|
|
4
4
|
module Fileops
|
5
5
|
|
6
6
|
def copy(to, options = {})
|
7
|
-
response = client.raw.copy({ :from_path => self.path, :to_path => to }.merge(options))
|
7
|
+
response = client.raw.copy({ :from_path => "/#{self.path}", :to_path => "/#{Cloudpt::API::Util.strip_slash(to)}" }.merge(options))
|
8
8
|
self.update response
|
9
9
|
end
|
10
10
|
|
11
11
|
def move(to, options = {})
|
12
|
-
response = client.raw.move({ :from_path => self.path, :to_path => to }.merge(options))
|
12
|
+
response = client.raw.move({ :from_path => "/#{self.path}", :to_path => "/#{Cloudpt::API::Util.strip_slash(to)}" }.merge(options))
|
13
13
|
self.update response
|
14
14
|
end
|
15
15
|
|
16
16
|
def destroy(options = {})
|
17
|
-
response = client.raw.delete({ :path => self.path }.merge(options))
|
17
|
+
response = client.raw.delete({ :path => "/#{self.path}" }.merge(options))
|
18
18
|
self.update response
|
19
19
|
end
|
20
20
|
|
21
21
|
def path
|
22
|
-
self['path']
|
22
|
+
Cloudpt::API::Util.strip_slash(self['path'])
|
23
23
|
end
|
24
24
|
|
25
25
|
end
|
@@ -12,14 +12,14 @@ module Cloudpt
|
|
12
12
|
end
|
13
13
|
|
14
14
|
self.endpoints = {
|
15
|
-
:main => "https://
|
15
|
+
:main => "https://publicapi.cloudpt.pt",
|
16
16
|
:content => "https://api-content.cloudpt.pt",
|
17
17
|
:authorize => "https://cloudpt.pt"
|
18
18
|
}
|
19
|
-
self.prefix = ""
|
19
|
+
self.prefix = "/1"
|
20
20
|
self.app_key = nil
|
21
21
|
self.app_secret = nil
|
22
|
-
self.mode =
|
22
|
+
self.mode = 'sandbox'
|
23
23
|
|
24
24
|
end
|
25
25
|
|
@@ -11,9 +11,9 @@ module Cloudpt
|
|
11
11
|
end
|
12
12
|
::OAuth::Consumer.new(Cloudpt::API::Config.app_key, Cloudpt::API::Config.app_secret,
|
13
13
|
:site => Cloudpt::API::Config.endpoints[endpoint],
|
14
|
-
:request_token_path =>
|
15
|
-
:authorize_path =>
|
16
|
-
:access_token_path =>
|
14
|
+
:request_token_path => "/oauth/request_token",
|
15
|
+
:authorize_path => "/oauth/authorize",
|
16
|
+
:access_token_path => "/oauth/access_token")
|
17
17
|
end
|
18
18
|
|
19
19
|
def access_token(consumer, options = {})
|
data/lib/cloudpt-api/version.rb
CHANGED
@@ -3,9 +3,15 @@ require "spec_helper"
|
|
3
3
|
|
4
4
|
describe Cloudpt::API::Client do
|
5
5
|
|
6
|
-
before do
|
6
|
+
before(:all) do
|
7
7
|
# pending
|
8
8
|
@client = Cloudpt::Spec.instance
|
9
|
+
@dirname = "#{Cloudpt::Spec.test_dir}"
|
10
|
+
@dir = @client.mkdir @dirname
|
11
|
+
end
|
12
|
+
|
13
|
+
after(:all) do
|
14
|
+
@dir.destroy
|
9
15
|
end
|
10
16
|
|
11
17
|
describe "#initialize" do
|
@@ -27,11 +33,11 @@ describe Cloudpt::API::Client do
|
|
27
33
|
|
28
34
|
describe "#find" do
|
29
35
|
|
30
|
-
before do
|
31
|
-
@filename = "#{Cloudpt::Spec.test_dir}/spec
|
36
|
+
before(:all) do
|
37
|
+
@filename = "#{Cloudpt::Spec.test_dir}/spec--find-file-test-#{Time.now.to_i}.txt"
|
32
38
|
@file = @client.upload @filename, "spec file"
|
33
39
|
|
34
|
-
@dirname = "#{Cloudpt::Spec.test_dir}/spec
|
40
|
+
@dirname = "#{Cloudpt::Spec.test_dir}/spec--find-dir-test-#{Time.now.to_i}"
|
35
41
|
@dir = @client.mkdir @dirname
|
36
42
|
end
|
37
43
|
|
@@ -50,9 +56,17 @@ describe Cloudpt::API::Client do
|
|
50
56
|
end
|
51
57
|
|
52
58
|
describe "#list" do
|
59
|
+
before do
|
60
|
+
@filename = "#{Cloudpt::Spec.test_dir}/spec-find-file-test-#{Time.now.to_i}.txt"
|
61
|
+
@file = @client.upload @filename, "spec file"
|
62
|
+
|
63
|
+
@dirname = "#{Cloudpt::Spec.test_dir}/spec-find-dir-test-#{Time.now.to_i}"
|
64
|
+
@dir = @client.mkdir @dirname
|
65
|
+
end
|
66
|
+
|
53
67
|
it "lists root" do
|
54
|
-
result = @client.list("")
|
55
|
-
result.should be_an_instance_of(Array)
|
68
|
+
result = @client.list("#{Cloudpt::Spec.test_dir}")
|
69
|
+
result['contents'].should be_an_instance_of(Array)
|
56
70
|
end
|
57
71
|
end
|
58
72
|
|
@@ -106,13 +120,15 @@ describe Cloudpt::API::Client do
|
|
106
120
|
response.bytes.should == 9
|
107
121
|
end
|
108
122
|
|
123
|
+
#FAIL ON SERVER |*<>?:
|
109
124
|
it "uploads the file with tricky characters" do
|
110
|
-
filename = "#{Cloudpt::Spec.test_dir}/test
|
125
|
+
filename = "#{Cloudpt::Spec.test_dir}/test ,!@\#$%^&{b}[].;'.,-#{Cloudpt::Spec.namespace}.txt"
|
111
126
|
response = @client.upload filename, "Some file"
|
112
127
|
response.path.should == filename
|
113
128
|
response.bytes.should == 9
|
114
129
|
end
|
115
130
|
|
131
|
+
#FAIL ON SERVER
|
116
132
|
it "uploads the file with utf8" do
|
117
133
|
filename = "#{Cloudpt::Spec.test_dir}/test łołąó-#{Cloudpt::Spec.namespace}.txt"
|
118
134
|
response = @client.upload filename, "Some file"
|
@@ -125,22 +141,22 @@ describe Cloudpt::API::Client do
|
|
125
141
|
|
126
142
|
let(:term) { "searchable-test-#{Cloudpt::Spec.namespace}" }
|
127
143
|
|
128
|
-
before do
|
144
|
+
before(:all) do
|
129
145
|
filename = "#{Cloudpt::Spec.test_dir}/searchable-test-#{Cloudpt::Spec.namespace}.txt"
|
130
146
|
@client.upload filename, "Some file"
|
131
|
-
|
132
|
-
|
133
|
-
after do
|
134
|
-
@response.size.should == 1
|
135
|
-
@response.first.class.should == Cloudpt::API::File
|
147
|
+
sleep(2)
|
136
148
|
end
|
137
149
|
|
138
150
|
it "finds a file" do
|
139
|
-
|
151
|
+
response = @client.search term, :path => "#{Cloudpt::Spec.test_dir}"
|
152
|
+
response.size.should_not == 0
|
153
|
+
response.first.class.should == Cloudpt::API::File
|
140
154
|
end
|
141
155
|
|
142
156
|
it "works if leading slash is present in path" do
|
143
|
-
|
157
|
+
response = @client.search term, :path => "/#{Cloudpt::Spec.test_dir}"
|
158
|
+
response.size.should_not == 0
|
159
|
+
response.first.class.should == Cloudpt::API::File
|
144
160
|
end
|
145
161
|
|
146
162
|
end
|
@@ -148,12 +164,17 @@ describe Cloudpt::API::Client do
|
|
148
164
|
describe "#copy_from_copy_ref" do
|
149
165
|
|
150
166
|
it "copies a file from a copy_ref" do
|
151
|
-
filename = "
|
167
|
+
filename = "#{Cloudpt::Spec.test_dir}/searchable-test-copy-#{Cloudpt::Spec.namespace}.txt"
|
152
168
|
@client.upload filename, "Some file"
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
169
|
+
sleep(2)
|
170
|
+
response = @client.search "searchable-test-copy-#{Cloudpt::Spec.namespace}", :path => "#{Cloudpt::Spec.test_dir}"
|
171
|
+
ref = response.first.copy_ref
|
172
|
+
ref.should_not == nil
|
173
|
+
the_copy_ref = ref['copy-ref']
|
174
|
+
the_copy_ref.should_not == nil
|
175
|
+
@client.copy_from_copy_ref the_copy_ref, "#{filename}.copied"
|
176
|
+
sleep(2)
|
177
|
+
response = @client.search "searchable-test-copy-#{Cloudpt::Spec.namespace}.txt.copied", :path => "#{Cloudpt::Spec.test_dir}"
|
157
178
|
response.size.should == 1
|
158
179
|
response.first.class.should == Cloudpt::API::File
|
159
180
|
end
|
@@ -188,7 +209,7 @@ describe Cloudpt::API::Client do
|
|
188
209
|
end
|
189
210
|
|
190
211
|
it "returns the files that have changed since the cursor was made" do
|
191
|
-
filename = "#{Cloudpt::Spec.test_dir}/delta-
|
212
|
+
filename = "#{Cloudpt::Spec.test_dir}/delta-test_add-#{Cloudpt::Spec.namespace}.txt"
|
192
213
|
delete_filename = "#{Cloudpt::Spec.test_dir}/delta-test-delete-#{Cloudpt::Spec.namespace}.txt"
|
193
214
|
@client.upload delete_filename, 'Some file'
|
194
215
|
response = @client.delta
|
@@ -47,7 +47,7 @@ describe Cloudpt::API::Connection do
|
|
47
47
|
response = mock :code => 500, :body => '{ "a":1}'
|
48
48
|
lambda do
|
49
49
|
@connection.request { response }
|
50
|
-
end.should raise_error(Cloudpt::API::Error)
|
50
|
+
end.should raise_error(Cloudpt::API::Error::ServerError)
|
51
51
|
end
|
52
52
|
|
53
53
|
it "raises a Cloudpt::API::Error when the response is a 400" do
|
@@ -4,14 +4,11 @@ describe Cloudpt::API::Dir do
|
|
4
4
|
|
5
5
|
before do
|
6
6
|
@client = Cloudpt::Spec.instance
|
7
|
+
@parent_dir = @client.mkdir "#{Cloudpt::Spec.test_dir}"
|
7
8
|
@dirname = "#{Cloudpt::Spec.test_dir}/spec-dir-test-#{Time.now.to_i}"
|
8
9
|
@dir = @client.mkdir @dirname
|
9
10
|
end
|
10
11
|
|
11
|
-
after do
|
12
|
-
# @dir.delete
|
13
|
-
end
|
14
|
-
|
15
12
|
describe "#copy" do
|
16
13
|
|
17
14
|
it "copies the dir properly" do
|
@@ -20,6 +17,11 @@ describe Cloudpt::API::Dir do
|
|
20
17
|
@dir.path.should == new_dirname
|
21
18
|
end
|
22
19
|
|
20
|
+
after do
|
21
|
+
@dir.destroy
|
22
|
+
@parent_dir.destroy
|
23
|
+
end
|
24
|
+
|
23
25
|
end
|
24
26
|
|
25
27
|
describe "#move" do
|
@@ -30,6 +32,11 @@ describe Cloudpt::API::Dir do
|
|
30
32
|
@dir.path.should == new_dirname
|
31
33
|
end
|
32
34
|
|
35
|
+
after do
|
36
|
+
@dir.destroy
|
37
|
+
@parent_dir.destroy
|
38
|
+
end
|
39
|
+
|
33
40
|
end
|
34
41
|
|
35
42
|
describe "#destroy" do
|
@@ -4,12 +4,14 @@ describe Cloudpt::API::File do
|
|
4
4
|
|
5
5
|
before do
|
6
6
|
@client = Cloudpt::Spec.instance
|
7
|
+
@dirname = "#{Cloudpt::Spec.test_dir}"
|
8
|
+
@dir = @client.mkdir @dirname
|
7
9
|
@filename = "#{Cloudpt::Spec.test_dir}/spec-test-#{Time.now.to_i}.txt"
|
8
10
|
@file = @client.upload @filename, "spec file"
|
9
11
|
end
|
10
12
|
|
11
13
|
after do
|
12
|
-
|
14
|
+
@dir.destroy
|
13
15
|
end
|
14
16
|
|
15
17
|
describe "#copy" do
|
@@ -44,8 +46,9 @@ describe Cloudpt::API::File do
|
|
44
46
|
describe "#revisions" do
|
45
47
|
|
46
48
|
it "retrieves all revisions as an Array of File objects" do
|
47
|
-
|
48
|
-
|
49
|
+
sleep(2)
|
50
|
+
@client.upload @file.path, "Updated content", {'overwrite' => true, :method => :post}
|
51
|
+
#FAIL AT SERVER ?
|
49
52
|
revisions = @file.revisions
|
50
53
|
revisions.size.should == 2
|
51
54
|
revisions.collect { |f| f.class }.should == [Cloudpt::API::File, Cloudpt::API::File]
|
@@ -85,8 +88,9 @@ describe Cloudpt::API::File do
|
|
85
88
|
|
86
89
|
result = @file.share_url
|
87
90
|
result.should be_an_instance_of(Cloudpt::API::Object)
|
88
|
-
result.
|
89
|
-
|
91
|
+
result.should have_key 'expires'
|
92
|
+
result.should have_key 'url'
|
93
|
+
result.should have_key 'link_shareid'
|
90
94
|
end
|
91
95
|
|
92
96
|
end
|
@@ -94,11 +98,11 @@ describe Cloudpt::API::File do
|
|
94
98
|
describe "#copy_ref" do
|
95
99
|
|
96
100
|
it "returns a copy_ref object" do
|
97
|
-
|
101
|
+
sleep(2)
|
98
102
|
result = @file.copy_ref
|
99
103
|
result.should be_an_instance_of(Cloudpt::API::Object)
|
100
|
-
result.
|
101
|
-
|
104
|
+
result.should have_key 'copy_ref'
|
105
|
+
result.should have_key 'expires'
|
102
106
|
end
|
103
107
|
|
104
108
|
end
|
@@ -106,11 +110,11 @@ describe Cloudpt::API::File do
|
|
106
110
|
describe "#direct_url" do
|
107
111
|
|
108
112
|
it "returns an Url object" do
|
109
|
-
|
113
|
+
sleep(2)
|
110
114
|
result = @file.direct_url
|
111
115
|
result.should be_an_instance_of(Cloudpt::API::Object)
|
112
|
-
result.
|
113
|
-
|
116
|
+
result.should have_key 'url'
|
117
|
+
result.should have_key 'expires'
|
114
118
|
end
|
115
119
|
|
116
120
|
end
|
@@ -6,6 +6,7 @@ describe Cloudpt::API::File do
|
|
6
6
|
before do
|
7
7
|
@io = StringIO.new
|
8
8
|
@client = Cloudpt::Spec.instance
|
9
|
+
@dir = @client.mkdir Cloudpt::Spec.test_dir
|
9
10
|
@filename = "#{Cloudpt::Spec.test_dir}/spec-test-#{Time.now.to_i}.jpg"
|
10
11
|
jpeg = File.read("spec/fixtures/cloudpt.jpg")
|
11
12
|
@file = @client.upload @filename, jpeg
|
@@ -14,14 +15,15 @@ describe Cloudpt::API::File do
|
|
14
15
|
describe "#thumbnail" do
|
15
16
|
|
16
17
|
it "downloads a thumbnail" do
|
18
|
+
sleep(2)
|
17
19
|
result = @file.thumbnail
|
18
20
|
|
19
21
|
@io << result
|
20
22
|
@io.rewind
|
21
23
|
|
22
24
|
jpeg = JPEG.new(@io)
|
23
|
-
jpeg.height.should ==
|
24
|
-
jpeg.width.should ==
|
25
|
+
jpeg.height.should == 32
|
26
|
+
jpeg.width.should == 32
|
25
27
|
end
|
26
28
|
|
27
29
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cloudpt-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-02-
|
12
|
+
date: 2013-02-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: multi_json
|