seafile-api 0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 25a300668ad3660778a9ec20e04f2f32dce08dad
4
+ data.tar.gz: eb9ee71f58ceb014ceb0af09e4a9a1716e056462
5
+ SHA512:
6
+ metadata.gz: 569007ea2f8b4f756c43ef29f3ac2e34a4a24bab2ebfbba1426c0f0a620fdca647c060302839716086afdda3a7e3c0438506dbd58b50c80f45aee42dc9cf902b
7
+ data.tar.gz: a9c79effaafddff0dee542fd8baf0f176ac1a9f7127a8cb7dc74d2975d2c2e5c7962752df1928cf702ee7ae2ecf20b116ec9154e444d03a774dadd0c21abed47
@@ -0,0 +1,44 @@
1
+ require 'json'
2
+ require 'curb'
3
+ require 'net/http'
4
+ include URI
5
+
6
+ module SeafileApi
7
+ class Connect
8
+
9
+ attr_accessor :user_name
10
+ attr_accessor :password
11
+ attr_accessor :host
12
+ attr_accessor :repo
13
+ def initialize(user_name ,password,host,repo)
14
+ self.user_name = user_name
15
+ self.password = password
16
+ self.host = host
17
+ self.repo = repo
18
+ end
19
+
20
+ end
21
+
22
+ end
23
+ require "seafile-api/file/post_operations"
24
+ require "seafile-api/message"
25
+ require "seafile-api/group"
26
+ require "seafile-api/directory"
27
+ require "seafile-api/group/group"
28
+ require "seafile-api/group/group_member"
29
+ require "seafile-api/group/group_message"
30
+ require "seafile-api/account"
31
+ require "seafile-api/starred"
32
+ require "seafile-api/share"
33
+ require "seafile-api/library"
34
+ require "seafile-api/library/del_library"
35
+ require "seafile-api/library/get_library"
36
+ require "seafile-api/library/post_library"
37
+ require "seafile-api/shared/share"
38
+ require "seafile-api/shared/shared_files"
39
+ require "seafile-api/shared/shared_libraries"
40
+ require "seafile-api/file/dry_methods"
41
+ require "seafile-api/file/file_operations"
42
+ require "seafile-api/file/get_operations"
43
+ require "seafile-api/config"
44
+ require "seafile-api/file"
@@ -0,0 +1,46 @@
1
+ module SeafileApi
2
+
3
+ class Connect
4
+ def list_accounts
5
+ get_list_acc
6
+ end
7
+ def create_accounts(email,pass)
8
+ put_create_acc(email,pass)
9
+ end
10
+ def update_account(email,pass)
11
+ put_update_acc(email,pass)
12
+ end
13
+ def account_info
14
+ get_acc_info
15
+ end
16
+ def del_account(email)
17
+ delete_acc(email)
18
+ end
19
+ private
20
+ #TODO: add result processing
21
+ #https://cloud.seafile.com/api2/accounts/{email}/
22
+ def delete_acc(email)
23
+ curl_delete("#{self.host}/api2/accounts/#{email}").body_str
24
+ end
25
+ #curl -H "Authorization: Token f2210dacd9c6ccb8133606d94ff8e61d99b477fd" -H 'Accept: application/json; indent=4' https://cloud.seafile.com/api2/accounts/
26
+ def get_list_acc
27
+ curl_get("accounts").body_str
28
+ end
29
+ #curl -v -X PUT -d "password=123456" -H "Authorization: Token f2210dacd9c6ccb8133606d94ff8e61d99b477fd" -H 'Accept: application/json; indent=4' https://cloud.seafile.com/api2/accounts/newaccount@gmail.com/
30
+ def put_create_acc(email,pass)
31
+ curl_put("#{self.host}/api2/accounts/#{email}/",{"password" => pass}).body_str
32
+ end
33
+ #curl -v -X PUT -d "password=654321&is_staff=true" -H "Authorization: Token f2210dacd9c6ccb8133606d94ff8e61d99b477fd" -H 'Accept: application/json; indent=4' https://cloud.seafile.com/api2/accounts/newaccount@gmail.com/
34
+ def put_update_acc(email,pass)
35
+ curl_put("#{self.host}/api2/accounts/#{email}/", {"password" => pass}).body_str
36
+ end
37
+
38
+ #curl -H "Authorization: Token f2210dacd9c6ccb8133606d94ff8e61d99b477fd" -H 'Accept: application/json; indent=4' https://cloud.seafile.com/api2/account/info/
39
+ def get_acc_info
40
+ curl_get("/account/info/").body_str
41
+ end
42
+
43
+
44
+ end
45
+
46
+ end
@@ -0,0 +1,7 @@
1
+ module SeafileApi
2
+
3
+ class Connect
4
+
5
+ end
6
+
7
+ end
@@ -0,0 +1,53 @@
1
+ module SeafileApi
2
+
3
+ class Connect
4
+ def list_dir_entry(path='/',repo=self.repo)
5
+ get_list_dir_entry(repo,path)
6
+ end
7
+ def create_dir(path,repo=self.repo)
8
+ post_create_dir(path,repo)
9
+ end
10
+
11
+ # You do not have permission to perform this action
12
+ def del_dir(path,repo=self.repo)
13
+ delete_directory(path,repo)
14
+ end
15
+ def download_dir(path,repo=self.repo)
16
+ get_download_dir(path,repo)
17
+ end
18
+ # You do not have permission to perform this action
19
+ def share_dir(email,path,perm="r",repo=self.repo,s_type="d")
20
+ post_share_dir(repo,{"email"=> email, "path"=> path,"s_type"=> s_type,"perm"=> perm})
21
+ end
22
+
23
+ private
24
+ #curl -H "Authorization: Token f2210dacd9c6ccb8133606d94ff8e6fd" -H 'Accept: application/json; indent=4' https://cloud.seafile.com/api2/repos/99b758e6-91ab-4265-b705-925367374cf0/dir/?p=/foo
25
+ def get_list_dir_entry(repo,path)
26
+ http = curl_get("repos/#{repo}/dir/?p=#{path}")
27
+ cl_body_str(http)
28
+ end
29
+
30
+ #curl -d "operation=mkdir" -v -H 'Authorization: Tokacd9c6ccb8133606d94ff8e61d99b477fd' -H 'Accept: application/json; charset=utf-8; indent=4' https://cloud.seafile.com/api2/repos/dae8cecc-2359-4d33-aa42-01b7846c4b32/dir/?p=/foo
31
+ def post_create_dir(path,repo)
32
+ curl_post("#{self.host}/api2/repos/#{repo}/dir/?p=#{path}",{"operation"=>"mkdir"}).body_str
33
+ end
34
+
35
+ #curl -X DELETE -v -H 'Authorization: Token f2210dacd3606d94ff8e61d99b477fd' -H 'Accept: application/json; charset=utf-8; indent=4' https://cloud.seafile.com/api2/repos/dae8cecc-2359-4d33-aa42-01b7846c4b32/dir/?p=/foo
36
+ def delete_directory(repo,path)
37
+ curl_delete("#{self.host}/api2/repos/#{repo}/dir/?p=#{path}").body_str
38
+ end
39
+
40
+ #curl -H 'Authorization: Token f2210dacd3606d94ff8e61d99b477fd' -H 'Accept: application/json; charset=utf-8; indent=4' https://cloud.seafile.com/api2/repos/dae8cecc-2359-4d33-aa42-01b7846c4b32/dir/download/?p=/foo
41
+ def get_download_dir(repo,path)
42
+ http = curl_get("repos/#{repo}/dir/download/?p=#{path}")
43
+ cl_body_str(http)
44
+ end
45
+
46
+ #curl -v -X POST -d "emails=user@example.com&s_type=d&path=/dir&perm=r" -H 'Authorization: Token f2210dacd3606d94ff8e61d99b477fd' -H 'Accept: application/json; charset=utf-8; indent=4' https://cloud.seafile.com/api2/repos/dae8cecc-2359-4d33-aa42-01b7846c4b32/dir/share/
47
+ def post_share_dir(repo,data)
48
+ curl_post("#{self.host}/api2/repos/#{repo}/dir/share/",data).body_str
49
+
50
+ end
51
+ end
52
+
53
+ end
@@ -0,0 +1,63 @@
1
+
2
+
3
+ module SeafileApi
4
+ class Connect
5
+ def file_link(filename,repo=self.repo)
6
+ get_file_link(filename,repo)
7
+ end
8
+ def token
9
+ get_sf_token
10
+ end
11
+ def file_detail(filename,repo=self.repo)
12
+ get_description(filename,repo)
13
+ end
14
+
15
+ def link_revision(filename,commit_id,repo=self.repo)
16
+ get_link_file_revision(filename,commit_id,repo)
17
+ end
18
+
19
+ def file_history(filename,repo=self.repo)
20
+ get_history(filename,repo)
21
+ end
22
+
23
+ def block_link(repo=self.repo)
24
+ get_block(repo)
25
+ end
26
+
27
+ def upload_file(file,repo=self.repo)
28
+ post_upload(repo,{"file"=> file,"filename"=> File.basename(file),"parent_dir"=> "/"})
29
+ end
30
+
31
+ def update_file(file,target_file=nil,repo=self.repo)
32
+ post_update(repo,{"file" => file, "filename" =>File.basename(file), "target_file"=> target_file ||File.basename(file)})
33
+ end
34
+
35
+ def create_file(filename,repo=self.repo)
36
+ post_file(filename,repo)
37
+ end
38
+
39
+ def rename_file(old_name,new_name,repo=self.repo)
40
+ post_rename(old_name,repo,{"operation"=>"rename", "newname" => new_name})
41
+ end
42
+
43
+ def copy_file(filename,dst_dir='/',dest_repo=self.repo,src_repo=self.repo)
44
+ post_copy(src_repo,{"file_names"=>filename, "dst_repo" => dest_repo, "dst_dir"=>dst_dir})
45
+ end
46
+
47
+ def move_file(filename,dst_dir='/',dest_repo=self.repo,src_repo=self.repo)
48
+ post_move(filename,src_repo,{"operation"=>"move", "dst_repo" => dest_repo, "dst_dir"=>dst_dir})
49
+ end
50
+
51
+ def del_file(filename,repo=self.repo)
52
+ delete_file(filename,repo)
53
+ end
54
+
55
+ #TODO: need test on new server version
56
+ #not working seafile server version 3.0.3 , curl to not working
57
+ def revert_file(filename,commit_id,repo=self.repo)
58
+ post_revert("#{filename}",commit_id,repo)
59
+ end
60
+
61
+ end
62
+ end
63
+
@@ -0,0 +1,70 @@
1
+
2
+ module SeafileApi
3
+ class Connect
4
+
5
+ private
6
+
7
+ def result(result)
8
+ if !result.scan('File not found').empty?
9
+ "File not found"
10
+ elsif !result.scan('Path is missing').empty?
11
+ "Path is missing"
12
+ elsif !result.scan('Operation failed').empty?
13
+ "Operation failed"
14
+ elsif !result.scan('http').empty?
15
+ "#{result}"
16
+ else
17
+ "#{result}"
18
+ end
19
+ end
20
+
21
+ def is_http?(http)
22
+ !http.body_str.gsub('"', '').scan('http').empty?
23
+ end
24
+
25
+ def cl_body_str(http)
26
+ http.body_str.gsub('"', '')
27
+ end
28
+
29
+ def curl_post(url,data={})
30
+ c = Curl::Easy.new(URI::encode(url))
31
+ c.multipart_form_post = true
32
+ c.headers['Authorization'] = "Token #{get_sf_token}"
33
+ data.delete_if { |key, value| value.nil? }
34
+ p_data = data.map do |key, value|
35
+ if key != 'file'
36
+ Curl::PostField.content(key, value)
37
+ else
38
+ Curl::PostField.file(key, value)
39
+ end
40
+ end
41
+ c.http_post(p_data)
42
+ c
43
+ end
44
+
45
+ def curl_get(url)
46
+ Curl.get(URI::encode("#{self.host}/api2/#{url}")) do|http|
47
+ http.headers['Authorization'] = "Token #{get_sf_token}"
48
+ end
49
+ end
50
+ def curl_put(url,data={})
51
+ c = Curl::Easy.new(URI::encode(url))
52
+ c.headers['Authorization'] = "Token #{get_sf_token}"
53
+ c.headers['Content-Type'] = 'application/json'
54
+ data.delete_if { |key, value| value.nil? }
55
+ c.put_data= data.to_json
56
+ c.post
57
+ c
58
+ end
59
+ def curl_delete(url,data={})
60
+ c = Curl::Easy.new(URI::encode(url))
61
+ c.headers['Authorization'] = "Token #{get_sf_token}"
62
+ c.headers['Content-Type'] = 'application/json'
63
+
64
+ c.put_data= data.to_json unless data ==''
65
+ c.http_delete()
66
+ c
67
+ end
68
+
69
+ end
70
+ end
@@ -0,0 +1,36 @@
1
+ module SeafileApi
2
+ class Connect
3
+ private
4
+ #!!!!!!!!!operation with file sections
5
+ #curl -X DELETE -v -H 'Authorization: Token f2210dacd3606d94ff8e61d99b477fd' -H 'Accept: application/json; charset=utf-8; indent=4' https://cloud.seafile.com/api2/repos/dae8cecc-2359-4d33-aa42-01b7846c4b32
6
+ def delete_file(filename,repo)
7
+ curl_delete("#{self.host}/api2/repos/#{repo}/file/?p=#{filename}").body_str
8
+ end
9
+
10
+ #curl -v -X PUT -d "commit_id=a1ec20709675f4dc8db825cdbca296be245d189b&p=/foo.c" -H "Authorization: Token f2210dacd9c6ccb8133606d94ff8e61d99b477fd" -H 'Accept: application/json; indent=4' https://cloud.seafile.com/api2/repos/8f5f2222-72a8-454f-ac40-8397c5a556a8/file/revert
11
+ def post_revert(filename,commit_id,repo)
12
+ curl_put("#{self.host}/api2/repos/#{repo}/file/revert",{"commit_id" => commit_id,"p" => filename }).body_str
13
+ end
14
+
15
+
16
+ #curl -v -d "operation=create" -H 'Authorization: Token f2210dacd9c6ccb8133606d94ff8e61d99b477fd' -H 'Accept: application/json; charset=utf-8; indent=4' https://cloud.seafile.com/api2/repos/dae8cecc-2359-4d33-aa42-01b7846c4b32/file/?p=/foo.c
17
+ def post_file(filename,repo)
18
+ curl_post("#{self.host}/api2/repos/#{repo}/file/?p=#{filename}",{"operation"=> "create"}).body_str
19
+ end
20
+
21
+ #curl -v -d "operation=move&dst_repo=affc837f-7fdd-4e91-b88a-32caf99897f2&dst_dir=/" -H 'Authorization: Token f2210dacd9c6ccb8133606d94ff8e61d99b477fd' -H 'Accept: application/json; charset=utf-8; indent=4' https://cloud.seafile.com/api2/repos/dae8cecc-2359-4d33-aa42-01b7846c4b32/file/?p=/foo.c
22
+ def post_move(filename,src_repo,data)
23
+ curl_post("#{self.host}/api2/repos/#{src_repo}/file/?p=#{filename}",data).body_str
24
+ end
25
+
26
+ #curl -d "dst_repo=73ddb2b8-dda8-471b-b7a7-ca742b07483c&dst_dir=/&file_names=foo.c" -H 'Authorization: Token f2210dacd9c6ccb8133606d94ff8e61d99b477fd' "https://cloud.seafile.com/api2/repos/c7436518-5f46-4296-97db-2fcba4c8c8db/fileops/copy/
27
+ def post_copy(src_repo,data)
28
+ curl_post("#{self.host}/api2/repos/#{src_repo}/fileops/copy/",data).body_str
29
+ end
30
+
31
+ #curl -v -d "operation=rename&newname=newfoo.c" -H 'Authorization: Token f2210dacd9c6ccb8133606d94ff8e61d99b477fd' -H 'Accept: application/json; charset=utf-8; indent=4' https://cloud.seafile.com/api2/repos/dae8cecc-2359-4d33-aa42-01b7846c4b32/file/?p=/foo.c
32
+ def post_rename(old_name,repo,data)
33
+ curl_post("#{self.host}/api2/repos/#{repo}/file/?p=#{old_name}",data).body_str
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,49 @@
1
+ module SeafileApi
2
+ class Connect
3
+ private
4
+ def get_sf_token
5
+ token_url = URI.parse("#{self.host}/api2/auth-token/")
6
+ begin
7
+ res = Net::HTTP.post_form(token_url, :username => self.user_name , :password => self.password)
8
+ rescue Exception => e
9
+ p "!!!!!!!!!!!!!!!! #{e}"
10
+ end
11
+ JSON.parse(res.body)["token"]
12
+ end
13
+
14
+ #curl -H 'Authorization: Token f2210dacd3606d94ff8e61d99b477fd' -H 'Accept: application/json; charset=utf-8; indent=4' https://cloud.seafile.com/api2/repos/dae8cecc-2359-4d33-aa42-01b7846c4b32/file/revision/?p=/foo.c\&commit_id=a1ec20709675f4dc8db825cdbca296be245d189b
15
+ def get_link_file_revision(filename,commit_id,repo)
16
+ http = curl_get("repos/#{repo}/file/revision/?p=#{filename}&commit_id=#{commit_id}")
17
+ result(cl_body_str(http))
18
+ end
19
+ #!!! get file link method
20
+ # maybe Errors
21
+ # 400 Path is missing
22
+ # 404 File not found
23
+ # 520 Operation failed.
24
+ def get_file_link(filename,repo)
25
+ http = curl_get("repos/#{repo}/file/?p=#{filename}")
26
+ result(cl_body_str(http))
27
+ end
28
+ def get_block(repo)
29
+ http = curl_get("repos/#{repo}/upload-blks-link/")
30
+ result(cl_body_str(http))
31
+ end
32
+
33
+ #curl -H 'Authorization: Token f2210dacd3606d94ff8e61d99b477fd' -H 'Accept: application/json; charset=utf-8; indent=4' https://cloud.seafile.com/api2/repos/dae8cecc-2359-4d33-aa42-01b7846c4b32/file/detail/?p=/foo.c
34
+ #get file description
35
+ def get_description(filename,repo)
36
+ http = curl_get("repos/#{repo}/file/detail/?p=#{filename}")
37
+ result(cl_body_str(http))
38
+ end
39
+
40
+ #curl -H 'Authorization: Token f2210dacd3606d94ff8e61d99b477fd' -H 'Accept: application/json; charset=utf-8; indent=4' https://cloud.seafile.com/api2/repos/dae8cecc-2359-4d33-aa42-01b7846c4b32/file/history/?p=/foo.c
41
+ #get file History
42
+ def get_history(filename,repo)
43
+ http = curl_get("repos/#{repo}/file/history/?p=#{filename}")
44
+ result(http.body_str.gsub('"', ''))
45
+ end
46
+
47
+
48
+ end
49
+ end
@@ -0,0 +1,32 @@
1
+ module SeafileApi
2
+ class Connect
3
+ private
4
+ #update file_
5
+ def post_update(repo,data)
6
+ http = curl_get("repos/#{repo}/update-link/")
7
+ if is_http?(http)
8
+ curl_post(cl_body_str(http),data).body_str
9
+ else
10
+ "something wrong #{http.body}"
11
+ end
12
+
13
+ end
14
+ =begin
15
+ 400 Bad request
16
+ 440 Invalid filename
17
+ 441 File already exists
18
+ 442 File size is too large
19
+ 443 Out of quota
20
+ 500 Internal server error
21
+ =end
22
+ def post_upload(repo,data)
23
+ http = curl_get("repos/#{repo}/upload-link/")
24
+ if is_http?(http)
25
+ curl_post(cl_body_str(http),data).body_str
26
+ else
27
+ "something wrong #{http.body_str}"
28
+ end
29
+ end
30
+
31
+ end
32
+ end
@@ -0,0 +1,38 @@
1
+ module SeafileApi
2
+ class Connect
3
+ def list_groups
4
+ get_list_groups
5
+ end
6
+ def add_group(group_name)
7
+ put_new_group(group_name)
8
+ end
9
+ #group_message
10
+ def group_messages(group_id)
11
+ get_group_messages(group_id)
12
+ end
13
+ def group_message_detail(group_id,msg_id)
14
+ get_group_message_detail(group_id,msg_id)
15
+ end
16
+ def group_messages_replies
17
+ get_group_messages_replies
18
+ end
19
+
20
+ def send_group_message(group_id,message,repo_id=self.repo,path="/")
21
+ post_message_to_group(group_id,{"message"=> message,"repo_id"=> repo_id,"path"=> path})
22
+ end
23
+
24
+ def reply_group_message(group_id,message,msg_id)
25
+ post_reply_message_to_group(group_id,msg_id,{"message" => message})
26
+ end
27
+
28
+ #group member
29
+ def add_group_member(user_email,group_id)
30
+ put_new_meber_to_group(user_email,group_id)
31
+ end
32
+
33
+ def del_group_member(user_email,group_id)
34
+ delete_group_member(user_email,group_id)
35
+ end
36
+
37
+ end
38
+ end
@@ -0,0 +1,19 @@
1
+ module SeafileApi
2
+
3
+ class Connect
4
+ private
5
+
6
+ #curl -X PUT -d "group_name=newgroup" -H 'Authorization: Token f2210dacd9c6ccb8133606d94ff8e61d99b477fd' "https://cloud.seafile.com/api2/groups/"
7
+
8
+ def put_new_group(group_name)
9
+ c = curl_put("#{self.host}/api2/groups/",{"group_name" => group_name})
10
+ c.body_str
11
+ end
12
+
13
+ def get_list_groups
14
+ curl_get("groups/").body_str
15
+ end
16
+
17
+ end
18
+
19
+ end
@@ -0,0 +1,13 @@
1
+ module SeafileApi
2
+ class Connect
3
+ private
4
+ #curl -X PUuT -d "user_name=user@example.com"-H 'Authorization: Token f2210dacd9c6ccb8133606d94ff8e61d99b477fd' "https://cloud.seafile.com/api2/groups/1/members/"
5
+ def put_new_meber_to_group(user_email,group_id)
6
+ curl_put("#{self.host}/api2/groups/#{group_id}/members/",{"user_name" => user_email}).body_str
7
+ end
8
+
9
+ def delete_group_member(user_email,group_id)
10
+ curl_delete("#{self.host}/api2/groups/#{group_id}/members/",{'user_name' =>user_email}).body_str
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,29 @@
1
+ module SeafileApi
2
+ class Connect
3
+ private
4
+ #curl -d "message=this is another test&repo_id=c7436518-5f46-4296-97db-2fcba4c8c8db&path=/123.md" -H 'Authorization: Token f2210dacd9c6ccb8133606d94ff8e61d99b477fd' "https://cloud.seafile.com/api2/group/msgs/1/"
5
+ def post_message_to_group(group_id,data)
6
+ curl_post("#{self.host}/api2/group/msgs/#{group_id}/",data).body_str
7
+ end
8
+
9
+ #curl -d "message=this is a reply" -H 'Authorization: Token f2210dacd9c6ccb8133606d94ff8e61d99b477fd' "https://cloud.seafile.com/api2/group/1/msg/1/"
10
+ def post_reply_message_to_group(group_id,msg_id,data)
11
+ curl_post("#{self.host}/api2/group/#{group_id}/msg/#{msg_id}/",data).body_str
12
+ end
13
+
14
+ #curl -H 'Authorization: Token f2210dacd9c6ccb8133606d94ff8e61d99b477fd' "https://cloud.seafile.com/api2/group/msgs/1/"
15
+ def get_group_messages(group_id)
16
+ curl_get("group/msgs/#{group_id}/").body_str
17
+ end
18
+
19
+ #curl -H 'Authorization: Token f2210dacd9c6ccb8133606d94ff8e61d99b477fd' "https://cloud.seafile.com/api2/group/1/msg/1/"
20
+ def get_group_message_detail(group_id,msg_id)
21
+ curl_get("group/#{group_id}/msg/#{msg_id}/").body_str
22
+ end
23
+ #curl -H 'Authorization: Token f2210dacd9c6ccb8133606d94ff8e61d99b477fd' "https://cloud.seafile.com/api2/new_replies/"
24
+ def get_group_messages_replies
25
+ curl_get("new_replies/").body_str
26
+ end
27
+
28
+ end
29
+ end
@@ -0,0 +1,68 @@
1
+ module SeafileApi
2
+
3
+ class Connect
4
+ #get libraries
5
+ def default_library
6
+ get_default_lib
7
+ end
8
+ def create_sub_library(repo_id,name,p='/')
9
+ get_create_sub_lib(repo_id,p,name)
10
+ end
11
+ #search not supported
12
+ def search_libraries(keyword)
13
+ get_searched_lib(keyword)
14
+ end
15
+ def list_libraries
16
+ get_list_lib
17
+ end
18
+
19
+ def list_virtual_libraries
20
+ get_list_virtual_lib
21
+ end
22
+ def library_info(repo_id)
23
+ get_lib_info(repo_id)
24
+ end
25
+
26
+ def library_owner(repo_id)
27
+ get_lib_owner(repo_id)
28
+ end
29
+
30
+ def library_history(repo_id)
31
+ get_lib_history(repo_id)
32
+ end
33
+ def fetch_library_info(repo_id)
34
+ get_lib_download_info(repo_id)
35
+ end
36
+
37
+ #post libraries
38
+ def create_library(name,desc="new repo",pwd=nil)
39
+ post_lib({"name" =>name,"desc" =>desc,"passwd" => pwd})
40
+ end
41
+ def create_default_library
42
+ post_default_lib
43
+ end
44
+ def create_public_library(repo_id)
45
+ post_public_lib(repo_id)
46
+ end
47
+
48
+ def decrypt_library(repo_id,password)
49
+ post_lib_pass(repo_id,{'password' => password })
50
+ end
51
+
52
+ # del libraries
53
+ def del_library(repo_id)
54
+ delete_lib(repo_id)
55
+ end
56
+ def remove_public_library(repo_id)
57
+ delete_public_lib(repo_id)
58
+ end
59
+
60
+
61
+
62
+
63
+ private
64
+
65
+
66
+ end
67
+
68
+ end
@@ -0,0 +1,15 @@
1
+ module SeafileApi
2
+ class Connect
3
+ private
4
+ #curl -v -X DELETE -H 'Authorization: Token f2210dacd9c6ccb8133606d94ff8e61d99b477fd' -H 'Accept: application/json; indent=4' https://cloud.seafile.com/api2/repos/8f5f2222-72a8-454f-ac40-8397c5a556a8/
5
+ def delete_lib(repo_id)
6
+ curl_delete("#{self.host}/api2/repos/#{repo_id}/").body_str
7
+ end
8
+
9
+ #curl -X DELETE -H 'Authorization: Token f2210dacd9c6ccb8133606d94ff8e61d9b477fd' -H 'Accept: application/json; indent=4' https://cloud.seafile.com/api2/repos/dae8cecc-2359-4d33-aa42-01b7846c4b32/public/
10
+ def delete_public_lib(repo_id)
11
+ curl_delete("#{self.host}/api2/repos/#{repo_id}/public/").body_str
12
+ end
13
+ end
14
+
15
+ end
@@ -0,0 +1,48 @@
1
+ module SeafileApi
2
+ class Connect
3
+ private
4
+ #curl -H 'Authorization: Token f2210dacd9c6ccb8133606d94ff8e61d99b477fd' "https://cloud.seafile.com/api2/default-repo/"
5
+ def get_default_lib
6
+ curl_get("default-repo/").body_str
7
+ end
8
+
9
+ #curl -G -H 'Authorization: Token 24fd3c026886e3121b2ca630805ed425c272cb96' -H 'Accept: application/json; indent=4' https://cloud.seafile.com/api2/repos/632ab8a8-ecf9-4435-93bf-f495d5bfe975/
10
+ def get_lib_info(repo_id)
11
+ curl_get("repos/#{repo_id}/").body_str
12
+ end
13
+
14
+ #curl -H 'Authorization: Token f2210dacd9c6ccb8133606d94ff8e61d9b477fd' -H 'Accept: application/json; indent=4' https://cloud.seafile.com/api2/repos/dae8cecc-2359-4d33-aa42-01b7846c4b32/download-info/
15
+ def get_lib_download_info(repo_id)
16
+ curl_get("repos/#{repo_id}/download-info/").body_str
17
+ end
18
+
19
+ #curl -G -H ‘Authorization: Token 24fd3c026886e3121b2ca630805ed425c272cb96’ -H ‘Accept: application/json; indent=4’ https://cloud.seafile.com/api2/search/?q=keyword
20
+ def get_searched_lib(keyword)
21
+ curl_get("search/?q=#{keyword}").body_str
22
+ end
23
+ #curl -H 'Authorization: Token 24fd3c026886e3121b2ca630805ed425c272cb96' -H 'Accept: application/json; indent=4' https://cloud.seafile.com/api2/repos/
24
+ def get_list_lib
25
+ curl_get("repos/").body_str
26
+ end
27
+ #curl -H 'Authorization: Token f2210dacd9c6ccb8133606d94ff8e61d99b477fd' "https://cloud.seafile.com/api2/virtual-repos/"
28
+ def get_list_virtual_lib
29
+ curl_get("virtual-repos/").body_str
30
+ end
31
+
32
+ #curl -H 'Authorization: Token f2210dacd9c6ccb8133606d94ff8e61d9b477fd' -H 'Accept: application/json; indent=4' https://cloud.seafile.com/api2/repos/dae8cecc-2359-4d33-aa42-01b7846c4b32/dir/sub_repo/?p=/\&name=sub_lib
33
+ def get_create_sub_lib(repo_id,p,name)
34
+ curl_get("repos/#{repo_id}/dir/sub_repo/?p=#{p}&name=#{name}").body_str
35
+ end
36
+
37
+ #curl -H 'Authorization: Token f2210dacd9c6ccb8133606d94ff8e61d9b477fd' -H 'Accept: application/json; indent=4' https://cloud.seafile.com/api2/repos/dae8cecc-2359-4d33-aa42-01b7846c4b32/owner/
38
+ def get_lib_owner(repo_id)
39
+ curl_get("repos/#{repo_id}/owner/").body_str
40
+ end
41
+
42
+ #curl -H 'Authorization: Token f2210dacd9c6ccb8133606d94ff8e61d9b477fd' -H 'Accept: application/json; indent=4' https://cloud.seafile.com/api2/repos/dae8cecc-2359-4d33-aa42-01b7846c4b32/history/
43
+ def get_lib_history(repo_id)
44
+ curl_get("repos/#{repo_id}/history/").body_str
45
+ end
46
+ end
47
+
48
+ end
@@ -0,0 +1,27 @@
1
+ module SeafileApi
2
+ class Connect
3
+ private
4
+ #curl -H 'Authorization: Token f2210dacd9c6ccb8133606d94ff8e61d99b477fd' "https://cloud.seafile.com/api2/default-repo/"
5
+ def post_default_lib
6
+ curl_post("#{self.host}/api2/default-repo/").body_str
7
+ end
8
+
9
+ #curl -X POST -H 'Authorization: Token f2210dacd9c6ccb8133606d94ff8e61d9b477fd' -H 'Accept: application/json; indent=4' https://cloud.seafile.com/api2/repos/dae8cecc-2359-4d33-aa42-01b7846c4b32/public/
10
+ def post_public_lib(repo_id)
11
+ curl_post("#{self.host}/api2/repos/#{repo_id}/public/").body_str
12
+ end
13
+
14
+
15
+
16
+ #curl -v -d "name=foo&desc=new library" -H 'Authorization: Token f2210dacd9c6ccb8133606d94ff8e61d99b477fd' -H 'Accept: application/json; indent=4' https://cloud.seafile.com/api2/repos/
17
+ def post_lib(data)
18
+ curl_post("#{self.host}/api2/repos/",data).body_str
19
+ end
20
+
21
+ #curl -v -d "password=123" -H 'Authorization: Token e6a33d61954f219a96b60f635cf02717964e4385' -H 'Accept: application/json; indent=4' https://cloud.seafile.com/api2/repos/0c2465a5-4753-4660-8a22-65abec9ec8d0/
22
+ def post_lib_pass(repo_id,data)
23
+ curl_post("#{self.host}/api2/repos/#{repo_id}/",data).body_str
24
+ end
25
+ end
26
+
27
+ end
@@ -0,0 +1,32 @@
1
+ module SeafileApi
2
+ class Connect
3
+ def list_user_message(to_email)
4
+ get_list_message(to_email)
5
+ end
6
+ def unread_message
7
+ get_count_unread_message
8
+ end
9
+ def reply_user_message(to_email,message)
10
+ post_reply_message(to_email,{"message" => message})
11
+ end
12
+
13
+ private
14
+ #curl -H 'Authorization: Token f2210dacd9c6ccb8133606d94ff8e61d99b477fd' "https://cloud.seafile.com/api2/user/msgs/"#{email}/"
15
+ def get_list_message(email)
16
+ curl_get("user/msgs/#{email}/").body_str
17
+ end
18
+
19
+ #curl -H 'Authorization: Token f2210dacd9c6ccb8133606d94ff8e61d99b477fd' "https://cloud.seafile.com/api2/unseen_messages/"
20
+
21
+ def get_count_unread_message
22
+ curl_get("unseen_messages/").body_str
23
+ end
24
+
25
+ #curl -d "message=this is a user msg reply" -H 'Authorization: Token f2210dacd9c6ccb8133606d94ff8e61d99b477fd' "https://cloud.seafile.com/api2/user/msgs/2/"
26
+ def post_reply_message(email,data)
27
+ curl_post("#{self.host}/api2/user/msgs/#{email}/",data).body_str
28
+ end
29
+
30
+ end
31
+
32
+ end
@@ -0,0 +1,58 @@
1
+ module SeafileApi
2
+ class Connect
3
+ #share
4
+ def list_file_share_link
5
+ get_list_shared_files_link
6
+ end
7
+
8
+ def create_file_share_link(file,repo_id=self.repo)
9
+ create_share_link(file,repo_id)
10
+ end
11
+ def del_file_share_link(shared_t)
12
+ delete_share_link(shared_t)
13
+ end
14
+
15
+ #shared_files
16
+ def list_shared_files
17
+ get_list_shared_files
18
+ end
19
+
20
+ def shared_file_link(file_t)
21
+ get_shared_file_link(file_t)
22
+ end
23
+ def shared_file_detail(file_t)
24
+ get_share_file_detail(file_t)
25
+ end
26
+
27
+ def del_shared_file(file_t)
28
+ delete_shared_file(file_t)
29
+ end
30
+ #
31
+ #TODO need know what is private shared file -> need test"error_msg\": \"Token not found\"}
32
+ def download_private_shared_file(file_t)
33
+ get_private_shared_file_link(file_t)
34
+ end
35
+ #TODO need know what is private shared file -> need test"error_msg\": \"Token not found\"}
36
+ def private_shared_file_detail(file_t)
37
+ get_private_shared_file_detail(file_t)
38
+ end
39
+
40
+ #shared_libraries
41
+ def list_shared_libraries
42
+ get_list_shared_libraries
43
+ end
44
+ #TODO: need know what it do
45
+ def list_beshared_libraries
46
+ get_list_beshared_libraries
47
+ end
48
+ #TODO need test not working !!
49
+ def share_library(repo_id,user,group_id,permission="rw",share_type="group")
50
+ put_share_library(repo_id,share_type,user,group_id,permission)
51
+ end
52
+ #TODO need test not working wrong user error
53
+ def unshare_library(repo_id,share_type,user,group_id)
54
+ delete_unshare_library(repo_id,share_type,user,group_id)
55
+ end
56
+
57
+ end
58
+ end
@@ -0,0 +1,20 @@
1
+ module SeafileApi
2
+ class Connect
3
+ private
4
+ #curl -H 'Authorization: Token f2210dacd9c6ccb8133606d94ff8e61d99b477fd' "https://cloud.seafile.com/api2/shared-links/"
5
+ def get_list_shared_files_link
6
+ curl_get("shared-links/").body_str
7
+ end
8
+
9
+ #curl -v -X DELETE -H 'Authorization: Token f2210dacd9c6ccb8133606d94ff8e61d99b477fd' "https://cloud.seafile.com/api2/shared-links/?t=0ae587a7d1"
10
+ def delete_share_link(shared_t)
11
+ curl_delete("#{self.host}/api2/shared-links/?t=#{shared_t}").head.split()[2]
12
+ end
13
+
14
+ #curl -v -X PUT -d "p=/foo.md" -H 'Authorization: Token f2210dacd9c6ccb8133606d94ff8e61d99b477fd' -H 'Accept: application/json; indent=4' https://cloud.seafile.com/api2/repos/afc3b694-7d4c-4b8a-86a4-89c9f3261b12/file/shared-link/
15
+ def create_share_link(file,repo_id)
16
+ curl_put("#{self.host}/api2/repos/#{repo_id}/file/shared-link/",{"p"=> file }).head.split('Location:')[1].scan(/\w{4,5}:\/\/.{1,}\//)[0]
17
+ end
18
+
19
+ end
20
+ end
@@ -0,0 +1,34 @@
1
+ module SeafileApi
2
+ class Connect
3
+ private
4
+ #curl -H 'Authorization: Token f2210dacd9c6ccb8133606d94ff8e61d99b477fd' "https://cloud.seafile.com/api2/shared-files/"
5
+ def get_list_shared_files
6
+ curl_get("shared-files/").body_str
7
+ end
8
+ #curl -H 'Authorization: Token f2210dacd9c6ccb8133606d94ff8e61d99b477fd' "https://cloud.seafile.com/api2/f/ad93cd0d66/"
9
+ def get_shared_file_link(file_t)
10
+ curl_get("f/#{file_t}/").body_str
11
+ end
12
+
13
+ #curl -H 'Authorization: Token f2210dacd9c6ccb8133606d94ff8e61d99b477fd' "https://cloud.seafile.com/api2/s/f/c5aa5f0219/"
14
+ def get_private_shared_file_link(file_t)
15
+ curl_get("s/f/#{file_t}/").body_str
16
+ end
17
+
18
+ #curl -H 'Authorization: Token f2210dacd9c6ccb8133606d94ff8e61d99b477fd' "https://cloud.seafile.com/api2/f/ad93cd0d66/detail/"
19
+ def get_share_file_detail(file_t)
20
+ curl_get("f/#{file_t}/detail/").body_str
21
+ end
22
+
23
+ #curl -H 'Authorization: Token f2210dacd9c6ccb8133606d94ff8e61d99b477fd' "https://cloud.seafile.com/api2/s/f/c5aa5f0219/detail/"
24
+ def get_private_shared_file_detail(file_t)
25
+ curl_get("s/f/#{file_t}/detail/").body_str
26
+ end
27
+
28
+ #curl -v -X DELETE -H 'Authorization: Token f2210dacd9c6ccb8133606d94ff8e61d99b477fd' "https://cloud.seafile.com/api2/shared-files/?t=94aace406a"
29
+ def delete_shared_file(file_t)
30
+ curl_delete("#{self.host}/api2/shared-links/?t=#{file_t}").head.split()[2]
31
+ end
32
+ end
33
+
34
+ end
@@ -0,0 +1,24 @@
1
+ module SeafileApi
2
+ class Connect
3
+ private
4
+ #curl -v -H 'Authorization: Token f2210dacd9c6ccb8133606d94ff8e61d99b477fd' -H 'Accept: application/json; indent=4' https://cloud.seafile.com/api2/shared-repos/
5
+ def get_list_shared_libraries
6
+ curl_get("shared-repos/").body_str
7
+ end
8
+
9
+ #curl -X PUT -H 'Authorization: Token f2210dacd9c6ccb8133606d94ff8e61d99b477fd' "https://cloud.seafile.com/api2/shared-repos/7d42522b-1f6f-465d-b9c9-879f8eed7c6c/?share_type=group&user=user@example.com&group_id=1&permission=rw"
10
+ def put_share_library(repo_id,share_type,user,group_id,permission)
11
+ curl_put("#{self.host}/api2/shared-repos/#{repo_id}/?share_type=#{share_type}&user=#{user}group_id=#{group_id}&permission=#{permission}").body_str
12
+ end
13
+
14
+ #curl -X DELETE -H 'Authorization: Token f2210dacd9c6ccb8133606d94ff8e61d99b477fd' "https://cloud.seafile.com/api2/shared-repos/7d42522b-1f6f-465d-b9c9-879f8eed7c6c/?share_type=personal&user=user@example.com&group_id=0"
15
+ def delete_unshare_library(repo_id,share_type,user,group_id)
16
+ curl_delete("#{self.host}/api2/shared-repos/#{repo_id}/?share_type=#{share_type}&user=#{user}group_id=#{group_id}").body_str
17
+ end
18
+
19
+ #curl -H 'Authorization: Token f2210dacd9c6ccb8133606d94ff8e61d99b477fd' "https://cloud.seafile.com/api2/beshared-repos/"
20
+ def get_list_beshared_libraries
21
+ curl_get("beshared-repos/").body_str
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,27 @@
1
+ module SeafileApi
2
+ class Connect
3
+ def list_starred
4
+ get_list_starred_files
5
+ end
6
+ def star_a_file(file,repo_id=self.repo)
7
+ post_star_file({"repo_id" => repo_id, "p" => file})
8
+ end
9
+ def unstar_a_file(file,repo_id=self.repo)
10
+ delete_unstar_file(repo_id,file)
11
+ end
12
+
13
+ private
14
+ #https://cloud.seafile.com/api2/starredfiles/
15
+ def get_list_starred_files
16
+ curl_get("starredfiles/").body_str
17
+ end
18
+ #curl -v -d "repo_id=dae8cecc-2359-4d33-aa42-01b7846c4b32&p=/foo.md" -H 'Authorization: Token f2210dacd9c6ccb8133606d94ff8e61d99b477fd' -H 'Accept: application/json; charset=utf-8; indent=4' https://cloud.seafile.com/api2/starredfiles/
19
+ def post_star_file(data)
20
+ curl_post("#{self.host}/api2/starredfiles/",data).body_str
21
+ end
22
+ #curl -X DELETE -v -H 'Authorization: Token f2210dacd9c6ccb8133606d94ff8e61d99b477fd' -H 'Accept: application/json; charset=utf-8; indent=4' 'https://cloud.seafile.com/api2/starredfiles/?repo_id=dae8cecc-2359-4d33-aa42-01b7846c4b32&p=/foo.md'
23
+ def delete_unstar_file(repo_id,file)
24
+ curl_delete("#{self.host}/api2/starredfiles/?repo_id=#{repo_id}&p=#{file}").body_str
25
+ end
26
+ end
27
+ end
metadata ADDED
@@ -0,0 +1,109 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: seafile-api
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ platform: ruby
6
+ authors:
7
+ - Kostiantyn Semchenko
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-06-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: curb
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: 0.8.5
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 0.8.5
55
+ description: Seafile-Api gem for ruby
56
+ email:
57
+ - kostiantyn.semchenko@masterofcode.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - lib/seafile-api.rb
63
+ - lib/seafile-api/account.rb
64
+ - lib/seafile-api/config.rb
65
+ - lib/seafile-api/directory.rb
66
+ - lib/seafile-api/file.rb
67
+ - lib/seafile-api/file/dry_methods.rb
68
+ - lib/seafile-api/file/file_operations.rb
69
+ - lib/seafile-api/file/get_operations.rb
70
+ - lib/seafile-api/file/post_operations.rb
71
+ - lib/seafile-api/group.rb
72
+ - lib/seafile-api/group/group.rb
73
+ - lib/seafile-api/group/group_member.rb
74
+ - lib/seafile-api/group/group_message.rb
75
+ - lib/seafile-api/library.rb
76
+ - lib/seafile-api/library/del_library.rb
77
+ - lib/seafile-api/library/get_library.rb
78
+ - lib/seafile-api/library/post_library.rb
79
+ - lib/seafile-api/message.rb
80
+ - lib/seafile-api/share.rb
81
+ - lib/seafile-api/shared/share.rb
82
+ - lib/seafile-api/shared/shared_files.rb
83
+ - lib/seafile-api/shared/shared_libraries.rb
84
+ - lib/seafile-api/starred.rb
85
+ homepage: https://github.com/NingenUA/seafile-api
86
+ licenses:
87
+ - MIT
88
+ metadata: {}
89
+ post_install_message:
90
+ rdoc_options: []
91
+ require_paths:
92
+ - lib
93
+ required_ruby_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - '>='
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ required_rubygems_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - '>='
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ requirements: []
104
+ rubyforge_project:
105
+ rubygems_version: 2.2.2
106
+ signing_key:
107
+ specification_version: 4
108
+ summary: Seafile-Api
109
+ test_files: []