ruby-egnyte 0.1.6
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.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/Gemfile +5 -0
- data/LICENSE.txt +23 -0
- data/README.markdown +113 -0
- data/Rakefile +4 -0
- data/egnyte.gemspec +32 -0
- data/includes/cacert.pem +3849 -0
- data/lib/egnyte.rb +25 -0
- data/lib/egnyte/client.rb +11 -0
- data/lib/egnyte/errors.rb +28 -0
- data/lib/egnyte/file.rb +51 -0
- data/lib/egnyte/folder.rb +112 -0
- data/lib/egnyte/folder_structure.rb +13 -0
- data/lib/egnyte/group.rb +185 -0
- data/lib/egnyte/helper.rb +41 -0
- data/lib/egnyte/item.rb +43 -0
- data/lib/egnyte/link.rb +109 -0
- data/lib/egnyte/permission.rb +181 -0
- data/lib/egnyte/session.rb +197 -0
- data/lib/egnyte/user.rb +207 -0
- data/lib/egnyte/version.rb +3 -0
- data/spec/file_spec.rb +71 -0
- data/spec/fixtures/folder_listing_no_files.json +12 -0
- data/spec/fixtures/group/group_all.json +17 -0
- data/spec/fixtures/group/group_by_parameter.json +10 -0
- data/spec/fixtures/group/group_by_parameter_empty.json +7 -0
- data/spec/fixtures/group/group_create.json +1 -0
- data/spec/fixtures/link/link.json +1 -0
- data/spec/fixtures/link/link_create.json +1 -0
- data/spec/fixtures/link/link_list.json +1 -0
- data/spec/fixtures/link/link_list_empty.json +1 -0
- data/spec/fixtures/list_file.json +27 -0
- data/spec/fixtures/list_folder.json +23 -0
- data/spec/fixtures/permission/permission_list.json +1 -0
- data/spec/fixtures/user/user_all.json +1007 -0
- data/spec/fixtures/user/user_by_email.json +27 -0
- data/spec/fixtures/user/user_create.json +20 -0
- data/spec/fixtures/user/user_find.json +20 -0
- data/spec/fixtures/user/user_update.json +20 -0
- data/spec/folder_spec.rb +207 -0
- data/spec/group_spec.rb +166 -0
- data/spec/helper_spec.rb +30 -0
- data/spec/links_spec.rb +156 -0
- data/spec/permissions_spec.rb +98 -0
- data/spec/spec_helper.rb +17 -0
- data/spec/user_spec.rb +212 -0
- metadata +260 -0
data/spec/helper_spec.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
#encoding: UTF-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Egnyte::Helper do
|
6
|
+
describe "#normalize_path" do
|
7
|
+
it 'should remove leading and trailing slashes' do
|
8
|
+
expect(Egnyte::Helper.normalize_path('/banana')).to eq('banana')
|
9
|
+
expect(Egnyte::Helper.normalize_path('banana/')).to eq('banana')
|
10
|
+
expect(Egnyte::Helper.normalize_path('/banana/')).to eq('banana')
|
11
|
+
expect(Egnyte::Helper.normalize_path('banana')).to eq('banana')
|
12
|
+
expect(Egnyte::Helper.normalize_path('/ban/ana/')).to eq('ban/ana')
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "#params_to_s" do
|
17
|
+
it 'should convert a parameters hash to an properly formatted params query string' do
|
18
|
+
expect(Egnyte::Helper.params_to_s({email: 'test@egnyte.com'})).to eq "?email=test@egnyte.com"
|
19
|
+
# expect(Egnyte::Helper.params_to_filter_string({authType: 'ad', userType: 'power'})).to eq "?filter=authType%20eq%20%22ad%22&filter=userType%20eq%20%22power%22"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "#params_to_filter_string" do
|
24
|
+
it 'should convert a parameters hash to an Egnyte formatted filter string' do
|
25
|
+
expect(Egnyte::Helper.params_to_filter_string({email: 'test@egnyte.com'})).to eq "?filter=email eq \"test@egnyte.com\""
|
26
|
+
expect(Egnyte::Helper.params_to_filter_string({authType: 'ad', userType: 'power'})).to eq "?filter=authType eq \"ad\"&filter=userType eq \"power\""
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
data/spec/links_spec.rb
ADDED
@@ -0,0 +1,156 @@
|
|
1
|
+
#encoding: UTF-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Egnyte::Link do
|
6
|
+
before(:each) do
|
7
|
+
@invalid_link_params = {}
|
8
|
+
@valid_folder_link_params = {
|
9
|
+
path: '/Shared/Documents',
|
10
|
+
type: 'folder',
|
11
|
+
accessibility: 'Anyone'
|
12
|
+
}
|
13
|
+
@valid_file_link_params = {
|
14
|
+
path: '/Shared/Documents/test.txt',
|
15
|
+
type: 'file',
|
16
|
+
accessibility: 'Anyone'
|
17
|
+
}
|
18
|
+
stub_request(:get, "https://test.egnyte.com/pubapi/v1/userinfo").
|
19
|
+
with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization'=>'Bearer access_token', 'User-Agent'=>'Ruby'}).
|
20
|
+
to_return(:status => 200, :body => "", :headers => {})
|
21
|
+
@session = Egnyte::Session.new({
|
22
|
+
key: 'api_key',
|
23
|
+
domain: 'test',
|
24
|
+
access_token: 'access_token'
|
25
|
+
}, :implicit, 0.0)
|
26
|
+
@client = Egnyte::Client.new(@session)
|
27
|
+
@folder_link = Egnyte::Link.new(@session, @valid_folder_link_params)
|
28
|
+
@file_link = Egnyte::Link.new(@session, @valid_file_link_params)
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "#initialize" do
|
32
|
+
|
33
|
+
it 'instantiates a valid link if it has all required fields' do
|
34
|
+
expect(@folder_link).to be_valid
|
35
|
+
expect(@file_link).to be_valid
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
context "Posting to Egnyte" do
|
41
|
+
|
42
|
+
before(:each) do
|
43
|
+
stub_request(:post, "https://test.egnyte.com/pubapi/v1/links")
|
44
|
+
.with(:body => @folder_link.to_json,
|
45
|
+
:headers => {'Authorization'=>'Bearer access_token', 'Content-Type'=>'application/json'})
|
46
|
+
.to_return(:status => 201, :body => File.read('./spec/fixtures/link/link_create.json'), :headers => {})
|
47
|
+
stub_request(:get, "https://test.egnyte.com/pubapi/v1/links/jFmtRccgU0")
|
48
|
+
.with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization'=>'Bearer access_token', 'User-Agent'=>'Ruby'})
|
49
|
+
.to_return(:status => 200, :body => File.read('./spec/fixtures/link/link.json'), :headers => {})
|
50
|
+
end
|
51
|
+
|
52
|
+
describe "#create" do
|
53
|
+
|
54
|
+
it "should create a new link if valid" do
|
55
|
+
@link = Egnyte::Link.create(@session, @valid_folder_link_params)
|
56
|
+
expect(@link.id).to eq 'jFmtRccgU0'
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should raise an error if it tries to create an invaid link" do
|
60
|
+
expect{ Egnyte::Link.create(@session, @invalid_link_params) }.to raise_error(Egnyte::MissingAttribute)
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
describe "#save" do
|
66
|
+
|
67
|
+
it 'should raise an error if an attribute is missing' do
|
68
|
+
@folder_link.path = nil
|
69
|
+
expect{ @folder_link.save }.to raise_error(Egnyte::MissingAttribute)
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'should save a valid new link object by sending a POST to the Egnyte Link API' do
|
73
|
+
@folder_link = @folder_link.save
|
74
|
+
expect(@folder_link.id).to eq 'jFmtRccgU0'
|
75
|
+
expect(@folder_link.path).to eq '/Shared/Documents'
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
81
|
+
|
82
|
+
describe "#Link::find" do
|
83
|
+
|
84
|
+
it 'should return an Egnyte::Link object from a link id string' do
|
85
|
+
stub_request(:get, "https://test.egnyte.com/pubapi/v1/links/jFmtRccgU0")
|
86
|
+
.with(:headers => {'Authorization'=>'Bearer access_token'})
|
87
|
+
.to_return(:status => 200, :body => File.read('./spec/fixtures/link/link.json'), :headers => {})
|
88
|
+
link = @client.link('jFmtRccgU0')
|
89
|
+
expect(link).to be_an Egnyte::Link
|
90
|
+
expect(link.id).to eq 'jFmtRccgU0'
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
94
|
+
|
95
|
+
describe "#Link::all" do
|
96
|
+
|
97
|
+
it 'should list all links' do
|
98
|
+
stub_request(:get, "https://test.egnyte.com/pubapi/v1/links")
|
99
|
+
.with(:headers => { 'Authorization' => 'Bearer access_token' })
|
100
|
+
.to_return(:body => File.read('./spec/fixtures/link/link_list.json'), :status => 200)
|
101
|
+
list = Egnyte::Link.all(@session)
|
102
|
+
expect(list).to be_an Array
|
103
|
+
expect(list.first).to be_a String
|
104
|
+
expect(list.size).to eq 4
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
108
|
+
|
109
|
+
describe "#Link::where" do
|
110
|
+
|
111
|
+
it 'should find links that match the where filter' do
|
112
|
+
stub_request(:get, "https://test.egnyte.com/pubapi/v1/links?path=/Shared/Documents")
|
113
|
+
.with(:headers => {'Authorization'=>'Bearer access_token'})
|
114
|
+
.to_return(:status => 200, :body => File.read('./spec/fixtures/link/link_list.json'), :headers => {})
|
115
|
+
link_list = Egnyte::Link.where(@session, {path: '/Shared/Documents'})
|
116
|
+
expect(link_list).to be_an Array
|
117
|
+
expect(link_list.size).to eq 4
|
118
|
+
expect(link_list.first).to be_a String
|
119
|
+
end
|
120
|
+
|
121
|
+
it 'should return an empty array if no match is found' do
|
122
|
+
stub_request(:get, "https://test.egnyte.com/pubapi/v1/links?path=/YagniFubar")
|
123
|
+
.with(:headers => {'Authorization'=>'Bearer access_token'})
|
124
|
+
.to_return(:status => 200, :body => File.read('./spec/fixtures/link/link_list_empty.json'), :headers => {})
|
125
|
+
link_list = Egnyte::Link.where(@session, {path: '/YagniFubar'})
|
126
|
+
expect(link_list).to be_an Array
|
127
|
+
expect(link_list.size).to eq 0
|
128
|
+
end
|
129
|
+
|
130
|
+
end
|
131
|
+
|
132
|
+
describe "#User::delete" do
|
133
|
+
|
134
|
+
it 'should delete a link by id if the link exists' do
|
135
|
+
stub_request(:delete, "https://test.egnyte.com/pubapi/v1/links/jFmtRccgU0")
|
136
|
+
.with(:headers => {'Authorization'=>'Bearer access_token'})
|
137
|
+
.to_return(:status => 200, :body => "", :headers => {})
|
138
|
+
expect(Egnyte::User).to receive(:delete)
|
139
|
+
Egnyte::User.delete(@session, 'jFmtRccgU0')
|
140
|
+
end
|
141
|
+
|
142
|
+
end
|
143
|
+
|
144
|
+
describe "#to_json" do
|
145
|
+
|
146
|
+
it 'should render a valid json representation of a folder link' do
|
147
|
+
expect(@folder_link.to_json).to eq "{\"path\":\"/Shared/Documents\",\"type\":\"folder\",\"accessibility\":\"Anyone\"}"
|
148
|
+
end
|
149
|
+
|
150
|
+
it 'should render a valid json representation of a file link' do
|
151
|
+
expect(@file_link.to_json).to eq "{\"path\":\"/Shared/Documents/test.txt\",\"type\":\"file\",\"accessibility\":\"Anyone\"}"
|
152
|
+
end
|
153
|
+
|
154
|
+
end
|
155
|
+
|
156
|
+
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
#encoding: UTF-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Egnyte::Permission do
|
6
|
+
before(:each) do
|
7
|
+
@valid_permission_hash = {
|
8
|
+
"users" => {
|
9
|
+
"david" => "Owner",
|
10
|
+
"dpfeffer" => "Editor"
|
11
|
+
},
|
12
|
+
"groups" => { "Test Group" => "Editor" }
|
13
|
+
}
|
14
|
+
@invalid_permission_hash = {
|
15
|
+
"blah" => {
|
16
|
+
"david" => "Owner",
|
17
|
+
"dpfeffer" => "Editor"
|
18
|
+
}
|
19
|
+
}
|
20
|
+
@lowercase_permission_hash = {
|
21
|
+
"users" => {
|
22
|
+
"david" => "owner",
|
23
|
+
"dpfeffer" => "editor"
|
24
|
+
},
|
25
|
+
"groups" => { "Test Group" => "editor" }
|
26
|
+
}
|
27
|
+
@crazy_permission_hash = {
|
28
|
+
"users" => {
|
29
|
+
"david" => "crazy",
|
30
|
+
"dpfeffer" => "Viewer"
|
31
|
+
},
|
32
|
+
"groups" => { "Test Group" => "perms" }
|
33
|
+
}
|
34
|
+
@valid_permission_structure_from_api = JSON.parse(File.read('./spec/fixtures/permission/permission_list.json'))
|
35
|
+
stub_request(:get, "https://test.egnyte.com/pubapi/v1/userinfo").
|
36
|
+
with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization'=>'Bearer access_token', 'User-Agent'=>'Ruby'}).
|
37
|
+
to_return(:status => 200, :body => "", :headers => {})
|
38
|
+
@session = Egnyte::Session.new({
|
39
|
+
key: 'api_key',
|
40
|
+
domain: 'test',
|
41
|
+
access_token: 'access_token'
|
42
|
+
}, :implicit, 0.0)
|
43
|
+
@client = Egnyte::Client.new(@session)
|
44
|
+
@permission = Egnyte::Permission.new(@valid_permission_hash)
|
45
|
+
end
|
46
|
+
|
47
|
+
describe "#initialize" do
|
48
|
+
|
49
|
+
it 'instantiates a valid permission set if it has all required fields' do
|
50
|
+
expect(@permission.valid?).to be true
|
51
|
+
expect(@permission.has_data?).to be true
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'raises an error if it does not have valid fields' do
|
55
|
+
expect {Egnyte::Permission.new(@invalid_permission_hash)}.to raise_error( Egnyte::InvalidParameters )
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'drops invalid permission levels' do
|
59
|
+
@permission = Egnyte::Permission.new(@crazy_permission_hash)
|
60
|
+
expect(@permission.data["users"]["dpfeffer"]).to eq "Viewer"
|
61
|
+
expect(@permission.data["users"]["david"]).to be nil
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'capitalizes the first letter of permission levels' do
|
65
|
+
@permission = Egnyte::Permission.new(@lowercase_permission_hash)
|
66
|
+
expect(@permission.data["users"]["david"]).to eq "Owner"
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'can construct a valid permission listing response from the API' do
|
70
|
+
perm = Egnyte::Permission.build_from_api_listing(@valid_permission_structure_from_api)
|
71
|
+
expect(perm.valid?).to be true
|
72
|
+
expect(perm.has_data?).to be true
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
|
77
|
+
describe "#to_json" do
|
78
|
+
|
79
|
+
it 'should render a valid json representation of a permission object' do
|
80
|
+
expect(@permission.to_json).to eq "{\"users\":{\"david\":\"Owner\",\"dpfeffer\":\"Editor\"},\"groups\":{\"Test Group\":\"Editor\"}}"
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
describe "#merge" do
|
86
|
+
|
87
|
+
it 'should be able to merge two permission objects' do
|
88
|
+
@permission.merge!({
|
89
|
+
"users" => {
|
90
|
+
"jsmith" => "Owner" ,
|
91
|
+
"jdoe" => "Editor"
|
92
|
+
}
|
93
|
+
})
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
97
|
+
|
98
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'simplecov'
|
2
|
+
SimpleCov.start
|
3
|
+
|
4
|
+
require 'egnyte'
|
5
|
+
require 'webmock/rspec'
|
6
|
+
|
7
|
+
RSpec.configure do |c|
|
8
|
+
c.filter_run_excluding :skip => true
|
9
|
+
# Use color in STDOUT
|
10
|
+
c.color = true
|
11
|
+
|
12
|
+
# Use color not only in STDOUT but also in pagers and files
|
13
|
+
c.tty = true
|
14
|
+
|
15
|
+
# Use the specified formatter
|
16
|
+
#c.formatter = :progress # :documentation, :html, :textmate
|
17
|
+
end
|
data/spec/user_spec.rb
ADDED
@@ -0,0 +1,212 @@
|
|
1
|
+
#encoding: UTF-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Egnyte::User do
|
6
|
+
before(:each) do
|
7
|
+
@invalid_user_params = {}
|
8
|
+
@valid_user_params = {
|
9
|
+
:userName => "userA",
|
10
|
+
:email => "userA@example.com",
|
11
|
+
:name => {
|
12
|
+
:familyName => "A",
|
13
|
+
:givenName => "user"
|
14
|
+
},
|
15
|
+
:authType => "egnyte",
|
16
|
+
:userType => "power",
|
17
|
+
:active => true,
|
18
|
+
:sendInvite => true
|
19
|
+
}
|
20
|
+
stub_request(:get, "https://test.egnyte.com/pubapi/v1/userinfo").
|
21
|
+
with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization'=>'Bearer access_token', 'User-Agent'=>'Ruby'}).
|
22
|
+
to_return(:status => 200, :body => "", :headers => {})
|
23
|
+
@session = Egnyte::Session.new({
|
24
|
+
key: 'api_key',
|
25
|
+
domain: 'test',
|
26
|
+
access_token: 'access_token'
|
27
|
+
}, :implicit, 0.0)
|
28
|
+
@client = Egnyte::Client.new(@session)
|
29
|
+
@user = Egnyte::User.new(@session, @valid_user_params)
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "#initialize" do
|
33
|
+
|
34
|
+
it 'instantiates a valid user if it has all required fields' do
|
35
|
+
expect(@user).to be_valid
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "#create" do
|
41
|
+
|
42
|
+
it "should create a new user if valid" do
|
43
|
+
stub_request(:post, "https://test.egnyte.com/pubapi/v2/users")
|
44
|
+
.with(:body => @user.to_json,
|
45
|
+
:headers => {'Authorization'=>'Bearer access_token', 'Content-Type'=>'application/json'})
|
46
|
+
.to_return(:status => 201, :body => File.read('./spec/fixtures/user/user_create.json'), :headers => {})
|
47
|
+
@user = Egnyte::User.create(@session, @valid_user_params)
|
48
|
+
expect(@user.id).to eq 12163350648
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should raise an error if it tries to create an invaid user" do
|
52
|
+
expect{ Egnyte::User.create(@session, @invalid_user_params) }.to raise_error(Egnyte::MissingAttribute)
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
describe "#save" do
|
58
|
+
|
59
|
+
it 'should raise an error if an attribute is missing' do
|
60
|
+
@user.userName = nil
|
61
|
+
expect{ @user.save }.to raise_error(Egnyte::MissingAttribute)
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'should save a valid new user object by sending a POST to the Egnyte User API' do
|
65
|
+
stub_request(:post, "https://test.egnyte.com/pubapi/v2/users")
|
66
|
+
.with(:body => @user.to_json,
|
67
|
+
:headers => {'Authorization'=>'Bearer access_token', 'Content-Type'=>'application/json'})
|
68
|
+
.to_return(:status => 201, :body => File.read('./spec/fixtures/user/user_create.json'), :headers => {})
|
69
|
+
@user = @user.save
|
70
|
+
expect(@user.id).to eq 12163350648
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'should update an existing user object by sending a PATCH to the Egnyte User API' do
|
74
|
+
stub_request(:patch, "https://test.egnyte.com/pubapi/v2/users/12163350648")
|
75
|
+
.with(:body => @user.to_json_for_update,
|
76
|
+
:headers => {'Authorization'=>'Bearer access_token', 'Content-Type'=>'application/json'})
|
77
|
+
.to_return(:status => 200, :body => File.read('./spec/fixtures/user/user_update.json'), :headers => {})
|
78
|
+
@valid_user_params[:id] = 12163350648
|
79
|
+
@user = Egnyte::User.new(@session, @valid_user_params)
|
80
|
+
@user.save
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
describe "#User::find" do
|
86
|
+
|
87
|
+
it 'should find a user by id if the user exists' do
|
88
|
+
stub_request(:get, "https://test.egnyte.com/pubapi/v2/users/12408258604")
|
89
|
+
.with(:headers => {'Authorization'=>'Bearer access_token'})
|
90
|
+
.to_return(:status => 200, :body => File.read('./spec/fixtures/user/user_find.json'), :headers => {})
|
91
|
+
user = @client.user(12408258604)
|
92
|
+
expect(user).to be_an Egnyte::User
|
93
|
+
expect(user.id).to eq 12408258604
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
97
|
+
|
98
|
+
describe "#User::find_by_email" do
|
99
|
+
|
100
|
+
it 'should find a user by email if the user exists' do
|
101
|
+
stub_request(:get, "https://test.egnyte.com/pubapi/v2/users?count=100&filter=email%20eq%20%22afisher@example.com%22&startIndex=1")
|
102
|
+
.with(:headers => {'Authorization'=>'Bearer access_token'})
|
103
|
+
.to_return(:status => 200, :body => File.read('./spec/fixtures/user/user_by_email.json'), :headers => {})
|
104
|
+
user = @client.user_by_email('afisher@example.com')
|
105
|
+
expect(user).to be_an Egnyte::User
|
106
|
+
expect(user.id).to eq 12408258604
|
107
|
+
end
|
108
|
+
|
109
|
+
end
|
110
|
+
|
111
|
+
describe "#User::all" do
|
112
|
+
|
113
|
+
it 'should list all users' do
|
114
|
+
stub_request(:get, "https://test.egnyte.com/pubapi/v2/users?count=100&startIndex=1")
|
115
|
+
.with(:headers => { 'Authorization' => 'Bearer access_token' })
|
116
|
+
.to_return(:body => File.read('./spec/fixtures/user/user_all.json'), :status => 200)
|
117
|
+
list = Egnyte::User.all(@session)
|
118
|
+
expect(list).to be_an Array
|
119
|
+
expect(list.first).to be_an Egnyte::User
|
120
|
+
expect(list.size).to eq 50
|
121
|
+
end
|
122
|
+
|
123
|
+
end
|
124
|
+
|
125
|
+
describe "#User::where" do
|
126
|
+
|
127
|
+
it 'should find users that match the where filter' do
|
128
|
+
stub_request(:get, "https://test.egnyte.com/pubapi/v2/users?count=100&filter=email%20eq%20%22afisher@example.com%22&startIndex=1")
|
129
|
+
.with(:headers => {'Authorization'=>'Bearer access_token'})
|
130
|
+
.to_return(:status => 200, :body => File.read('./spec/fixtures/user/user_by_email.json'), :headers => {})
|
131
|
+
user_list = Egnyte::User.where(@session, {email: 'afisher@example.com'})
|
132
|
+
expect(user_list).to be_an Array
|
133
|
+
expect(user_list.first).to be_an Egnyte::User
|
134
|
+
expect(user_list.first.id).to eq 12408258604
|
135
|
+
expect(user_list.size).to eq 1
|
136
|
+
end
|
137
|
+
|
138
|
+
it 'should return an empty array if no match is found' do
|
139
|
+
stub_request(:get, "https://test.egnyte.com/pubapi/v2/users?filter=email%20eq%20%22FakeEmailThatDoesNotExist%22&startIndex=1&count=100")
|
140
|
+
.with(:headers => {'Authorization'=>'Bearer access_token'})
|
141
|
+
.to_return(:status => 200, :body => '{"startIndex":1,"totalResults":0,"itemsPerPage":100,"resources":[]}', :headers => {})
|
142
|
+
user_list = Egnyte::User.where(@session, {email: 'FakeEmailThatDoesNotExist'})
|
143
|
+
expect(user_list).to be_an Array
|
144
|
+
expect(user_list.size).to eq 0
|
145
|
+
end
|
146
|
+
|
147
|
+
end
|
148
|
+
|
149
|
+
describe "#User::search" do
|
150
|
+
|
151
|
+
before(:each) do
|
152
|
+
stub_request(:get, "https://test.egnyte.com/pubapi/v2/users?count=100&startIndex=1")
|
153
|
+
.with(:headers => { 'Authorization' => 'Bearer access_token' })
|
154
|
+
.to_return(:body => File.read('./spec/fixtures/user/user_all.json'), :status => 200)
|
155
|
+
end
|
156
|
+
|
157
|
+
it 'should find users that match the search criteria' do
|
158
|
+
user_list = Egnyte::User.search(@session, 'example.com')
|
159
|
+
expect(user_list).to be_an Array
|
160
|
+
expect(user_list.first).to be_an Egnyte::User
|
161
|
+
expect(user_list.size).to eq 50
|
162
|
+
end
|
163
|
+
|
164
|
+
it 'should return an empty array if no match is found' do
|
165
|
+
user_list = Egnyte::User.search(@session, 'NonexistantSearchCriteria')
|
166
|
+
expect(user_list).to be_an Array
|
167
|
+
expect(user_list.size).to eq 0
|
168
|
+
end
|
169
|
+
|
170
|
+
end
|
171
|
+
|
172
|
+
describe "#User::delete" do
|
173
|
+
|
174
|
+
it 'should delete a user by id if the user exists' do
|
175
|
+
stub_request(:delete, "https://test.egnyte.com/pubapi/v2/users/12408258604")
|
176
|
+
.with(:headers => {'Authorization'=>'Bearer access_token'})
|
177
|
+
.to_return(:status => 200, :body => "", :headers => {})
|
178
|
+
expect(Egnyte::User).to receive(:delete).and_return({})
|
179
|
+
Egnyte::User.delete(@session, 12408258604)
|
180
|
+
end
|
181
|
+
|
182
|
+
end
|
183
|
+
|
184
|
+
describe "#User::links" do
|
185
|
+
|
186
|
+
it 'should find link associated with this user' do
|
187
|
+
stub_request(:get, "https://test.egnyte.com/pubapi/v2/users/12408258604")
|
188
|
+
.with(:headers => {'Authorization'=>'Bearer access_token'})
|
189
|
+
.to_return(:status => 200, :body => File.read('./spec/fixtures/user/user_find.json'), :headers => {})
|
190
|
+
stub_request(:get, "https://test.egnyte.com/pubapi/v1/links?username=afisher")
|
191
|
+
.with(:headers => {'Authorization'=>'Bearer access_token'})
|
192
|
+
.to_return(:status => 200, :body => File.read('./spec/fixtures/link/link_list.json'), :headers => {})
|
193
|
+
Egnyte::User.links(@session, 12408258604)
|
194
|
+
end
|
195
|
+
|
196
|
+
end
|
197
|
+
|
198
|
+
describe "#User::permissions" do
|
199
|
+
|
200
|
+
it 'should find link associated with this user' do
|
201
|
+
stub_request(:get, "https://test.egnyte.com/pubapi/v2/users/12408258604")
|
202
|
+
.with(:headers => {'Authorization'=>'Bearer access_token'})
|
203
|
+
.to_return(:status => 200, :body => File.read('./spec/fixtures/user/user_find.json'), :headers => {})
|
204
|
+
stub_request(:get, "https://test.egnyte.com/pubapi/v1/links?username=afisher")
|
205
|
+
.with(:headers => {'Authorization'=>'Bearer access_token'})
|
206
|
+
.to_return(:status => 200, :body => File.read('./spec/fixtures/link/link_list.json'), :headers => {})
|
207
|
+
Egnyte::User.links(@session, 12408258604)
|
208
|
+
end
|
209
|
+
|
210
|
+
end
|
211
|
+
|
212
|
+
end
|