egnyte 0.0.5 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZmJiZmE1MmY3MDE0ZjY4NDE4NWQxNjY3OTZmYTYxZjk4NzViNDQzMQ==
4
+ YWNmYjdjYmYyZDU0MTJlMzAzYmY4NDE2OWFiMWQyYWZiMzg5MGRmNA==
5
5
  data.tar.gz: !binary |-
6
- M2M2OWZlNGFmZjMxMTRlMjdmZmNjZGFiODkyODEyODk0MWZkZmZhNA==
6
+ MTk1NTY5YmVlM2FhMDA0NDJhNTFhYzQ0YWU0ZWZjMTRkZjQ5NWMwMQ==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- ZDk0ZTk5MDA1ZjliYjQ5OGM4Mzc1YTE3ZjY1NzM0ZGI0OWI4ZDEwNDM4OTAw
10
- NmViNzI4ODY3M2NlZmY4OTA0OTFiMDQ5OTY0ZDdiYjJjZjdkMjg0YmZiZTc4
11
- NjE4ZTg0YjYzMGEzMWFkODkyMDcxMDEwNmZiOWY2YzdmMzA1ZTg=
9
+ YmNjYmQ1MTBlMTZiMmU0MzZlNDUxNjcyYTJiYmNkOGNkNWM1YjE0ZDZiZDgw
10
+ ZTE3MTQ5ODQ5YmNhYmVkY2NkODM4NDEwM2Q2MzZlMDhhODk2NWEyNTUwMzFm
11
+ OTgxMWMzMTBkNGM5Yzk4MzRjM2U4ZmZmZThiZDhlNzc2NDYzMDA=
12
12
  data.tar.gz: !binary |-
13
- ZDMyNmRmZmVmNDg0Y2ZmZmU1YmZjZTdjN2JlMWMyYzI2ODExOWU1MmQ2ODg2
14
- NDRmZTc4MTM0ZmUzZTViZGQ4MDFlNmQ3OWVhYTVjMzYxZTZlZDRmOTA0Mjhh
15
- M2I0OGU4Y2IzZDA4MTEzZGNiMzM0MmE1N2UyMDgxNWU0MjA3MDQ=
13
+ YjA0NDcyYWJjNjViYTU1NmFlMTQzN2NmMmRlMmEyMDAyOTgxMzdlNDJhMjMw
14
+ ZWNkNGFkOWY0NmVjZmI3NjY1NGQxMzFhNDYwMDIyZmRiZGRjMzU3MzQ3M2Q5
15
+ YjdjNGM0NDU5NGE4YWU4YmI1MWViMTEyNGQ1ZWZkNTM4NThhOTg=
@@ -4,13 +4,17 @@ module Egnyte
4
4
  path = Egnyte::Helper.normalize_path(path)
5
5
 
6
6
  new_folder_path = "#{self.path}/#{path}"
7
- new_folder_path = URI.escape(new_folder_path)
8
7
 
9
- @session.post("#{fs_path}#{new_folder_path}", JSON.dump({
8
+ @session.post("#{fs_path}#{URI.escape(new_folder_path)}", JSON.dump({
10
9
  action: 'add_folder'
11
10
  }))
12
11
 
13
- Folder::find(@session, new_folder_path)
12
+ Folder.new({
13
+ 'path' => new_folder_path,
14
+ 'folders' => [],
15
+ 'is_folder' => true,
16
+ 'name' => new_folder_path.split('/').pop
17
+ }, @session)
14
18
  end
15
19
 
16
20
  def delete
@@ -18,8 +22,18 @@ module Egnyte
18
22
  end
19
23
 
20
24
  def upload(filename, content)
21
- @session.multipart_post("#{fs_path('fs-content')}#{URI.escape(path)}/#{URI.escape(filename)}", filename, content)
22
- File::find(@session, "#{path}/#{filename}")
25
+ resp = @session.multipart_post("#{fs_path('fs-content')}#{URI.escape(path)}/#{URI.escape(filename)}", filename, content, false)
26
+
27
+ content.rewind # to calculate size, rewind content stream.
28
+
29
+ File.new({
30
+ 'is_folder' => false,
31
+ 'entry_id' => resp['ETag'],
32
+ 'checksum' => resp['X-Sha512-Checksum'],
33
+ 'last_modified' => resp['Last-Modified'],
34
+ 'name' => filename,
35
+ 'size' => content.size
36
+ }, @session)
23
37
  end
24
38
 
25
39
  def files
@@ -30,34 +30,34 @@ module Egnyte
30
30
  @access_token = OAuth2::AccessToken.new(@client, token) if @strategy == :implicit
31
31
  end
32
32
 
33
- def get(url)
33
+ def get(url, return_parsed_response=true)
34
34
  uri = URI.parse(url)
35
35
  request = Net::HTTP::Get.new( uri.request_uri )
36
- resp = request( uri, request )
36
+ resp = request( uri, request, return_parsed_response )
37
37
  end
38
38
 
39
- def delete(url)
39
+ def delete(url, return_parsed_response=true)
40
40
  uri = URI.parse(url)
41
41
  request = Net::HTTP::Delete.new( uri.request_uri )
42
- resp = request( uri, request )
42
+ resp = request( uri, request, return_parsed_response )
43
43
  end
44
44
 
45
- def post(url, body)
45
+ def post(url, body, return_parsed_response=true)
46
46
  uri = URI.parse(url)
47
47
  request = Net::HTTP::Post.new(uri.request_uri)
48
48
  request.body = body
49
49
  request.content_type = "application/json"
50
- resp = request(uri, request)
50
+ resp = request(uri, request, return_parsed_response)
51
51
  end
52
52
 
53
- def multipart_post(url, filename, data)
53
+ def multipart_post(url, filename, data, return_parsed_response=true)
54
54
  uri = URI.parse(url)
55
55
 
56
56
  request = Net::HTTP::Post.new(uri.request_uri)
57
57
  request.body = data.read
58
58
  request.content_type = 'application/binary'
59
59
 
60
- resp = request(uri, request)
60
+ resp = request(uri, request, return_parsed_response)
61
61
  end
62
62
 
63
63
  # perform a streaming download of a file
@@ -74,7 +74,7 @@ module Egnyte
74
74
 
75
75
  private
76
76
 
77
- def request(uri, request)
77
+ def request(uri, request, return_parsed_response=true)
78
78
  http = Net::HTTP.new(uri.host, uri.port)
79
79
  http.use_ssl = true
80
80
  http.ssl_version = :SSLv3
@@ -88,7 +88,8 @@ module Egnyte
88
88
  # two requests per second.
89
89
  sleep(@backoff)
90
90
 
91
- parse_response( response.code.to_i, response.body )
91
+ parsed_response = parse_response( response.code.to_i, response.body )
92
+ return_parsed_response ? parsed_response : response
92
93
  end
93
94
 
94
95
  def parse_response( status, body )
@@ -1,3 +1,3 @@
1
1
  module Egnyte
2
- VERSION = "0.0.5"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -4,12 +4,60 @@ require 'spec_helper'
4
4
 
5
5
  describe Egnyte::Folder do
6
6
  before(:each) do
7
- session = Egnyte::Session.new({
7
+ @session = Egnyte::Session.new({
8
8
  key: 'api_key',
9
9
  domain: 'test',
10
10
  access_token: 'access_token'
11
11
  }, :implicit, 0.0)
12
- @client = Egnyte::Client.new(session)
12
+ @client = Egnyte::Client.new(@session)
13
+ end
14
+
15
+ describe "#upload" do
16
+ it "upload file to appropriate endpoint, and return a file object" do
17
+ stub_request(:post, "https://test.egnyte.com/pubapi/v1/fs-content/apple/banana/LICENSE.txt")
18
+ .with(:headers => { 'Authorization' => 'Bearer access_token' }, :body => File.open('./LICENSE.txt').read)
19
+ .to_return(:body => '', :status => 200, :headers => {
20
+ 'ETag' => 'c0c6c151-104b-4ddd-a0c7-eea809fc8a6a',
21
+ 'X-Sha512-Checksum' => '434390eddf638ab28e0f4668dca32e4a2b05c96eb3c8c0ca889788e204158cb4f240f1055ebac35745ede0e2349c83b407b9e4e0109bdc0b5ccdfe332a60fcfc',
22
+ 'last_modified' => 'Mon, 05 Aug 2013 22:37:35 GMT'
23
+ })
24
+
25
+ folder = Egnyte::Folder.new({
26
+ 'path' => 'apple/banana',
27
+ 'name' => 'banana'
28
+ }, @session)
29
+
30
+ file = nil
31
+
32
+ File.open( './LICENSE.txt' ) do |data|
33
+ file = folder.upload('LICENSE.txt', data)
34
+ end
35
+
36
+ file.is_folder.should == false
37
+ file.name.should == 'LICENSE.txt'
38
+ file.entry_id.should == 'c0c6c151-104b-4ddd-a0c7-eea809fc8a6a'
39
+ file.checksum.should == '434390eddf638ab28e0f4668dca32e4a2b05c96eb3c8c0ca889788e204158cb4f240f1055ebac35745ede0e2349c83b407b9e4e0109bdc0b5ccdfe332a60fcfc'
40
+ file.last_modified.should == 'Mon, 05 Aug 2013 22:37:35 GMT'
41
+ file.size.should == 1071
42
+ end
43
+ end
44
+
45
+ describe "#create" do
46
+ it "should call post to fs/path with appropriate payload and return folder object" do
47
+ stub_request(:post, "https://test.egnyte.com/pubapi/v1/fs/apple/banana/New%20Folder")
48
+ .with(:headers => { 'Authorization' => 'Bearer access_token' }, :body => JSON.dump({"action" => "add_folder"}))
49
+ .to_return(:body => '', :status => 200)
50
+
51
+ folder = Egnyte::Folder.new({
52
+ 'path' => 'apple/banana',
53
+ 'name' => 'banana'
54
+ }, @session)
55
+
56
+ new_folder = folder.create('New Folder')
57
+ new_folder.name.should == 'New Folder'
58
+ new_folder.path.should == 'apple/banana/New Folder'
59
+ new_folder.folders.should == []
60
+ end
13
61
  end
14
62
 
15
63
  describe "Folder::find" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: egnyte
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Benjamin Coe
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2013-07-31 00:00:00.000000000 Z
14
+ date: 2013-08-05 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: multipart-post