ribose-cli 0.1.0 → 0.2.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.
@@ -0,0 +1,22 @@
1
+ require "terminal-table"
2
+
3
+ module Ribose
4
+ module CLI
5
+ module Util
6
+ def self.list(headings:, rows:)
7
+ Terminal::Table.new do |table|
8
+ table.headings = headings
9
+ table.rows = rows
10
+ end
11
+ end
12
+
13
+ def self.truncate(content, length = 50)
14
+ if content && content.length > length
15
+ content = content[0..length] + "..."
16
+ end
17
+
18
+ content
19
+ end
20
+ end
21
+ end
22
+ end
@@ -1,5 +1,5 @@
1
1
  module Ribose
2
- module Cli
3
- VERSION = "0.1.0".freeze
2
+ module CLI
3
+ VERSION = "0.2.0".freeze
4
4
  end
5
5
  end
data/lib/ribose/cli.rb CHANGED
@@ -1,7 +1,26 @@
1
+ require "thor"
2
+ require "ribose"
3
+
4
+ require "ribose/cli/auth"
5
+ require "ribose/cli/util"
1
6
  require "ribose/cli/version"
7
+ require "ribose/cli/command"
2
8
 
3
9
  module Ribose
4
- module Cli
5
- # Your code goes here...
10
+ module CLI
11
+ def self.start(arguments)
12
+ Ribose::CLI::Command.start(arguments)
13
+ rescue Ribose::Errors::Forbidden
14
+ Thor::Shell::Basic.new.say(
15
+ "Invalid: Missing API Configuration\n\n" \
16
+ "Ribose API Token & Email are required for any of the CLI operation\n" \
17
+ "You can set your API Key using `ribose config --token "" --email "" `",
18
+ )
19
+ end
20
+ end
21
+
22
+ # Temporary: The API Client will implement it
23
+ module Errors
24
+ class Forbidden < StandardError; end
6
25
  end
7
26
  end
data/ribose-cli.gemspec CHANGED
@@ -6,7 +6,7 @@ require "ribose/cli/version"
6
6
 
7
7
  Gem::Specification.new do |spec|
8
8
  spec.name = "ribose-cli"
9
- spec.version = Ribose::Cli::VERSION
9
+ spec.version = Ribose::CLI::VERSION
10
10
  spec.authors = ["Ribose Inc."]
11
11
  spec.email = ["operations@ribose.com"]
12
12
 
@@ -20,8 +20,14 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.require_paths = ["lib"]
22
22
  spec.bindir = "bin"
23
+ spec.executables = "ribose"
24
+
25
+ spec.add_dependency "thor", "~> 0.19.4"
26
+ spec.add_dependency "ribose", "~> 0.2.0"
27
+ spec.add_dependency "terminal-table"
23
28
 
24
29
  spec.add_development_dependency "bundler", "~> 1.14"
25
30
  spec.add_development_dependency "rake", "~> 10.0"
26
31
  spec.add_development_dependency "rspec", "~> 3.0"
32
+ spec.add_development_dependency "webmock", "~> 2.0"
27
33
  end
@@ -0,0 +1,17 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe "Config" do
4
+ it "allows us to set token and user email" do
5
+ allow(File).to receive(:expand_path).and_return(fixtures_path)
6
+ command = %w(config --token SECRET_TOKEN --email user-one@example.com)
7
+
8
+ Ribose::CLI.start(command)
9
+
10
+ expect(Ribose::CLI::RCFile.api_token).to eq("SECRET_TOKEN")
11
+ expect(Ribose::CLI::RCFile.user_email).to eq("user-one@example.com")
12
+ end
13
+
14
+ def fixtures_path
15
+ File.expand_path("../../fixtures", __FILE__)
16
+ end
17
+ end
@@ -0,0 +1,90 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe "Space Conversation" do
4
+ describe "Listing conversations" do
5
+ it "retrieves the list of conversations" do
6
+ command = %w(conversation list --space-id 123456789 --format json)
7
+
8
+ stub_ribose_space_conversation_list(123456789)
9
+ output = capture_stdout { Ribose::CLI.start(command) }
10
+
11
+ expect(output).to match(/"name":"Sample conversation"/)
12
+ expect(output).to match(/"id":"741ebd0f-0959-42c5-b7d3-7749666d2f5f"/)
13
+ end
14
+ end
15
+
16
+ describe "Retrieving a conversation" do
17
+ it "retrieves the details for a conversation" do
18
+ command = %w(conversation show --space-id 12345 --conversation-id 6789)
19
+
20
+ stub_ribose_space_conversation_fetch_api(12345, 6789)
21
+ output = capture_stdout { Ribose::CLI.start(command) }
22
+
23
+ expect(output).to match(/number_of_messages | 1/)
24
+ expect(output).to match(/name | Trips to the Mars!/)
25
+ end
26
+ end
27
+
28
+ describe "Adding a new conversations" do
29
+ it "creates a new conversation into a user space" do
30
+ command = %W(
31
+ conversation add
32
+ --title #{conversation.title}
33
+ --space-id #{conversation.space_id}
34
+ --tags #{conversation.tags}
35
+ )
36
+
37
+ stub__conversation_creation(conversation)
38
+ output = capture_stdout { Ribose::CLI.start(command) }
39
+
40
+ expect(output).to match(/New Conversation created!/)
41
+ expect(output).to match(/Id: ee50bb3c-ed79-4efc-821a-64926f645bfb/)
42
+ end
43
+ end
44
+
45
+ describe "Update an existing conversation" do
46
+ it "updates details for an existing conversation" do
47
+ command = %W(
48
+ conversation update
49
+ --conversation-id 123456789
50
+ --space-id #{conversation.space_id}
51
+ --title #{conversation.title}
52
+ --tags #{conversation.tags}
53
+ )
54
+
55
+ stub_ribose_space_conversation_update_api(
56
+ 123_456_789, 123_456_789, conversation.to_h
57
+ )
58
+
59
+ output = capture_stdout { Ribose::CLI.start(command) }
60
+
61
+ expect(output).to match(/Your conversation has been updated!/)
62
+ end
63
+ end
64
+
65
+ describe "Remove a conversation" do
66
+ it "removes a conversation from a speace" do
67
+ command = %w(conversation remove -s 9876 --conversation-id 12345)
68
+
69
+ stub_ribose_space_conversation_remove(9876, 12345)
70
+ output = capture_stdout { Ribose::CLI.start(command) }
71
+
72
+ expect(output).to match(/The Conversation has been removed!/)
73
+ end
74
+ end
75
+
76
+ def conversation
77
+ @conversation ||= OpenStruct.new(
78
+ space_id: 123_456_789, title: "The Special Conversation", tags: "sample",
79
+ )
80
+ end
81
+
82
+ def stub__conversation_creation(conversation)
83
+ stub_ribose_space_conversation_create(
84
+ conversation.space_id,
85
+ name: conversation.title,
86
+ tag_list: conversation.tags,
87
+ space_id: conversation.space_id.to_s,
88
+ )
89
+ end
90
+ end
@@ -0,0 +1,80 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe "File Interface" do
4
+ describe "listing files" do
5
+ it "retrieves the list of files" do
6
+ command = %w(file list --space-id 123456 --format json)
7
+
8
+ stub_ribose_space_file_list(123456)
9
+ output = capture_stdout { Ribose::CLI.start(command) }
10
+
11
+ expect(output).to match(/"id":9896/)
12
+ expect(output).to match(/"name":"sample-file.png"/)
13
+ end
14
+ end
15
+
16
+ describe "show" do
17
+ it "retrieves the details for a file" do
18
+ command = %w(file show --file-id 5678 --space-id 1234)
19
+
20
+ stub_ribose_space_file_fetch_api(1234, 5678)
21
+ output = capture_stdout { Ribose::CLI.start(command) }
22
+
23
+ expect(output).to match(/id | 9896/)
24
+ expect(output).to match(/name | sample-file.png/)
25
+ expect(output).to match(/content_type | image\/png/)
26
+ end
27
+ end
28
+
29
+ describe "adding new file" do
30
+ it "uploads the new file to user space" do
31
+ command = %W(file add --space-id 123456 #{file_attributes[:file]})
32
+
33
+ stub_ribose_space_file_upload_api(123456, file_attributes)
34
+ output = capture_stdout { Ribose::CLI.start(command) }
35
+
36
+ expect(output).to match(/sample.png added to your space!/)
37
+ end
38
+ end
39
+
40
+ describe "update" do
41
+ it "updates details for a space file" do
42
+ command = %W(
43
+ file update
44
+ --file-id 5678
45
+ --space-id 1234
46
+ --tags #{update_attributes[:tags]}
47
+ --file-name #{update_attributes[:file_name]}
48
+ --description #{update_attributes[:description]}
49
+ )
50
+
51
+ stub_ribose_space_file_update_api(1234, 5678, update_attributes)
52
+ output = capture_stdout { Ribose::CLI.start(command) }
53
+
54
+ expect(output).to match(/The file has been updated with new attributes/)
55
+ end
56
+ end
57
+
58
+ describe "remove" do
59
+ it "removes a file from a user space" do
60
+ command = %w(file remove --file-id 5678 --space-id 1234)
61
+
62
+ stub_ribose_space_file_delete_api(1234, 5678)
63
+ output = capture_stdout { Ribose::CLI.start(command) }
64
+
65
+ expect(output).to match(/The file has been removed from your space!/)
66
+ end
67
+ end
68
+
69
+ def file_attributes
70
+ { file: sample_fixture, description: "", tag_list: "" }
71
+ end
72
+
73
+ def update_attributes
74
+ { tags: "one, two", file_name: "new name", description: "New description" }
75
+ end
76
+
77
+ def sample_fixture
78
+ @sample_fixture ||= File.join(Ribose.root, "spec/fixtures/sample.png")
79
+ end
80
+ end
@@ -0,0 +1,109 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe "Space Invitation" do
4
+ describe "list" do
5
+ it "retrieves the list of space invitations" do
6
+ command = %w(invitation list)
7
+
8
+ stub_ribose_space_invitation_lis_api
9
+ output = capture_stdout { Ribose::CLI.start(command) }
10
+
11
+ expect(output).to match(/ID | Inviter | Type/)
12
+ expect(output).to match(/Doe | Invitation::ToSpace | The CLI Space/)
13
+ end
14
+ end
15
+
16
+ describe "add" do
17
+ it "sends a space invitation to a member" do
18
+ command = %W(
19
+ invitation add
20
+ --space-id #{invitation.space_id}
21
+ --user-id #{invitation.id1}:#{invitation.role}
22
+ --email #{invitation.email1}:0 #{invitation.email2}:1
23
+ --message #{invitation.message}
24
+ )
25
+
26
+ stub_ribose_space_invitation_mass_create(
27
+ invitation.space_id, build_attr_in_stub_format(invitation)
28
+ )
29
+
30
+ output = capture_stdout { Ribose::CLI.start(command) }
31
+
32
+ expect(output).to match(/Invitation has been sent successfully!/)
33
+ end
34
+ end
35
+
36
+ describe "update" do
37
+ it "updates the details for an invitation" do
38
+ command = %w(invitation update --invitation-id 2468 --role-id 246)
39
+ stub_ribose_space_invitation_update_api(2468, role_id: "246")
40
+
41
+ output = capture_stdout { Ribose::CLI.start(command) }
42
+
43
+ expect(output).to match(/Space invitation has been updated!/)
44
+ end
45
+ end
46
+
47
+ describe "accept" do
48
+ it "allows us to accept a space invitation" do
49
+ command = %w(invitation accept --invitation-id 2468)
50
+
51
+ stub_ribose_space_invitation_update_api(2468, state: 1)
52
+ output = capture_stdout { Ribose::CLI.start(command) }
53
+
54
+ expect(output).to match(/Space invitation has been accepted!/)
55
+ end
56
+ end
57
+
58
+ describe "reject" do
59
+ it "allows us to reject a space invitation" do
60
+ command = %w(invitation reject --invitation-id 2468)
61
+
62
+ stub_ribose_space_invitation_update_api(2468, state: 2)
63
+ output = capture_stdout { Ribose::CLI.start(command) }
64
+
65
+ expect(output).to match(/Space invitation has been rejected!/)
66
+ end
67
+ end
68
+
69
+ describe "remove" do
70
+ it "removes a space invitation" do
71
+ command = %w(invitation remove --invitation-id 2468)
72
+
73
+ stub_ribose_space_invitation_cancel_api(2468)
74
+ output = capture_stdout { Ribose::CLI.start(command) }
75
+
76
+ expect(output).to match(/Space invitation has been removed!/)
77
+ end
78
+ end
79
+
80
+ def invitation
81
+ @invitation ||= OpenStruct.new(
82
+ id1: "123456",
83
+ id2: "567890",
84
+ role: "123456",
85
+ space_id: "123456789",
86
+ email1: "invitee-one@example.com",
87
+ email2: "invitee-two@example.com",
88
+ message: "Your invitation message",
89
+ )
90
+ end
91
+
92
+ # This might look compact, but the only purpose for this is to prepare
93
+ # the attributes / sequence with the one webmock would be epxecting to
94
+ # stub the api request successfully.
95
+ #
96
+ def build_attr_in_stub_format(invitation)
97
+ {
98
+ body: invitation.message,
99
+ emails: [invitation.email1, invitation.email2],
100
+ user_ids: [invitation.id1],
101
+ role_ids: {
102
+ "#{invitation.email1}": "0",
103
+ "#{invitation.email2}": "1",
104
+ "#{invitation.id1}": invitation.role,
105
+ },
106
+ space_id: invitation.space_id,
107
+ }
108
+ end
109
+ end
@@ -0,0 +1,73 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe "Join Space Request" do
4
+ describe "list" do
5
+ it "retrieves the list of join space requests" do
6
+ command = %w(join-space list)
7
+
8
+ stub_ribose_join_space_request_list_api
9
+ output = capture_stdout { Ribose::CLI.start(command) }
10
+
11
+ expect(output).to match(/| ID | Inviter | Type/)
12
+ expect(output).to match(/| 27743 | Jennie Doe | Invitation::ToSpace/)
13
+ end
14
+ end
15
+
16
+ describe "show" do
17
+ it "retrieves the details for a join reqeust" do
18
+ command = %w(join-space show --request-id 2468)
19
+
20
+ stub_ribose_join_space_request_fetch_api(2468)
21
+ output = capture_stdout { Ribose::CLI.start(command) }
22
+
23
+ expect(output).to match(/state | 0/)
24
+ expect(output).to match(/id | 123456789/)
25
+ expect(output).to match(/type | Invitation::ToSpace/)
26
+ end
27
+ end
28
+
29
+ describe "add" do
30
+ it "creates a new join space request" do
31
+ command = %w(join-space add --space-id 1234)
32
+
33
+ stub_join_space_request_api_call(1234)
34
+ output = capture_stdout { Ribose::CLI.start(command) }
35
+
36
+ expect(output).to match(/Join space request has been sent successfully!/)
37
+ end
38
+ end
39
+
40
+ describe "accept" do
41
+ it "allows a user to accept a join space request" do
42
+ command = %w(join-space accept --request-id 2468)
43
+
44
+ stub_ribose_join_space_request_update(2468, state: 1)
45
+ output = capture_stdout { Ribose::CLI.start(command) }
46
+
47
+ expect(output).to match(/Join space request has been accepted!/)
48
+ end
49
+ end
50
+
51
+ describe "reject" do
52
+ it "allows a user to reject a join space request" do
53
+ command = %w(join-space reject --request-id 2468)
54
+
55
+ stub_ribose_join_space_request_update(2468, state: 2)
56
+ output = capture_stdout { Ribose::CLI.start(command) }
57
+
58
+ expect(output).to match(/Join space request has been rejected!/)
59
+ end
60
+ end
61
+
62
+ # This prepares the request body to match with wbmock's expected
63
+ # one to successfully stub `POST /invitations/join_space_request`
64
+ #
65
+ def stub_join_space_request_api_call(space_id, state: 0, body: "")
66
+ stub_ribose_join_space_request_create_api(
67
+ state: state,
68
+ body: body,
69
+ type: "Invitation::JoinSpaceRequest",
70
+ space_id: space_id.to_s,
71
+ )
72
+ end
73
+ end
@@ -0,0 +1,87 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe "Space Member" do
4
+ describe "list" do
5
+ it "retrieves the list of space members" do
6
+ command = %w(member list --space-id 123456)
7
+
8
+ stub_ribose_space_member_list(123456)
9
+ output = capture_stdout { Ribose::CLI.start(command) }
10
+
11
+ expect(output).to match(/| Name | Role Name/)
12
+ expect(output).to match(/8332-fcdaecb13e34 | John Doe | Administrator/)
13
+ end
14
+ end
15
+
16
+ describe "add" do
17
+ it "adds a new member to a space" do
18
+ command = %W(
19
+ member add
20
+ --space-id #{invitation.space_id}
21
+ --user-id #{invitation.id1}:#{invitation.role}
22
+ --email #{invitation.email1}:0 #{invitation.email2}:1
23
+ --message #{invitation.message}
24
+ )
25
+
26
+ stub_ribose_space_invitation_mass_create(
27
+ invitation.space_id, build_attr_in_stub_format(invitation)
28
+ )
29
+
30
+ output = capture_stdout { Ribose::CLI.start(command) }
31
+
32
+ expect(output).to match(/Invitation has been sent successfully!/)
33
+ end
34
+ end
35
+
36
+ describe "update" do
37
+ it "updates an existing member details" do
38
+ command = %w(member update --role-id 135 --member-id 246 --space-id 1234)
39
+
40
+ stub_ribose_member_role_assign(1234, 246, "135")
41
+ output = capture_stdout { Ribose::CLI.start(command) }
42
+
43
+ expect(output).to match(/Member has been updated with new role!/)
44
+ end
45
+ end
46
+
47
+ describe "remove" do
48
+ it "removes an existing space member" do
49
+ command = %w(member remove --member-id 246 --space-id 1234)
50
+
51
+ stub_ribose_space_member_delete_api(1234, 246)
52
+ output = capture_stdout { Ribose::CLI.start(command) }
53
+
54
+ expect(output).to match(/The member has been removed from this space/)
55
+ end
56
+ end
57
+
58
+ def invitation
59
+ @invitation ||= OpenStruct.new(
60
+ id1: "123456",
61
+ id2: "567890",
62
+ role: "123456",
63
+ space_id: "123456789",
64
+ email1: "invitee-one@example.com",
65
+ email2: "invitee-two@example.com",
66
+ message: "Your invitation message",
67
+ )
68
+ end
69
+
70
+ # This might look compact, but the only purpose for this is to prepare
71
+ # the attributes / sequence with the one webmock would be epxecting to
72
+ # stub the api request successfully.
73
+ #
74
+ def build_attr_in_stub_format(invitation)
75
+ {
76
+ body: invitation.message,
77
+ emails: [invitation.email1, invitation.email2],
78
+ user_ids: [invitation.id1],
79
+ role_ids: {
80
+ "#{invitation.email1}": "0",
81
+ "#{invitation.email2}": "1",
82
+ "#{invitation.id1}": invitation.role,
83
+ },
84
+ space_id: invitation.space_id,
85
+ }
86
+ end
87
+ end
@@ -0,0 +1,67 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe "Conversation Messages" do
4
+ describe "listing messages" do
5
+ it "retrieves the list of messages" do
6
+ command = %w(message list -s 123456789 -c 123456789 --format json)
7
+
8
+ stub_ribose_message_list(123456789, 123456789)
9
+ output = capture_stdout { Ribose::CLI.start(command) }
10
+
11
+ expect(output).to match(/"contents":"Welcome to Ribose Space"/)
12
+ expect(output).to match(/"id":"eec38935-3070-4949-b217-878aa07db699"/)
13
+ end
14
+ end
15
+
16
+ describe "Adding new message" do
17
+ it "allows us to add message to a conversation" do
18
+ command = %W(
19
+ message add
20
+ --space-id 123
21
+ --message-body #{message.contents}
22
+ --conversation-id #{message.conversation_id}
23
+ )
24
+
25
+ stub_ribose_message_create(123, message: message.to_h)
26
+ output = capture_stdout { Ribose::CLI.start(command) }
27
+
28
+ expect(output).to match(/Messge has been posted/)
29
+ expect(output).to match(/Id: 9af4df9f-2a30-4d66-a925-efaf45057ae4/)
30
+ end
31
+ end
32
+
33
+ describe "Updating a message" do
34
+ it "allows us to update a existing message" do
35
+ command = %W(
36
+ message update
37
+ --space-id 123
38
+ --message-id 456789
39
+ --message-body #{message.contents}
40
+ --conversation-id #{message.conversation_id}
41
+ )
42
+
43
+ stub_ribose_message_update(123, 456789, message: message.to_h)
44
+ output = capture_stdout { Ribose::CLI.start(command) }
45
+
46
+ expect(output).to match(/Messge has been updated!/)
47
+ end
48
+ end
49
+
50
+ describe "Remove a message" do
51
+ it "allows us to remove an existing message" do
52
+ command = %w(message remove -s 123 -c 456 --message-id 123456)
53
+
54
+ stub_ribose_message_remove(123, 123456, 456)
55
+ output = capture_stdout { Ribose::CLI.start(command) }
56
+
57
+ expect(output).to match(/The message has been removed!/)
58
+ end
59
+ end
60
+
61
+ def message
62
+ @message ||= OpenStruct.new(
63
+ contents: "Welcome to Ribose!",
64
+ conversation_id: "987654321",
65
+ )
66
+ end
67
+ end
@@ -0,0 +1,61 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe "Space Note" do
4
+ describe "listing notes" do
5
+ it "retrieves the list of notes" do
6
+ command = %w(note list --space-id 123456789)
7
+
8
+ stub_ribose_wiki_list_api(123_456_789)
9
+ output = capture_stdout { Ribose::CLI.start(command) }
10
+
11
+ expect(output).to match(/Wiki Page One/)
12
+ expect(output).to match(/Wiki Page Two/)
13
+ end
14
+ end
15
+
16
+ describe "retrieve a note" do
17
+ it "retrieves the details for a note" do
18
+ command = %w(note show --space-id 123456 --note-id 789012)
19
+
20
+ stub_ribose_wiki_fetch_api(123456, 789012)
21
+ output = capture_stdout { Ribose::CLI.start(command) }
22
+
23
+ expect(output).to match(/revision | 23/)
24
+ expect(output).to match(/name | Wiki Page One/)
25
+ expect(output).to match(/address | wiki-page-one/)
26
+ end
27
+ end
28
+
29
+ describe "adding a new note" do
30
+ it "adds a new note to a specific space" do
31
+ command = %w(note add -s 123456 --title Home --tag-list hello)
32
+ stub_ribose_wiki_create_api(123_456, tag_list: "hello", name: "Home")
33
+
34
+ output = capture_stdout { Ribose::CLI.start(command) }
35
+
36
+ expect(output).to match(/Note has been posted added! Id:/)
37
+ end
38
+ end
39
+
40
+ describe "update a note" do
41
+ it "updates the details for an existing note" do
42
+ command = %w(note update -s 1234 -n 5678 --title Sample)
43
+ stub_ribose_wiki_update_api(1234, 5678, name: "Sample", tag_list: "")
44
+
45
+ output = capture_stdout { Ribose::CLI.start(command) }
46
+
47
+ expect(output).to match(/Your space note has been updated!/)
48
+ end
49
+ end
50
+
51
+ describe "remove a note" do
52
+ it "removes a note from a specific space" do
53
+ command = %w(note remove -s 123456789 --note-id 789123456)
54
+
55
+ stub_ribose_wiki_delete_api(123456789, 789123456)
56
+ output = capture_stdout { Ribose::CLI.start(command) }
57
+
58
+ expect(output).to match(/The note has been removed!/)
59
+ end
60
+ end
61
+ end