ribose-cli 0.1.0 → 0.5.0
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 +5 -5
- data/.github/workflows/test.yml +27 -0
- data/.gitignore +1 -0
- data/.rubocop.yml +9 -1075
- data/Gemfile +3 -0
- data/README.md +315 -7
- data/bin/console +2 -5
- data/bin/ribose +22 -0
- data/lib/ribose/cli/auth.rb +10 -0
- data/lib/ribose/cli/command.rb +60 -0
- data/lib/ribose/cli/commands/base.rb +80 -0
- data/lib/ribose/cli/commands/conversation.rb +114 -0
- data/lib/ribose/cli/commands/file.rb +96 -0
- data/lib/ribose/cli/commands/invitation.rb +81 -0
- data/lib/ribose/cli/commands/join_space.rb +78 -0
- data/lib/ribose/cli/commands/member.rb +81 -0
- data/lib/ribose/cli/commands/message.rb +98 -0
- data/lib/ribose/cli/commands/note.rb +98 -0
- data/lib/ribose/cli/commands/space.rb +86 -0
- data/lib/ribose/cli/rcfile.rb +67 -0
- data/lib/ribose/cli/util.rb +22 -0
- data/lib/ribose/cli/version.rb +2 -2
- data/lib/ribose/cli.rb +21 -2
- data/ribose-cli.gemspec +11 -3
- data/spec/acceptance/config_spec.rb +17 -0
- data/spec/acceptance/conversation_spec.rb +90 -0
- data/spec/acceptance/file_spec.rb +80 -0
- data/spec/acceptance/invitation_spec.rb +109 -0
- data/spec/acceptance/join_space_spec.rb +73 -0
- data/spec/acceptance/member_spec.rb +87 -0
- data/spec/acceptance/message_spec.rb +67 -0
- data/spec/acceptance/note_spec.rb +61 -0
- data/spec/acceptance/space_spec.rb +112 -0
- data/spec/fixtures/.riboserc +4 -0
- data/spec/ribose/cli/rcfile_spec.rb +27 -0
- data/spec/spec_helper.rb +15 -1
- data/spec/support/console_helper.rb +29 -0
- metadata +113 -18
- data/.travis.yml +0 -5
- data/spec/ribose/cli_spec.rb +0 -4
@@ -0,0 +1,96 @@
|
|
1
|
+
module Ribose
|
2
|
+
module CLI
|
3
|
+
module Commands
|
4
|
+
class File < Commands::Base
|
5
|
+
desc "list", "Listing the files for a space"
|
6
|
+
option :format, aliases: "-f", desc: "Output format, eg: json"
|
7
|
+
option :space_id, required: true, aliases: "-s", desc: "The Space UUID"
|
8
|
+
|
9
|
+
def list
|
10
|
+
say(build_output(list_files(options), options))
|
11
|
+
end
|
12
|
+
|
13
|
+
desc "show", "Details for a space file"
|
14
|
+
option :file_id, required: true, desc: "The space file ID"
|
15
|
+
option :format, aliases: "-f", desc: "Output format, eg: json"
|
16
|
+
option :space_id, required: true, aliases: "-s", desc: "The Space UUID"
|
17
|
+
|
18
|
+
def show
|
19
|
+
file = Ribose::SpaceFile.fetch(options[:space_id], options[:file_id])
|
20
|
+
say(build_resource_output(file, options))
|
21
|
+
end
|
22
|
+
|
23
|
+
desc "add", "Adding a new fille to a space"
|
24
|
+
option :space_id, required: true, aliases: "-s", desc: "The Space UUID"
|
25
|
+
option :description, aliases: "-d", desc: "The file upload description"
|
26
|
+
option :tag_list, aliases: "-t", desc: "File tags, separated by commas"
|
27
|
+
|
28
|
+
def add(file)
|
29
|
+
file_upload = create_upload(file, options)
|
30
|
+
|
31
|
+
if file_upload.id
|
32
|
+
say("#{file_upload.name} added to your space!")
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
desc "update", "Update a space file"
|
37
|
+
option :file_name, aliases: "-n", desc: "New name for the file"
|
38
|
+
option :description, aliases: "-d", desc: "New description for file"
|
39
|
+
option :tags, aliases: "-t", desc: "File tags, separated by commas"
|
40
|
+
option :file_id, required: true, aliases: "-f", desc: "Space file ID"
|
41
|
+
option :space_id, required: true, aliases: "-s", desc: "The Space UUID"
|
42
|
+
|
43
|
+
def update
|
44
|
+
update_file(symbolize_keys(options))
|
45
|
+
say("The file has been updated with new attributes")
|
46
|
+
rescue Ribose::UnprocessableEntity
|
47
|
+
say("Something went wrong! Please check required attributes")
|
48
|
+
end
|
49
|
+
|
50
|
+
desc "remove", "Remove a space file"
|
51
|
+
option :file_id, required: true, aliases: "-f", desc: "Space file ID"
|
52
|
+
option :space_id, required: true, aliases: "-s", desc: "The Space UUID"
|
53
|
+
|
54
|
+
def remove
|
55
|
+
Ribose::SpaceFile.delete(options[:space_id], options[:file_id])
|
56
|
+
say("The file has been removed from your space!")
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
def list_files(attributes)
|
62
|
+
@files ||= Ribose::SpaceFile.all(attributes[:space_id])
|
63
|
+
end
|
64
|
+
|
65
|
+
def create_upload(file, attributes = {})
|
66
|
+
Ribose::SpaceFile.create(
|
67
|
+
attributes[:space_id],
|
68
|
+
file: file,
|
69
|
+
tag_list: attributes[:tag_list],
|
70
|
+
description: attributes[:description],
|
71
|
+
)
|
72
|
+
end
|
73
|
+
|
74
|
+
def update_file(attributes)
|
75
|
+
Ribose::SpaceFile.update(
|
76
|
+
attributes.delete(:space_id),
|
77
|
+
attributes.delete(:file_id),
|
78
|
+
attributes,
|
79
|
+
)
|
80
|
+
end
|
81
|
+
|
82
|
+
def table_headers
|
83
|
+
["ID", "Name", "Versions"]
|
84
|
+
end
|
85
|
+
|
86
|
+
def table_field_names
|
87
|
+
%w(id name author content_type content_size version)
|
88
|
+
end
|
89
|
+
|
90
|
+
def table_rows(files)
|
91
|
+
files.map { |file| [file.id, file.name, file.version] }
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
module Ribose
|
2
|
+
module CLI
|
3
|
+
module Commands
|
4
|
+
class Invitation < Commands::Base
|
5
|
+
desc "list", "List space invitations"
|
6
|
+
option :query, type: :hash, desc: "Query parameters as hash"
|
7
|
+
option :format, aliases: "-f", desc: "Output format, eg: json"
|
8
|
+
|
9
|
+
def list
|
10
|
+
say(build_output(Ribose::SpaceInvitation.all(options), options))
|
11
|
+
end
|
12
|
+
|
13
|
+
desc "add", "Add a new space member"
|
14
|
+
option :space_id, required: true, aliases: "-s", desc: "The Space UUID"
|
15
|
+
option :user_id, aliases: "-u", type: :hash, desc: "Invitee's IDS"
|
16
|
+
option :email, aliases: "-e", type: :hash, desc: "Invitee's emails"
|
17
|
+
option :message, aliases: "-m", desc: "Space invitation message"
|
18
|
+
|
19
|
+
def add
|
20
|
+
invoke(Member, :add)
|
21
|
+
end
|
22
|
+
|
23
|
+
desc "update", "Update a space invitation"
|
24
|
+
option :role_id, aliases: "-r", desc: "The Role ID"
|
25
|
+
option :state, aliases: "-s", desc: "New state for invitation"
|
26
|
+
option :invitation_id, required: true, desc: "Invitation UUID"
|
27
|
+
|
28
|
+
def update
|
29
|
+
update_invitation(options)
|
30
|
+
say("Space invitation has been updated!")
|
31
|
+
rescue Ribose::UnprocessableEntity
|
32
|
+
say("Something went wrong! Please check required attributes")
|
33
|
+
end
|
34
|
+
|
35
|
+
desc "accept", "Accept a space invitation"
|
36
|
+
option :invitation_id, required: true, desc: "Invitation UUID"
|
37
|
+
|
38
|
+
def accept
|
39
|
+
Ribose::SpaceInvitation.accept(options[:invitation_id])
|
40
|
+
say("Space invitation has been accepted!")
|
41
|
+
end
|
42
|
+
|
43
|
+
desc "reject", "Reject a space invitation"
|
44
|
+
option :invitation_id, required: true, desc: "Invitation UUID"
|
45
|
+
|
46
|
+
def reject
|
47
|
+
Ribose::SpaceInvitation.reject(options[:invitation_id])
|
48
|
+
say("Space invitation has been rejected!")
|
49
|
+
end
|
50
|
+
|
51
|
+
desc "remove", "Remove a space invitation"
|
52
|
+
option :invitation_id, required: true, desc: "Invitation UUID"
|
53
|
+
|
54
|
+
def remove
|
55
|
+
Ribose::SpaceInvitation.cancel(options[:invitation_id])
|
56
|
+
say("Space invitation has been removed!")
|
57
|
+
rescue Ribose::Forbidden
|
58
|
+
say("Could not remove the specified invitation")
|
59
|
+
end
|
60
|
+
|
61
|
+
private
|
62
|
+
|
63
|
+
def update_invitation(attributes)
|
64
|
+
Ribose::SpaceInvitation.update(
|
65
|
+
attributes.delete(:invitation_id), attributes
|
66
|
+
)
|
67
|
+
end
|
68
|
+
|
69
|
+
def table_headers
|
70
|
+
["ID", "Inviter", "Type", "Space Name"]
|
71
|
+
end
|
72
|
+
|
73
|
+
def table_rows(invitations)
|
74
|
+
invitations.map do |invt|
|
75
|
+
[invt.id, invt.inviter.name, invt.type, invt.space.name]
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
module Ribose
|
2
|
+
module CLI
|
3
|
+
module Commands
|
4
|
+
class JoinSpace < Commands::Base
|
5
|
+
desc "list", "List join space requests"
|
6
|
+
option :query, type: :hash, desc: "Query parameters as hash"
|
7
|
+
option :format, aliases: "-f", desc: "Output format, eg: json"
|
8
|
+
|
9
|
+
def list
|
10
|
+
say(build_output(Ribose::JoinSpaceRequest.all(options), options))
|
11
|
+
end
|
12
|
+
|
13
|
+
desc "show", "Fetch a join space request"
|
14
|
+
option :format, aliases: "-f", desc: "Output format, eg: json"
|
15
|
+
option :request_id, required: true, aliases: "-r", desc: "Request UUID"
|
16
|
+
|
17
|
+
def show
|
18
|
+
join_space = Ribose::JoinSpaceRequest.fetch(options[:request_id])
|
19
|
+
say(build_resource_output(join_space, options))
|
20
|
+
end
|
21
|
+
|
22
|
+
desc "add", "Create a join space request"
|
23
|
+
option :type, aliases: "-t", desc: "The join request type"
|
24
|
+
option :state, desc: "The state for the join space request"
|
25
|
+
option :message, aliases: "-m", desc: "The join request message"
|
26
|
+
option :space_id, required: true, aliases: "-s", desc: "The Space UUID"
|
27
|
+
|
28
|
+
def add
|
29
|
+
create_join_request(options)
|
30
|
+
say("Join space request has been sent successfully!")
|
31
|
+
rescue Ribose::UnprocessableEntity
|
32
|
+
say("Something went wrong! Please check required attributes")
|
33
|
+
end
|
34
|
+
|
35
|
+
desc "accept", "Accept a join space request"
|
36
|
+
option :request_id, required: true, aliases: "-r", desc: "Request UUID"
|
37
|
+
|
38
|
+
def accept
|
39
|
+
Ribose::JoinSpaceRequest.accept(options[:request_id])
|
40
|
+
say("Join space request has been accepted!")
|
41
|
+
end
|
42
|
+
|
43
|
+
desc "reject", "Reject a join space request"
|
44
|
+
option :request_id, required: true, aliases: "-r", desc: "Request UUID"
|
45
|
+
|
46
|
+
def reject
|
47
|
+
Ribose::JoinSpaceRequest.reject(options[:request_id])
|
48
|
+
say("Join space request has been rejected!")
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def create_join_request(attributes)
|
54
|
+
Ribose::JoinSpaceRequest.create(
|
55
|
+
state: attributes[:state] || 0,
|
56
|
+
space_id: attributes[:space_id],
|
57
|
+
body: attributes[:message] || "",
|
58
|
+
type: attributes[:type] || "Invitation::JoinSpaceRequest",
|
59
|
+
)
|
60
|
+
end
|
61
|
+
|
62
|
+
def table_headers
|
63
|
+
["ID", "Inviter", "Type", "Space Name"]
|
64
|
+
end
|
65
|
+
|
66
|
+
def table_field_names
|
67
|
+
%w(id email body state type)
|
68
|
+
end
|
69
|
+
|
70
|
+
def table_rows(requests)
|
71
|
+
requests.map do |req|
|
72
|
+
[req.id, req.inviter.name, req.type, req.space.name]
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
module Ribose
|
2
|
+
module CLI
|
3
|
+
module Commands
|
4
|
+
class Member < Commands::Base
|
5
|
+
desc "list", "List space members"
|
6
|
+
option :format, aliases: "-f", desc: "Output format, eg: json"
|
7
|
+
option :space_id, required: true, aliases: "-s", desc: "The Space UUID"
|
8
|
+
|
9
|
+
def list
|
10
|
+
say(build_output(Ribose::Member.all(options[:space_id]), options))
|
11
|
+
end
|
12
|
+
|
13
|
+
desc "add", "Add a new space member"
|
14
|
+
option :space_id, required: true, aliases: "-s", desc: "The Space UUID"
|
15
|
+
option :user_id, aliases: "-u", type: :hash, desc: "Invitee's IDS"
|
16
|
+
option :email, aliases: "-e", type: :hash, desc: "Invitee's emails"
|
17
|
+
option :message, aliases: "-m", desc: "Space invitation message"
|
18
|
+
|
19
|
+
def add
|
20
|
+
add_member_to_space(options)
|
21
|
+
say("Invitation has been sent successfully!")
|
22
|
+
rescue Ribose::UnprocessableEntity
|
23
|
+
say("Something went wrong! Please check required attributes")
|
24
|
+
end
|
25
|
+
|
26
|
+
desc "update", "Update existing member details"
|
27
|
+
option :role_id, required: true, aliases: "-r", desc: "The role id"
|
28
|
+
option :member_id, required: true, aliases: "-m", desc: "Member UUID"
|
29
|
+
option :space_id, required: true, aliases: "-s", desc: "The Space UUID"
|
30
|
+
|
31
|
+
def update
|
32
|
+
update_member_role(options)
|
33
|
+
say("Member has been updated with new role!")
|
34
|
+
rescue Ribose::UnprocessableEntity
|
35
|
+
say("Something went wrong! Please check required attributes")
|
36
|
+
end
|
37
|
+
|
38
|
+
desc "remove", "Remove a space member"
|
39
|
+
option :member_id, required: true, aliases: "-m", desc: "Member UUID"
|
40
|
+
option :space_id, required: true, aliases: "-s", desc: "The Space UUID"
|
41
|
+
|
42
|
+
def remove
|
43
|
+
Ribose::Member.delete(options[:space_id], options[:member_id])
|
44
|
+
say("The member has been removed from this space")
|
45
|
+
rescue Ribose::UnprocessableEntity
|
46
|
+
say("Something went wrong! Please provide a valid id/uuid")
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def add_member_to_space(attributes)
|
52
|
+
Ribose::SpaceInvitation.mass_create(
|
53
|
+
attributes[:space_id],
|
54
|
+
body: attributes[:message] || "",
|
55
|
+
emails: (attributes[:email] || {}).keys,
|
56
|
+
user_ids: (attributes[:user_id] || {}).keys,
|
57
|
+
role_ids: (attributes[:email] || {}).merge(
|
58
|
+
attributes[:user_id] || {},
|
59
|
+
),
|
60
|
+
)
|
61
|
+
end
|
62
|
+
|
63
|
+
def update_member_role(attributes)
|
64
|
+
Ribose::MemberRole.assign(
|
65
|
+
attributes[:space_id], attributes[:member_id], attributes[:role_id]
|
66
|
+
)
|
67
|
+
end
|
68
|
+
|
69
|
+
def table_headers
|
70
|
+
["ID", "Name", "Role Name"]
|
71
|
+
end
|
72
|
+
|
73
|
+
def table_rows(members)
|
74
|
+
members.map do |member|
|
75
|
+
[member.user_id, member.user.name, member.role_name_in_space]
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
module Ribose
|
2
|
+
module CLI
|
3
|
+
module Commands
|
4
|
+
class Message < Commands::Base
|
5
|
+
desc "list", "Listing Messages"
|
6
|
+
option :conversation_id, aliases: "-c", required: true
|
7
|
+
option :format, aliases: "-f", desc: "Output format, eg: json"
|
8
|
+
option :space_id, required: true, aliases: "-s", desc: "The Space UUID"
|
9
|
+
|
10
|
+
def list
|
11
|
+
say(build_output(list_messages, options))
|
12
|
+
end
|
13
|
+
|
14
|
+
desc "add", "Add New Message to Conversation"
|
15
|
+
option :message_body, required: true, aliases: "-b"
|
16
|
+
option :conversation_id, aliases: "-c", required: true
|
17
|
+
option :space_id, required: true, aliases: "-s", desc: "The Space UUID"
|
18
|
+
|
19
|
+
def add
|
20
|
+
message = create_message(options)
|
21
|
+
say("Messge has been posted! Id: " + message.id)
|
22
|
+
end
|
23
|
+
|
24
|
+
desc "update", "Update an existing Message"
|
25
|
+
option :message_body, required: true, aliases: "-b"
|
26
|
+
option :message_id, required: true, aliases: "-m"
|
27
|
+
option :conversation_id, aliases: "-c", required: true
|
28
|
+
option :space_id, required: true, aliases: "-s", desc: "The Space UUID"
|
29
|
+
|
30
|
+
def update
|
31
|
+
update_message(options)
|
32
|
+
say("Messge has been updated!")
|
33
|
+
end
|
34
|
+
|
35
|
+
desc "remove", "Remove A Conversation from Space"
|
36
|
+
option :message_id, required: true, aliases: "-m"
|
37
|
+
option :conversation_id, aliases: "-c", required: true
|
38
|
+
option :space_id, required: true, aliases: "-s", desc: "The Space UUID"
|
39
|
+
|
40
|
+
def remove
|
41
|
+
remove_message(options)
|
42
|
+
say("The message has been removed!")
|
43
|
+
rescue
|
44
|
+
say("Please provide a valid message UUID")
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def list_messages
|
50
|
+
@messages ||= Ribose::Message.all(
|
51
|
+
space_id: options[:space_id],
|
52
|
+
conversation_id: options[:conversation_id],
|
53
|
+
)
|
54
|
+
end
|
55
|
+
|
56
|
+
def create_message(options)
|
57
|
+
Ribose::Message.create(
|
58
|
+
space_id: options[:space_id],
|
59
|
+
contents: options[:message_body],
|
60
|
+
conversation_id: options[:conversation_id],
|
61
|
+
)
|
62
|
+
end
|
63
|
+
|
64
|
+
def update_message(options)
|
65
|
+
Ribose::Message.update(
|
66
|
+
space_id: options[:space_id],
|
67
|
+
message_id: options[:message_id],
|
68
|
+
contents: options[:message_body],
|
69
|
+
conversation_id: options[:conversation_id],
|
70
|
+
)
|
71
|
+
end
|
72
|
+
|
73
|
+
def remove_message(options)
|
74
|
+
Ribose::Message.remove(
|
75
|
+
space_id: options[:space_id],
|
76
|
+
message_id: options[:message_id],
|
77
|
+
conversation_id: options[:conversation_id],
|
78
|
+
)
|
79
|
+
end
|
80
|
+
|
81
|
+
def sanitize(content, length = 30)
|
82
|
+
content = content.to_s.gsub(/<\/?[^>]*>/, "")
|
83
|
+
Ribose::CLI::Util.truncate(content, length)
|
84
|
+
end
|
85
|
+
|
86
|
+
def table_headers
|
87
|
+
["ID", "User", "Message"]
|
88
|
+
end
|
89
|
+
|
90
|
+
def table_rows(messages)
|
91
|
+
messages.map do |message|
|
92
|
+
[message.id, message.user.name, sanitize(message.contents)]
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
module Ribose
|
2
|
+
module CLI
|
3
|
+
module Commands
|
4
|
+
class Note < Commands::Base
|
5
|
+
desc "list", "Listing notes for a user space"
|
6
|
+
option :format, aliases: "-f", desc: "Output format, eg: json"
|
7
|
+
option :space_id, required: true, aliases: "-s", desc: "The Space UUID"
|
8
|
+
|
9
|
+
def list
|
10
|
+
say(build_output(list_notes(options), options))
|
11
|
+
end
|
12
|
+
|
13
|
+
desc "show", "Show details for a note"
|
14
|
+
option :format, aliases: "-f", desc: "Output format, eg: json"
|
15
|
+
option :note_id, required: true, aliases: "-n", desc: "The Note UUID"
|
16
|
+
option :space_id, required: true, aliases: "-s", desc: "The Space UUID"
|
17
|
+
|
18
|
+
def show
|
19
|
+
note = Ribose::Wiki.fetch(options[:space_id], options[:note_id])
|
20
|
+
say(build_resource_output(note, options))
|
21
|
+
end
|
22
|
+
|
23
|
+
desc "add", "Add a new note to a user space"
|
24
|
+
option :title, required: true, desc: "The title for the note"
|
25
|
+
option :tag_list, aliases: "-t", desc: "Note tags, separated by commas"
|
26
|
+
option :space_id, required: true, aliases: "-s", desc: "The Space UUID"
|
27
|
+
|
28
|
+
def add
|
29
|
+
note = create_note(options)
|
30
|
+
say("Note has been posted added! Id: " + note.id.to_s)
|
31
|
+
end
|
32
|
+
|
33
|
+
desc "update", "Update details for an existing note"
|
34
|
+
option :note_id, required: true, aliases: "-n", desc: "The Note UUID"
|
35
|
+
option :space_id, required: true, aliases: "-s", desc: "The Space UUID"
|
36
|
+
option :title, desc: "The title for the note"
|
37
|
+
option :tag_list, aliases: "-t", desc: "Note tags, separated by commas"
|
38
|
+
|
39
|
+
def update
|
40
|
+
update_note(options)
|
41
|
+
say("Your space note has been updated!")
|
42
|
+
rescue Ribose::UnprocessableEntity
|
43
|
+
say("Something went wrong!, please check required attributes")
|
44
|
+
end
|
45
|
+
|
46
|
+
desc "remove", "Removes a note from a space"
|
47
|
+
option :note_id, required: true, aliases: "-n", desc: "The Note UUID"
|
48
|
+
option :space_id, required: true, aliases: "-s", desc: "The Space UUID"
|
49
|
+
|
50
|
+
def remove
|
51
|
+
remove_note(options)
|
52
|
+
say("The note has been removed!")
|
53
|
+
rescue
|
54
|
+
say("Could not remove the specified note")
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
|
59
|
+
def list_notes(attributes)
|
60
|
+
@notes ||= Ribose::Wiki.all(attributes[:space_id])
|
61
|
+
end
|
62
|
+
|
63
|
+
def create_note(attributes)
|
64
|
+
Ribose::Wiki.create(
|
65
|
+
attributes[:space_id],
|
66
|
+
name: attributes[:title],
|
67
|
+
tag_list: attributes[:tag_list] || "",
|
68
|
+
)
|
69
|
+
end
|
70
|
+
|
71
|
+
def update_note(attributes)
|
72
|
+
Ribose::Wiki.update(
|
73
|
+
attributes[:space_id],
|
74
|
+
attributes[:note_id],
|
75
|
+
name: attributes[:title] || "",
|
76
|
+
tag_list: attributes[:tag_list] || "",
|
77
|
+
)
|
78
|
+
end
|
79
|
+
|
80
|
+
def remove_note(attributes)
|
81
|
+
Ribose::Wiki.delete(attributes[:space_id], attributes[:note_id])
|
82
|
+
end
|
83
|
+
|
84
|
+
def table_headers
|
85
|
+
["ID", "Name", "Revisions"]
|
86
|
+
end
|
87
|
+
|
88
|
+
def table_field_names
|
89
|
+
%w(id space_id name address version revision tag_list)
|
90
|
+
end
|
91
|
+
|
92
|
+
def table_rows(notes)
|
93
|
+
notes.map { |note| [note.id, note.name, note.revision] }
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
module Ribose
|
2
|
+
module CLI
|
3
|
+
module Commands
|
4
|
+
class Space < Commands::Base
|
5
|
+
desc "list", "List user spaces"
|
6
|
+
option :format, aliases: "-f", desc: "Output format, eg: json"
|
7
|
+
|
8
|
+
def list
|
9
|
+
say(build_output(list_user_spaces, options))
|
10
|
+
end
|
11
|
+
|
12
|
+
desc "show", "Details for a space"
|
13
|
+
option :space_id, aliases: "-s", description: "The Space UUID"
|
14
|
+
option :format, aliases: "-f", desc: "Output format, eg: json"
|
15
|
+
|
16
|
+
def show
|
17
|
+
space = Ribose::Space.fetch(options[:space_id])
|
18
|
+
say(build_resource_output(space, options))
|
19
|
+
end
|
20
|
+
|
21
|
+
desc "add", "Add a new user space"
|
22
|
+
option :name, aliases: "-n", desc: "Name of the space"
|
23
|
+
option :description, desc: "The description for space"
|
24
|
+
option :category_id, desc: "The category for this space"
|
25
|
+
option :access, default: "open", desc: "The visiblity for the space"
|
26
|
+
|
27
|
+
def add
|
28
|
+
space = Ribose::Space.create(**symbolize_keys(options))
|
29
|
+
say("New Space created! Id: " + space.id)
|
30
|
+
end
|
31
|
+
|
32
|
+
desc "update", "Update an existing space"
|
33
|
+
option :space_id, required: true, desc: "The Space UUID"
|
34
|
+
option :access, desc: "The visiblity for the space"
|
35
|
+
option :name, aliases: "-n", desc: "Name of the space"
|
36
|
+
option :description, desc: "The description for space"
|
37
|
+
option :category_id, desc: "The category for this space"
|
38
|
+
|
39
|
+
def update
|
40
|
+
attributes = symbolize_keys(options)
|
41
|
+
Ribose::Space.update(attributes.delete(:space_id), attributes)
|
42
|
+
say("Your space has been updated!")
|
43
|
+
rescue Ribose::UnprocessableEntity
|
44
|
+
say("Something went wrong!, please check required attributes")
|
45
|
+
end
|
46
|
+
|
47
|
+
desc "remove", "Remove an existing space"
|
48
|
+
option :space_id, required: true, desc: "The Space UUID"
|
49
|
+
option :confirmation, required: true, desc: "The confirmation"
|
50
|
+
|
51
|
+
def remove
|
52
|
+
remove_space(options)
|
53
|
+
say("The Sapce has been removed!")
|
54
|
+
rescue
|
55
|
+
say("Please provide a valid Space UUID")
|
56
|
+
end
|
57
|
+
|
58
|
+
private
|
59
|
+
|
60
|
+
def list_user_spaces
|
61
|
+
@user_spaces ||= Ribose::Space.all
|
62
|
+
end
|
63
|
+
|
64
|
+
def remove_space(attributes)
|
65
|
+
Ribose::Space.remove(
|
66
|
+
attributes[:space_id],
|
67
|
+
password_confirmation: attributes[:confirmation],
|
68
|
+
)
|
69
|
+
end
|
70
|
+
|
71
|
+
def table_headers
|
72
|
+
["ID", "Name", "Active?"]
|
73
|
+
end
|
74
|
+
|
75
|
+
def table_rows(spaces)
|
76
|
+
spaces.map { |space| [space.id, space.name, space.active ] }
|
77
|
+
end
|
78
|
+
|
79
|
+
# Single resource fields
|
80
|
+
def table_field_names
|
81
|
+
%w(id name visibility active members_count role_name)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require "yaml"
|
2
|
+
require "singleton"
|
3
|
+
|
4
|
+
module Ribose
|
5
|
+
module CLI
|
6
|
+
class RCFile
|
7
|
+
attr_reader :path, :data
|
8
|
+
FILE_NAME = ".riboserc".freeze
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
@path = build_rcfile_path
|
12
|
+
@data = load_configuration
|
13
|
+
end
|
14
|
+
|
15
|
+
def set(email:, password:, token: nil, api_host: nil)
|
16
|
+
data[:api_token] = token
|
17
|
+
data[:user_email] = email
|
18
|
+
data[:user_password] = password
|
19
|
+
data[:api_host] = api_host
|
20
|
+
|
21
|
+
write_api_details_to_file
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.api_token
|
25
|
+
new.data[:api_token]
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.user_email
|
29
|
+
new.data[:user_email]
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.user_password
|
33
|
+
new.data[:user_password]
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.api_host
|
37
|
+
ENV.fetch("RIBOSE_API_HOST", new.data[:api_host])
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.set(email:, password:, token: nil, api_host: nil)
|
41
|
+
new.set(token: token, email: email, password: password, api_host: api_host)
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def build_rcfile_path
|
47
|
+
File.join(File.expand_path("~"), FILE_NAME)
|
48
|
+
end
|
49
|
+
|
50
|
+
def load_configuration
|
51
|
+
YAML.load_file(path)
|
52
|
+
rescue Errno::ENOENT
|
53
|
+
default_configuration
|
54
|
+
end
|
55
|
+
|
56
|
+
def default_configuration
|
57
|
+
{ api_token: nil, user_email: nil }
|
58
|
+
end
|
59
|
+
|
60
|
+
def write_api_details_to_file
|
61
|
+
File.open(path, File::RDWR | File::TRUNC | File::CREAT, 0o0600) do |rc|
|
62
|
+
rc.write(data.to_yaml)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|