egnyte 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ MDFhNGJmODEwMWVhYzExZDM2YzI2YjYzZGQyMDM0ODQyNTc2ZTg4MA==
5
+ data.tar.gz: !binary |-
6
+ OTFlYjhhZjY4NzBiM2M3YzExM2M1YzEwNWU2N2M2NjBmM2QwZWQ1MA==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ YzViMDFmN2VjMjU2N2U1MGE5OGNlYTExMzUyZDFiNzBjODQ3NjI1YzVmYTIy
10
+ MWNjMzRlZDViZjI2ZmRlZmM1YWNiNGMzMWI4MTI3YjMwODI4NDBhMzUxNjJl
11
+ NDNhMmZlYWU2NTg1ZWE4NzI3NTBjYzg0MWFlZTE5MDdkMTcwODg=
12
+ data.tar.gz: !binary |-
13
+ ZDA0MjNlMmY0OWFmMTY5OGFlMDdmYmNiZGFjOTQwNGJiMzVmYTFjZDUyMGNl
14
+ ZTE4ZDA4ODMyMWU0YzExODA2MzBkNjhjYjFmMzhmNTU0YzllNDdhMzA5ZWRj
15
+ Nzk5ZDA4OWU3MDRkMmU1YTY2ZDI0NWY4OTc5ZGFjZjE5MGY3YzM=
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .DS_Store
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in egnyte.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Attachments.me
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,109 @@
1
+ Ruby Egnyte
2
+ ===========
3
+
4
+ Mainted by: [Attachments.me](https://attachments.me)
5
+
6
+ A feature-rich Ruby client for [Egnyte Version 1 API](https://developers.egnyte.com/docs).
7
+
8
+ Authentication
9
+ --------
10
+
11
+ * Create a session object with your [Egnyte API Key](https://developers.egnyte.com/)
12
+ * Create an authorize url and direct a user to it, to retrieve an access_token for their account.
13
+
14
+ ```ruby
15
+ require 'egnyte'
16
+
17
+ session = Egnyte::Session.new({
18
+ key: 'api_key',
19
+ domain: 'egnyte_domain'
20
+ })
21
+ session.authorize_url('https://127.0.0.1/oauth2callback')
22
+
23
+ # direct the user to the authorize URL generated,
24
+ # the callback provided will be executed with an access token.
25
+
26
+ session.create_access_token('the_access_token_returned')
27
+ ```
28
+ * Create a client, with the authenticated session.
29
+
30
+ ```ruby
31
+ @client = Egnyte::Client.new(session)
32
+ ```
33
+
34
+ The client initialized, we can start interacting with the Egnyte API.
35
+
36
+ Folders
37
+ ------
38
+
39
+ * Fetching a folder
40
+
41
+ ```ruby
42
+ folder = @client.folder('/Shared')
43
+ p folder.name # outputs 'Shared'.
44
+ ```
45
+
46
+ * Listing files in a folder.
47
+
48
+ ```ruby
49
+ @client.folder('/Shared/Documents/').files.each {|f| p f.name}
50
+ # outputs "IMG_0440.JPG", "IMG_0431.JPG"
51
+ ```
52
+
53
+ * Creating a folder.
54
+
55
+ ```ruby
56
+ new_folder = @client.folder('/Shared/Documents/').create('banana')
57
+ p new_folder.path # a new folder was created /Shared/Documents/banana
58
+ ```
59
+
60
+ * Deleting a folder.
61
+
62
+ ```ruby
63
+ folder = @client.folder('/Shared/Documents/banana')
64
+ folder.delete
65
+ ```
66
+
67
+ Files
68
+ -----
69
+
70
+ * Fetching a file
71
+
72
+ ```ruby
73
+ file = @client.file('/Shared/example.txt')
74
+ p file.name # example.txt.
75
+ ```
76
+
77
+ * Deleting a file.
78
+
79
+ ```ruby
80
+ @client.file('/Shared/example.txt').delete
81
+ ```
82
+
83
+ * Uploading a file.
84
+
85
+ ```ruby
86
+ local_path = "./LICENSE.txt"
87
+ filename = "LICENSE.txt"
88
+
89
+ folder = @client.folder('Shared/Documents/')
90
+ File.open( local_path ) do |data|
91
+ folder.upload(filename, data)
92
+ end
93
+ ```
94
+
95
+ * Downloading a file.
96
+
97
+ ```ruby
98
+ file = @client.file('/Shared/Documents/LICENSE.txt')
99
+ file.download
100
+ ```
101
+
102
+ Contributing
103
+ -----------
104
+
105
+ 1. Fork it
106
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
107
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
108
+ 4. Push to the branch (`git push origin my-new-feature`)
109
+ 5. Create new Pull Request
@@ -0,0 +1,4 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'egnyte/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "egnyte"
8
+ spec.version = Egnyte::VERSION
9
+ spec.authors = ["Benjamin Coe", "Dan Reed", "Larry Kang", "Jesse Miller"]
10
+ spec.email = ["ben@attachments.me"]
11
+ spec.description = %q{Ruby client for Egnyte version 1 API}
12
+ spec.summary = %q{Ruby client for Egnyte version 1 API. Built and maintained by Attachments.me.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "multipart-post"
22
+ spec.add_dependency "mime-types"
23
+ spec.add_dependency "oauth2"
24
+ spec.add_dependency "json"
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.3"
27
+ spec.add_development_dependency "rake"
28
+ spec.add_development_dependency "rspec"
29
+ spec.add_development_dependency "webmock"
30
+ end
@@ -0,0 +1,19 @@
1
+ require 'uri'
2
+ require 'json'
3
+ require 'oauth2'
4
+ require 'open-uri'
5
+ require 'net/https'
6
+ require 'mime/types'
7
+ require 'net/http/post/multipart'
8
+
9
+ require "egnyte/version"
10
+ require "egnyte/helper"
11
+ require "egnyte/errors"
12
+ require "egnyte/session"
13
+ require "egnyte/client"
14
+ require "egnyte/item"
15
+ require "egnyte/folder"
16
+ require "egnyte/file"
17
+
18
+ module Egnyte
19
+ end
@@ -0,0 +1,15 @@
1
+ module Egnyte
2
+ class Client
3
+ def initialize(session)
4
+ @session = session
5
+ end
6
+
7
+ def folder(path='Shared')
8
+ Folder::find(@session, path)
9
+ end
10
+
11
+ def file(path)
12
+ File::find(@session, path)
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,22 @@
1
+ module Egnyte
2
+ class EgnyteError < StandardError
3
+ def initialize(data)
4
+ @data = data
5
+ end
6
+
7
+ def [](key)
8
+ @data[key]
9
+ end
10
+ end
11
+
12
+ class UnsupportedAuthStrategy < StandardError; end
13
+ class FileExpected < StandardError; end
14
+ class FolderExpected < StandardError; end
15
+ class FileFolderNotFound < EgnyteError; end
16
+ class RequestError < EgnyteError; end
17
+ class BadRequest < EgnyteError; end
18
+ class NotAuthorized < EgnyteError; end
19
+ class InsufficientPermissions < EgnyteError; end
20
+ class FileFolderDuplicateExists < EgnyteError; end
21
+ class FileSizeExceedsLimit < EgnyteError; end
22
+ end
@@ -0,0 +1,35 @@
1
+ module Egnyte
2
+ class File < Item
3
+
4
+ def download
5
+ stream.read
6
+ end
7
+
8
+ # use opts to provide lambdas
9
+ # to track the streaming download:
10
+ #
11
+ # :content_length_proc
12
+ # :progress_proc
13
+ def stream( opts={} )
14
+ @session.streaming_download( "#{fs_path('fs-content')}/#{URI.escape(path)}", opts )
15
+ end
16
+
17
+ def delete
18
+ @session.delete("#{fs_path}/#{URI.escape(path)}")
19
+ end
20
+
21
+ def self.find(session, path)
22
+ path = Egnyte::Helper.normalize_path(path)
23
+
24
+ file = File.new({
25
+ 'path' => path
26
+ }, session)
27
+
28
+ parsed_body = session.get("#{file.fs_path}#{URI.escape(path)}")
29
+
30
+ raise FileExpected if parsed_body['is_folder']
31
+
32
+ file.update_data(parsed_body)
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,58 @@
1
+ module Egnyte
2
+ class Folder < Item
3
+ def create(path)
4
+ path = Egnyte::Helper.normalize_path(path)
5
+
6
+ new_folder_path = "#{self.path}/#{path}"
7
+ new_folder_path = URI.escape(new_folder_path)
8
+
9
+ @session.post("#{fs_path}#{new_folder_path}", JSON.dump({
10
+ action: 'add_folder'
11
+ }))
12
+
13
+ Folder::find(@session, new_folder_path)
14
+ end
15
+
16
+ def delete
17
+ @session.delete("#{fs_path}/#{URI.escape(path)}")
18
+ end
19
+
20
+ 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}")
23
+ end
24
+
25
+ def files
26
+ create_objects(File, 'files')
27
+ end
28
+
29
+ def folders
30
+ create_objects(Folder, 'folders')
31
+ end
32
+
33
+ def self.find(session, path)
34
+ path = Egnyte::Helper.normalize_path(path)
35
+
36
+ folder = Folder.new({
37
+ 'path' => path
38
+ }, session)
39
+
40
+ parsed_body = session.get("#{folder.fs_path}#{URI.escape(path)}")
41
+
42
+ raise FolderExpected unless parsed_body['is_folder']
43
+
44
+ folder.update_data(parsed_body)
45
+ end
46
+
47
+ private
48
+
49
+ def create_objects(klass, key)
50
+ @data[key].map do |data|
51
+ data = data.merge({
52
+ 'path' => "#{path}/#{data['name']}"
53
+ })
54
+ klass.new(data, @session)
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,9 @@
1
+ module Egnyte
2
+ class Helper
3
+ # removes leading and trailing '/'
4
+ # from folder and file names.
5
+ def self.normalize_path(path)
6
+ path.gsub(/(^\/)|(\/$)/, '')
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,22 @@
1
+ module Egnyte
2
+ class Item
3
+ def initialize(data, session)
4
+ @data = data
5
+ @session = session
6
+ end
7
+
8
+ def method_missing(method, *args, &block)
9
+ @data[method.to_s]
10
+ end
11
+
12
+ def update_data(data)
13
+ @data = @data.update(data)
14
+ self
15
+ end
16
+
17
+ # mode can be either fs, or fs-content.
18
+ def fs_path(mode='fs')
19
+ "https://#{@session.domain}.egnyte.com/#{@session.api}/v1/#{mode}/"
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,120 @@
1
+ module Egnyte
2
+ class Session
3
+
4
+ attr_accessor :domain, :api
5
+
6
+ def initialize(opts, strategy=:implicit)
7
+
8
+ @strategy = strategy # the authentication strategy to use.
9
+ raise Egnyte::UnsupportedAuthStrategy unless @strategy == :implicit
10
+
11
+ @api = 'pubapi' # currently we only support the public API.
12
+
13
+ # the domain of the egnyte account to interact with.
14
+ raise Egnyte::DomainRequired unless @domain = opts[:domain]
15
+
16
+ @client = OAuth2::Client.new(opts[:key], nil, {
17
+ :site => "https://#{@domain}.egnyte.com",
18
+ :authorize_url => "/puboauth/token"
19
+ })
20
+
21
+ @access_token = OAuth2::AccessToken.new(@client, opts[:access_token]) if opts[:access_token]
22
+ end
23
+
24
+ def authorize_url(redirect_uri)
25
+ @client.implicit.authorize_url(:redirect_uri => redirect_uri)
26
+ end
27
+
28
+ def create_access_token(token)
29
+ @access_token = OAuth2::AccessToken.new(@client, token) if @strategy == :implicit
30
+ end
31
+
32
+ def get(url)
33
+ uri = URI.parse(url)
34
+ request = Net::HTTP::Get.new( uri.request_uri )
35
+ resp = request( uri, request )
36
+ end
37
+
38
+ def delete(url)
39
+ uri = URI.parse(url)
40
+ request = Net::HTTP::Delete.new( uri.request_uri )
41
+ resp = request( uri, request )
42
+ end
43
+
44
+ def post(url, body)
45
+ uri = URI.parse(url)
46
+ request = Net::HTTP::Post.new(uri.request_uri)
47
+ request.body = body
48
+ request.content_type = "application/json"
49
+ resp = request(uri, request)
50
+ end
51
+
52
+ def multipart_post(url, filename, data)
53
+ uri = URI.parse(url)
54
+
55
+ request = Net::HTTP::Post::Multipart.new(uri.path, {
56
+ "filename" => UploadIO.new(data, MIME::Types.type_for(filename).first, filename)
57
+ })
58
+
59
+ resp = request(uri, request)
60
+ end
61
+
62
+ # perform a streaming download of a file
63
+ # rather than in-memory.
64
+ def streaming_download(url, opts)
65
+ params = {
66
+ :content_length_proc => opts[:content_length_proc],
67
+ :progress_proc => opts[:progress_proc],
68
+ 'Authorization' => "Bearer #{@access_token.token}"
69
+ }
70
+
71
+ open(url, params)
72
+ end
73
+
74
+ private
75
+
76
+ def request(uri, request)
77
+ http = Net::HTTP.new(uri.host, uri.port)
78
+ http.use_ssl = true
79
+ http.ssl_version = :SSLv3
80
+ #http.set_debug_output($stdout)
81
+
82
+ request.add_field('Authorization', "Bearer #{@access_token.token}")
83
+
84
+ response = http.request(request)
85
+
86
+ parse_response( response.code.to_i, response.body )
87
+ end
88
+
89
+ def parse_response( status, body )
90
+
91
+ begin
92
+ parsed_body = JSON.parse(body)
93
+ rescue
94
+ parsed_body = {}
95
+ end
96
+
97
+ # Handle known errors.
98
+ case status
99
+ when 400
100
+ raise BadRequest.new(parsed_body)
101
+ when 401
102
+ raise NotAuthorized.new(parsed_body)
103
+ when 403
104
+ raise InsufficientPermissions.new(parsed_body)
105
+ when 404
106
+ raise FileFolderNotFound.new(parsed_body)
107
+ when 405
108
+ raise FileFolderDuplicateExists.new(parsed_body)
109
+ when 413
110
+ raise FileSizeExceedsLimit.new(parsed_body)
111
+ end
112
+
113
+ # Handle all other request errors.
114
+ raise RequestError.new(parsed_body) if status >= 400
115
+
116
+ parsed_body
117
+ end
118
+
119
+ end
120
+ end
@@ -0,0 +1,3 @@
1
+ module Egnyte
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,41 @@
1
+ #encoding: UTF-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Egnyte::File do
6
+ before(:each) do
7
+ session = Egnyte::Session.new({
8
+ key: 'api_key',
9
+ domain: 'test',
10
+ access_token: 'access_token'
11
+ })
12
+ @client = Egnyte::Client.new(session)
13
+ end
14
+
15
+ describe "File::find" do
16
+ it "should return a file object if the file exists" do
17
+ stub_request(:get, "https://test.egnyte.com/pubapi/v1/fs/Shared/example.txt")
18
+ .with(:headers => { 'Authorization' => 'Bearer access_token' })
19
+ .to_return(:body => File.read('./spec/fixtures/list_file.json'), :status => 200)
20
+
21
+ @client.file('/Shared/example.txt').name.should == 'example.txt'
22
+ end
23
+
24
+ it "should raise FileOrFolderNotFound error for a non-existent file" do
25
+ stub_request(:get, "https://test.egnyte.com/pubapi/v1/fs/Shared/banana.txt")
26
+ .with(:headers => { 'Authorization' => 'Bearer access_token' })
27
+ .to_return(:status => 404)
28
+
29
+ lambda {@client.file('Shared/banana.txt')}.should raise_error( Egnyte::FileFolderNotFound )
30
+ end
31
+
32
+ it "should raise FileExpected if path to folder provided" do
33
+ stub_request(:get, "https://test.egnyte.com/pubapi/v1/fs/Shared")
34
+ .with(:headers => { 'Authorization' => 'Bearer access_token' })
35
+ .to_return(:body => File.read('./spec/fixtures/list_folder.json'), :status => 200)
36
+
37
+ lambda {@client.file('/Shared')}.should raise_error( Egnyte::FileExpected )
38
+ end
39
+ end
40
+
41
+ end
@@ -0,0 +1,27 @@
1
+ {
2
+ "is_folder":false,
3
+ "entry_id":"a4e2857e-9cf4-492f-9087-0a8cee324e4c",
4
+ "checksum":"32d919f9f96d6f8e92889e68eb2c9eb8079b2327d80a70e247a9c426f9fc5049a7a7978eb6f0ab6d129720b871637d8175e047199bcf77fe36d23d15e81886a8",
5
+ "last_modified":"Sun, 02 Sep 2012 08:03:12 GMT",
6
+ "uploaded_by":"jsmith",
7
+ "size":1023,
8
+ "name":"example.txt",
9
+ "versions":[
10
+ {
11
+ "is_folder":false,
12
+ "entry_id":"0ee550e4-854a-4ebc-a2d1-0de17714957f",
13
+ "checksum":"2aca968ceb5452f797810a67ff283eb0b72dc334868c11f16e8cb9b8ab713e30f49a30245d16a9f187293b4971fd8a1d6c588d981799283ec1fbcc84c9fe44cb",
14
+ "last_modified":"Sun, 02 Sep 2012 07:37:34 GMT",
15
+ "uploaded_by":"mjohnson",
16
+ "size":1378
17
+ },
18
+ {
19
+ "is_folder":false,
20
+ "entry_id":"1eb75cc1-af4f-4331-8e56-b2f7d1ebebe5",
21
+ "checksum":"0a6a7ba5048971d4718da58ec0f9ba51a4bfc5691f11da4c0afa38244f474f7076bb6edf48d8bfb55bbbcf128c55918fbe96485ac1178e78ac2686a6fb4a0785",
22
+ "last_modified":"Sun, 02 Sep 2012 08:02:20 GMT",
23
+ "uploaded_by":"jsmith",
24
+ "size":1108
25
+ }
26
+ ]
27
+ }
@@ -0,0 +1,23 @@
1
+ {
2
+ "name":"docs",
3
+ "is_folder":true,
4
+ "folder_id":"d7d56ebc-ce31-4ba8-a6b3-292ffb43f215",
5
+ "folders":[
6
+ {
7
+ "name":"subfolder1",
8
+ "is_folder":true,
9
+ "folder_id":"5652844d-dd48-45a9-b8be-3d06c06c819a"
10
+ }
11
+ ],
12
+ "files":[
13
+ {
14
+ "is_folder":false,
15
+ "entry_id":"be7b01af-a5e2-42ef-a0e1-3a20c820d327",
16
+ "checksum":"c0bab8ffa555571b31338ed1b9249b72a139fc57055b21d91d0d4c02c7d50221e32aba3a1beb3a3c85a1e3368ac8b4893d7a41739a6fd24b25108398d76516e9",
17
+ "last_modified":"Sun, 02 Sep 2012 08:02:48GMT",
18
+ "uploaded_by":"jsmith",
19
+ "size":1024,
20
+ "name":"test.txt"
21
+ }
22
+ ]
23
+ }
@@ -0,0 +1,66 @@
1
+ #encoding: UTF-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Egnyte::Folder do
6
+ before(:each) do
7
+ session = Egnyte::Session.new({
8
+ key: 'api_key',
9
+ domain: 'test',
10
+ access_token: 'access_token'
11
+ })
12
+ @client = Egnyte::Client.new(session)
13
+ end
14
+
15
+ describe "Folder::find" do
16
+ it "should return a folder object if the folder exists" do
17
+ stub_request(:get, "https://test.egnyte.com/pubapi/v1/fs/Shared")
18
+ .with(:headers => { 'Authorization' => 'Bearer access_token' })
19
+ .to_return(:body => File.read('./spec/fixtures/list_folder.json'), :status => 200)
20
+
21
+ @client.folder.name.should == 'docs'
22
+ end
23
+
24
+ it "should raise FileOrFolderNotFound error for a non-existent folder" do
25
+ stub_request(:get, "https://test.egnyte.com/pubapi/v1/fs/banana")
26
+ .with(:headers => { 'Authorization' => 'Bearer access_token' })
27
+ .to_return(:status => 404)
28
+
29
+ lambda {@client.folder('banana')}.should raise_error( Egnyte::FileFolderNotFound )
30
+ end
31
+
32
+ it "should raise FolderExpected if path to file provided" do
33
+ stub_request(:get, "https://test.egnyte.com/pubapi/v1/fs/Shared")
34
+ .with(:headers => { 'Authorization' => 'Bearer access_token' })
35
+ .to_return(:body => File.read('./spec/fixtures/list_file.json'), :status => 200)
36
+
37
+ lambda {@client.folder}.should raise_error( Egnyte::FolderExpected )
38
+ end
39
+ end
40
+
41
+ describe "#files" do
42
+ it "should return an array of file objects" do
43
+ stub_request(:get, "https://test.egnyte.com/pubapi/v1/fs/Shared")
44
+ .with(:headers => { 'Authorization' => 'Bearer access_token' })
45
+ .to_return(:body => File.read('./spec/fixtures/list_folder.json'), :status => 200)
46
+
47
+ folder = @client.folder
48
+ file = folder.files.first
49
+ file.is_a?(Egnyte::File).should == true
50
+ file.path.should == 'Shared/test.txt'
51
+ end
52
+ end
53
+
54
+ describe "#folders" do
55
+ it "should return an array of file objects" do
56
+ stub_request(:get, "https://test.egnyte.com/pubapi/v1/fs/Shared")
57
+ .with(:headers => { 'Authorization' => 'Bearer access_token' })
58
+ .to_return(:body => File.read('./spec/fixtures/list_folder.json'), :status => 200)
59
+
60
+ folder = @client.folder
61
+ file = folder.folders.first
62
+ file.is_a?(Egnyte::Folder).should == true
63
+ file.path.should == 'Shared/subfolder1'
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,13 @@
1
+ #encoding: UTF-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Egnyte::Helper do
6
+ describe "#normalize_path" do
7
+ Egnyte::Helper.normalize_path('/banana').should == 'banana'
8
+ Egnyte::Helper.normalize_path('banana/').should == 'banana'
9
+ Egnyte::Helper.normalize_path('/banana/').should == 'banana'
10
+ Egnyte::Helper.normalize_path('banana').should == 'banana'
11
+ Egnyte::Helper.normalize_path('/ban/ana/').should == 'ban/ana'
12
+ end
13
+ end
@@ -0,0 +1,6 @@
1
+ require 'egnyte'
2
+ require 'webmock/rspec'
3
+
4
+ RSpec.configure do |c|
5
+ c.filter_run_excluding :skip => true
6
+ end
metadata ADDED
@@ -0,0 +1,187 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: egnyte
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Benjamin Coe
8
+ - Dan Reed
9
+ - Larry Kang
10
+ - Jesse Miller
11
+ autorequire:
12
+ bindir: bin
13
+ cert_chain: []
14
+ date: 2013-07-11 00:00:00.000000000 Z
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: multipart-post
18
+ requirement: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: mime-types
32
+ requirement: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - ! '>='
35
+ - !ruby/object:Gem::Version
36
+ version: '0'
37
+ type: :runtime
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ - !ruby/object:Gem::Dependency
45
+ name: oauth2
46
+ requirement: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ! '>='
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ type: :runtime
52
+ prerelease: false
53
+ version_requirements: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ! '>='
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ - !ruby/object:Gem::Dependency
59
+ name: json
60
+ requirement: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ! '>='
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ type: :runtime
66
+ prerelease: false
67
+ version_requirements: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ! '>='
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ - !ruby/object:Gem::Dependency
73
+ name: bundler
74
+ requirement: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ~>
77
+ - !ruby/object:Gem::Version
78
+ version: '1.3'
79
+ type: :development
80
+ prerelease: false
81
+ version_requirements: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ~>
84
+ - !ruby/object:Gem::Version
85
+ version: '1.3'
86
+ - !ruby/object:Gem::Dependency
87
+ name: rake
88
+ requirement: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ! '>='
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ type: :development
94
+ prerelease: false
95
+ version_requirements: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ! '>='
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ - !ruby/object:Gem::Dependency
101
+ name: rspec
102
+ requirement: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ! '>='
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ type: :development
108
+ prerelease: false
109
+ version_requirements: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ! '>='
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ - !ruby/object:Gem::Dependency
115
+ name: webmock
116
+ requirement: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ! '>='
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ type: :development
122
+ prerelease: false
123
+ version_requirements: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - ! '>='
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ description: Ruby client for Egnyte version 1 API
129
+ email:
130
+ - ben@attachments.me
131
+ executables: []
132
+ extensions: []
133
+ extra_rdoc_files: []
134
+ files:
135
+ - .gitignore
136
+ - Gemfile
137
+ - LICENSE.txt
138
+ - README.markdown
139
+ - Rakefile
140
+ - egnyte.gemspec
141
+ - lib/egnyte.rb
142
+ - lib/egnyte/client.rb
143
+ - lib/egnyte/errors.rb
144
+ - lib/egnyte/file.rb
145
+ - lib/egnyte/folder.rb
146
+ - lib/egnyte/helper.rb
147
+ - lib/egnyte/item.rb
148
+ - lib/egnyte/session.rb
149
+ - lib/egnyte/version.rb
150
+ - spec/file_spec.rb
151
+ - spec/fixtures/list_file.json
152
+ - spec/fixtures/list_folder.json
153
+ - spec/folder_spec.rb
154
+ - spec/helper_spec.rb
155
+ - spec/spec_helper.rb
156
+ homepage: ''
157
+ licenses:
158
+ - MIT
159
+ metadata: {}
160
+ post_install_message:
161
+ rdoc_options: []
162
+ require_paths:
163
+ - lib
164
+ required_ruby_version: !ruby/object:Gem::Requirement
165
+ requirements:
166
+ - - ! '>='
167
+ - !ruby/object:Gem::Version
168
+ version: '0'
169
+ required_rubygems_version: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ! '>='
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ requirements: []
175
+ rubyforge_project:
176
+ rubygems_version: 2.0.3
177
+ signing_key:
178
+ specification_version: 4
179
+ summary: Ruby client for Egnyte version 1 API. Built and maintained by Attachments.me.
180
+ test_files:
181
+ - spec/file_spec.rb
182
+ - spec/fixtures/list_file.json
183
+ - spec/fixtures/list_folder.json
184
+ - spec/folder_spec.rb
185
+ - spec/helper_spec.rb
186
+ - spec/spec_helper.rb
187
+ has_rdoc: