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.
Files changed (40) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/test.yml +27 -0
  3. data/.gitignore +1 -0
  4. data/.rubocop.yml +9 -1075
  5. data/Gemfile +3 -0
  6. data/README.md +315 -7
  7. data/bin/console +2 -5
  8. data/bin/ribose +22 -0
  9. data/lib/ribose/cli/auth.rb +10 -0
  10. data/lib/ribose/cli/command.rb +60 -0
  11. data/lib/ribose/cli/commands/base.rb +80 -0
  12. data/lib/ribose/cli/commands/conversation.rb +114 -0
  13. data/lib/ribose/cli/commands/file.rb +96 -0
  14. data/lib/ribose/cli/commands/invitation.rb +81 -0
  15. data/lib/ribose/cli/commands/join_space.rb +78 -0
  16. data/lib/ribose/cli/commands/member.rb +81 -0
  17. data/lib/ribose/cli/commands/message.rb +98 -0
  18. data/lib/ribose/cli/commands/note.rb +98 -0
  19. data/lib/ribose/cli/commands/space.rb +86 -0
  20. data/lib/ribose/cli/rcfile.rb +67 -0
  21. data/lib/ribose/cli/util.rb +22 -0
  22. data/lib/ribose/cli/version.rb +2 -2
  23. data/lib/ribose/cli.rb +21 -2
  24. data/ribose-cli.gemspec +11 -3
  25. data/spec/acceptance/config_spec.rb +17 -0
  26. data/spec/acceptance/conversation_spec.rb +90 -0
  27. data/spec/acceptance/file_spec.rb +80 -0
  28. data/spec/acceptance/invitation_spec.rb +109 -0
  29. data/spec/acceptance/join_space_spec.rb +73 -0
  30. data/spec/acceptance/member_spec.rb +87 -0
  31. data/spec/acceptance/message_spec.rb +67 -0
  32. data/spec/acceptance/note_spec.rb +61 -0
  33. data/spec/acceptance/space_spec.rb +112 -0
  34. data/spec/fixtures/.riboserc +4 -0
  35. data/spec/ribose/cli/rcfile_spec.rb +27 -0
  36. data/spec/spec_helper.rb +15 -1
  37. data/spec/support/console_helper.rb +29 -0
  38. metadata +113 -18
  39. data/.travis.yml +0 -5
  40. data/spec/ribose/cli_spec.rb +0 -4
data/Gemfile CHANGED
@@ -2,3 +2,6 @@ source "https://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in ribose-cli.gemspec
4
4
  gemspec
5
+
6
+ # Temporarily use the development version
7
+ gem "ribose", git: "https://github.com/riboseinc/ribose-ruby", branch: "main"
data/README.md CHANGED
@@ -1,28 +1,336 @@
1
- # Ribose::Cli
1
+ # Ribose CLI
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/ribose/cli`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ [![Build Status](https://github.com/riboseinc/ribose-cli/actions/workflows/test.yml/badge.svg)](https://github.com/riboseinc/ribose-cli/actions/workflows/test.yml)
4
+ [![Code
5
+ Climate](https://codeclimate.com/github/riboseinc/ribose-cli/badges/gpa.svg)](https://codeclimate.com/github/riboseinc/ribose-cli)
4
6
 
5
- TODO: Delete this and the text above, and describe your gem
7
+ The command line interface to the Ribose API.
6
8
 
7
9
  ## Installation
8
10
 
9
11
  Add this line to your application's Gemfile:
10
12
 
11
13
  ```ruby
12
- gem 'ribose-cli'
14
+ gem "ribose-cli"
13
15
  ```
14
16
 
15
17
  And then execute:
16
18
 
17
- $ bundle
19
+ ```sh
20
+ $ bundle install
21
+ ```
18
22
 
19
23
  Or install it yourself as:
20
24
 
21
- $ gem install ribose-cli
25
+ ```sh
26
+ $ gem install ribose-cli
27
+ ```
22
28
 
23
29
  ## Usage
24
30
 
25
- TODO: Write usage instructions here
31
+ ### Configure
32
+
33
+ To start with, we kept it pretty simple, install this gem & then configure your
34
+ API Token and email using the following interface, This will store your Ribose
35
+ configuration as `.riboserc` in the home directory.
36
+
37
+ ```sh
38
+ ribose config --password='YOUR_API_PASSWORD' --email='youremail@example.com'
39
+ ```
40
+
41
+ ### Spaces
42
+
43
+ The `space` command retrieve space related resources, please use the `help`
44
+ command to see what's sub-commands are available.
45
+
46
+ ```sh
47
+ ribose help space
48
+ ```
49
+
50
+ #### Listing spaces
51
+
52
+ To list out the spaces, please use the `list` command, by default it will print
53
+ out the basic information in tabular format.
54
+
55
+ ```sh
56
+ ribose space list
57
+ ```
58
+
59
+ This interface also has support `json` format, if we want the output to be in
60
+ `json` then we can use the following
61
+
62
+ ```sh
63
+ ribose space list --format json
64
+ ```
65
+
66
+ #### Show a space details
67
+
68
+ ```sh
69
+ ribose space show --space-id 123456789
70
+ ```
71
+
72
+ #### Create a new space
73
+
74
+ To create a new user space we can use the following interface
75
+
76
+ ```sh
77
+ ribose space add --name "Space name" --access "open" --category-id 12 \
78
+ --description "Space description"
79
+ ```
80
+
81
+ #### Update a space
82
+
83
+ ```sh
84
+ ribose space update --space-id 123456 --name "New Space Name"
85
+ ```
86
+
87
+ #### Remove an existing space
88
+
89
+ ```sh
90
+ ribose space remove --space-id 123456789 --confirmation 123456789
91
+ ```
92
+
93
+ ### Members
94
+
95
+ #### List space members
96
+
97
+ ```sh
98
+ ribose member list --space-id space_uuid
99
+ ```
100
+
101
+ #### Add a new space member
102
+
103
+ ```sh
104
+ ribose member add \
105
+ --space-id space_uuid \
106
+ --user-id=user-one-uuid:role_one_id user-two-uuid:role_two_id \
107
+ --email=email-one@example.com:role_one_id email@example.com:role_two_id \
108
+ --message="Your invitation messages to the invitees"
109
+ ```
110
+
111
+ #### Update an existing member
112
+
113
+ ```sh
114
+ ribose member update --role-id 135 --member-id 246 --space-id 1234
115
+ ```
116
+
117
+ #### Remove a space member
118
+
119
+ ```sh
120
+ ribose member remove --member-id 246 --space-id 1234
121
+ ```
122
+
123
+ ### Space Invitation
124
+
125
+ #### List Space Invitation
126
+
127
+ ```sh
128
+ ribose invitation list [--query=key:value]
129
+ ```
130
+
131
+ #### Send out space invitation
132
+
133
+ ```sh
134
+ ribose invitation add \
135
+ --space-id space_uuid \
136
+ --user-id=user-one-uuid:role_one_id user-two-uuid:role_two_id \
137
+ --email=email-one@example.com:role_one_id email@example.com:role_two_id \
138
+ --message="Your invitation messages to the invitees"
139
+ ```
140
+
141
+ #### Update a space invitation
142
+
143
+ ```sh
144
+ ribose invitation update --invitation-id 2468 --role-id 246
145
+ ```
146
+
147
+ #### Accept a space invitation
148
+
149
+ ```sh
150
+ ribose invitation accept --invitation-id 2468
151
+ ```
152
+
153
+ #### Reject a space invitation
154
+
155
+ ```sh
156
+ ribose invitation reject --invitation-id 2468
157
+ ```
158
+
159
+ #### Remove a space invitation
160
+
161
+ ```sh
162
+ ribose invitation remove --invitation-id 2468
163
+ ```
164
+
165
+ ### Join Space Request
166
+
167
+ #### List join space requests
168
+
169
+ ```sh
170
+ ribose join-space list [--query=space-id:2468]
171
+ ```
172
+
173
+ #### Fetch a join space request
174
+
175
+ ```sh
176
+ ribose join-space show --request-id 2468
177
+ ```
178
+
179
+ #### Add join space request
180
+
181
+ ```sh
182
+ ribose join-space add --space-id 1234 [--message "My request message"]
183
+ ```
184
+
185
+ #### Accept a join space request
186
+
187
+ ```sh
188
+ ribose join-space accept --request-id 2468
189
+ ```
190
+
191
+ #### Reject a join space requests
192
+
193
+ ```sh
194
+ ribose join-space reject --request-id 2468
195
+ ```
196
+
197
+ ### Note
198
+
199
+ #### Listing space notes
200
+
201
+ ```sh
202
+ ribose note list --space-id space_uuid --format json
203
+ ```
204
+
205
+ ### Show a space note
206
+
207
+ ```sh
208
+ ribose note show --note-id 123456 --space-id 78901
209
+ ```
210
+
211
+ #### Create a new note
212
+
213
+ ```sh
214
+ ribose note add --space-id space_uuid --title "Name of the note"
215
+ ```
216
+
217
+ #### Update an existing note
218
+
219
+ ```sh
220
+ ribose note update --space-id 1234 --note-id 5678 --title "Name of the note"
221
+ ```
222
+
223
+ #### Remove a note
224
+
225
+ ```sh
226
+ ribose note remove --space-id space_uuid --note-id note_uuid
227
+ ```
228
+
229
+ ### Files
230
+
231
+ #### Listing files
232
+
233
+ Ribose space may contain multiple files, and if we want to retrieve the list of
234
+ the files of any space then we can use to following interface.
235
+
236
+ ```sh
237
+ ribose file list --space-id 123456
238
+ ```
239
+
240
+ The above interface will retrieve the basic details in tabular format, but it
241
+ also support additional `format` option, acceptable option: `json`.
242
+
243
+ #### Fetch a file details
244
+
245
+ ```sh
246
+ ribose file show --file-id 5678 --space-id 1234 [--format json]
247
+ ```
248
+
249
+ #### Add a new file
250
+
251
+ Ribose CLI allows us to upload a file in a user space, and to upload a new file
252
+ we can use the following interface.
253
+
254
+ ```sh
255
+ ribose file add full_path_the_file.ext --space-id space_uuid **other_options
256
+ ```
257
+
258
+ #### Update a space file
259
+
260
+ ```sh
261
+ ribose file update [--file-name "new filename"] \
262
+ [--description "New description"] \
263
+ [--tags "tag 1, tag 2, tag 3"] --file-id 5678 --space-id 1234
264
+ ```
265
+
266
+ #### Remove a space file
267
+
268
+ ```sh
269
+ ribose file remove --file-id 5678 --space-id 1234
270
+ ```
271
+
272
+ ### Conversations
273
+
274
+ #### Listing conversations
275
+
276
+ ```sh
277
+ ribose conversation list --space-id 123456789
278
+ ```
279
+
280
+ #### Show a conversation details
281
+
282
+ ```sh
283
+ ribose conversation show --space-id 123456789 --conversation-id 67890
284
+ ```
285
+
286
+ #### Create A New Conversation
287
+
288
+ ```sh
289
+ ribose conversation add --space-id 123456789 --title "Conversation Title" \
290
+ --tags "sample, conversation"
291
+ ```
292
+
293
+ #### Update a conversation
294
+
295
+ ```sh
296
+ conversation update --conversation-id 5678 --space-id 123456789 --title \
297
+ "Conversation Title" --tags "sample, conversation"
298
+ ```
299
+
300
+ #### Remove A Conversation
301
+
302
+ ```sh
303
+ ribose conversation remove --space-id 1234 --conversation-id 5678
304
+ ```
305
+
306
+ ### Message
307
+
308
+ #### Listing conversation messages
309
+
310
+ ```sh
311
+ ribose message list --space-id 12345 --conversation-id 56789
312
+ ```
313
+
314
+ #### Add a new message to conversation
315
+
316
+ ```sh
317
+ ribose message add --space-id 12345 --conversation-id 56789 \
318
+ --message-body "Welcome to Ribose Space"
319
+ ```
320
+
321
+ #### Update an existing message
322
+
323
+
324
+ ```sh
325
+ ribose message update --message-id 123456 --space-id 12345 \
326
+ --conversation-id 56789 --message-body "Welcome to Ribose Space"
327
+ ```
328
+
329
+ #### Remove an existing message
330
+
331
+ ```sh
332
+ ribose message remove --message-id 1234 --space-id 12345 --conversation-id 456
333
+ ```
26
334
 
27
335
  ## Development
28
336
 
data/bin/console CHANGED
@@ -7,8 +7,5 @@ require "ribose/cli"
7
7
  # with your gem easier. You can also use a different console, if you like.
8
8
 
9
9
  # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require "pry"
11
- # Pry.start
12
-
13
- require "irb"
14
- IRB.start(__FILE__)
10
+ require "pry"
11
+ Pry.start
data/bin/ribose ADDED
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+
4
+ # resolve bin path, ignoring symlinks
5
+ require "pathname"
6
+ bin_file = Pathname.new(__FILE__).realpath
7
+
8
+ # add self to libpath
9
+ $:.unshift File.expand_path("../../lib", bin_file)
10
+
11
+ # Fixes https://github.com/rubygems/rubygems/issues/1420
12
+ require "rubygems/specification"
13
+
14
+ class Gem::Specification
15
+ def this; self; end
16
+ end
17
+
18
+ # start up the CLI
19
+ require "bundler/setup"
20
+ require "ribose/cli"
21
+
22
+ Ribose::CLI.start(ARGV)
@@ -0,0 +1,10 @@
1
+ require "ribose"
2
+ require "ribose/cli/rcfile"
3
+
4
+ unless Ribose.configuration.user_password
5
+ Ribose.configure do |config|
6
+ config.api_host = Ribose::CLI::RCFile.api_host
7
+ config.user_email = Ribose::CLI::RCFile.user_email
8
+ config.user_password = Ribose::CLI::RCFile.user_password
9
+ end
10
+ end
@@ -0,0 +1,60 @@
1
+ require "ribose/cli/rcfile"
2
+ require "ribose/cli/commands/base"
3
+ require "ribose/cli/commands/space"
4
+ require "ribose/cli/commands/file"
5
+ require "ribose/cli/commands/conversation"
6
+ require "ribose/cli/commands/message"
7
+ require "ribose/cli/commands/note"
8
+ require "ribose/cli/commands/member"
9
+ require "ribose/cli/commands/invitation"
10
+ require "ribose/cli/commands/join_space"
11
+
12
+ module Ribose
13
+ module CLI
14
+ class Command < Thor
15
+ desc "space", "List, Add or Remove User Space"
16
+ subcommand :space, Ribose::CLI::Commands::Space
17
+
18
+ desc "member", "List, Add or Remove Space Member"
19
+ subcommand :member, Ribose::CLI::Commands::Member
20
+
21
+ desc "note", "List, Add or Remove Space Note"
22
+ subcommand :note, Ribose::CLI::Commands::Note
23
+
24
+ desc "file", "List, Add or Remove Files"
25
+ subcommand :file, Ribose::CLI::Commands::File
26
+
27
+ desc "conversation", "List, Add or Remove Conversation"
28
+ subcommand :conversation, Ribose::CLI::Commands::Conversation
29
+
30
+ desc "message", "List, Add or Remove Message"
31
+ subcommand :message, Ribose::CLI::Commands::Message
32
+
33
+ desc "invitation", "Manage Space Invitations"
34
+ subcommand :invitation, Ribose::CLI::Commands::Invitation
35
+
36
+ desc "join-space", "Manage Join Space Request"
37
+ subcommand :join_space, Ribose::CLI::Commands::JoinSpace
38
+
39
+ desc "config", "Configure API Key and User Email"
40
+ option :token, required: false, desc: "Your API Token for Ribose"
41
+ option :email, required: true, desc: "Your email address for Ribose"
42
+ option :password, required: true, desc: "Your API password for Ribose"
43
+ option :api_host, required: true, desc: "API host, eg: www.ribose.com"
44
+
45
+ def config
46
+ Ribose::CLI::RCFile.set(
47
+ token: options[:token],
48
+ email: options[:email],
49
+ password: options[:password],
50
+ api_host: options[:api_host],
51
+ )
52
+ end
53
+
54
+ desc "version", "The current active version"
55
+ def version
56
+ say(Ribose::CLI::VERSION)
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,80 @@
1
+ module Ribose
2
+ module CLI
3
+ module Commands
4
+ class Base < Thor
5
+ private
6
+
7
+ # Table Headers
8
+ #
9
+ # Listing resources in table view will invoke this method to
10
+ # retrieve the list of headers, please override this in the
11
+ # sub-class and fill it in with actual fields name.
12
+ #
13
+ def table_headers
14
+ raise NotImplementedError
15
+ end
16
+
17
+ # Table Rows
18
+ #
19
+ # List resources in table view will invoke this method to build
20
+ # each of the individual resource row, please override this with
21
+ # an array that includes the value for headers.
22
+ #
23
+ def table_rows
24
+ raise NotImplementedError
25
+ end
26
+
27
+ # Table field names
28
+ #
29
+ # Displaying a single resource in table view will invoke this
30
+ # method to figure out field name and values for each of the
31
+ # row in table, please override this with proper attributes
32
+ #
33
+ def table_field_names
34
+ raise NotImplementedError
35
+ end
36
+
37
+ def build_output(resources, options)
38
+ json_view(resources, options) || table_view(resources)
39
+ end
40
+
41
+ def build_resource_output(resource, options)
42
+ resource_as_json(resource, options) || resource_as_table(resource)
43
+ end
44
+
45
+ def json_view(resources, options)
46
+ if options[:format] == "json"
47
+ resources.map(&:to_h).to_json
48
+ end
49
+ end
50
+
51
+ def resource_as_json(resource, options)
52
+ if options[:format] == "json"
53
+ resource.to_h.to_json
54
+ end
55
+ end
56
+
57
+ def table_view(resources)
58
+ Ribose::CLI::Util.list(
59
+ headings: table_headers, rows: table_rows(resources),
60
+ )
61
+ end
62
+
63
+ def resource_as_table(resource)
64
+ Ribose::CLI::Util.list(
65
+ headings: ["Field", "Value"],
66
+ rows: table_field_names.map { |key| [key, resource[key.to_s]] },
67
+ )
68
+ end
69
+
70
+ def symbolize_keys(options_hash)
71
+ Hash.new.tap do |hash|
72
+ options_hash.each_key do |key|
73
+ hash[(key.to_sym rescue key) || key] = options_hash.fetch(key)
74
+ end
75
+ end
76
+ end
77
+ end
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,114 @@
1
+ module Ribose
2
+ module CLI
3
+ module Commands
4
+ class Conversation < Commands::Base
5
+ desc "list", "Listing A Space Conversations"
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_conversations, options))
11
+ end
12
+
13
+ desc "show", "Show the details for a conversation"
14
+ option :space_id, required: true, aliases: "-s", desc: "The Space UUID"
15
+ option :format, aliases: "-f", desc: "Output format, eg: json"
16
+
17
+ option(
18
+ :conversation_id,
19
+ required: true,
20
+ aliases: "-c",
21
+ desc: "The Conversation UUID",
22
+ )
23
+
24
+ def show
25
+ say(build_resource_output(conversation(options), options))
26
+ end
27
+
28
+ desc "add", "Add a new conversation to Space"
29
+ option :space_id, required: true, aliases: "-s", desc: "The Space UUID"
30
+ option :title, required: true, desc: "The title for the conversation"
31
+ option :tags, aliases: "-t", desc: "The tags for the conversation"
32
+
33
+ def add
34
+ conversation = create_conversation(options)
35
+ say("New Conversation created! Id: " + conversation.id)
36
+ end
37
+
38
+ desc "update", "Updae an existing conversation"
39
+ option :title, desc: "The title for the conversation"
40
+ option :tags, aliases: "-t", desc: "The tags for the conversation"
41
+ option :space_id, required: true, aliases: "-s", desc: "The Space UUID"
42
+ option(
43
+ :conversation_id,
44
+ required: true,
45
+ aliases: "-c",
46
+ desc: "The conversation UUID",
47
+ )
48
+
49
+ def update
50
+ update_conversation(symbolize_keys(options))
51
+ say("Your conversation has been updated!")
52
+ rescue Ribose::UnprocessableEntity
53
+ say("Something went wrong!, please check required attributes")
54
+ end
55
+
56
+ desc "remove", "Remove A Conversation from Space"
57
+ option :space_id, required: true, aliases: "-s", desc: "The Space UUID"
58
+ option :conversation_id, required: true, aliases: "-c"
59
+
60
+ def remove
61
+ remove_conversation(options)
62
+ say("The Conversation has been removed!")
63
+ rescue
64
+ say("Please provide a valid Conversation UUID")
65
+ end
66
+
67
+ private
68
+
69
+ def conversation(attributes)
70
+ @conversation ||= Ribose::Conversation.fetch(
71
+ attributes[:space_id], attributes[:conversation_id]
72
+ )
73
+ end
74
+
75
+ def list_conversations
76
+ @conversations ||= Ribose::Conversation.all(options[:space_id])
77
+ end
78
+
79
+ def create_conversation(options)
80
+ Ribose::Conversation.create(
81
+ options[:space_id], name: options[:title], tag_list: options[:tags]
82
+ )
83
+ end
84
+
85
+ def update_conversation(attributes)
86
+ Ribose::Conversation.update(
87
+ attributes.delete(:space_id),
88
+ attributes.delete(:conversation_id),
89
+ attributes,
90
+ )
91
+ end
92
+
93
+ def remove_conversation(options)
94
+ Ribose::Conversation.destroy(
95
+ space_id: options[:space_id],
96
+ conversation_id: options[:conversation_id],
97
+ )
98
+ end
99
+
100
+ def table_headers
101
+ ["ID", "Title"]
102
+ end
103
+
104
+ def table_field_names
105
+ %w(id space_id name number_of_messages allow_comment)
106
+ end
107
+
108
+ def table_rows(conversations)
109
+ conversations.map { |conv| [conv.id, conv.name] }
110
+ end
111
+ end
112
+ end
113
+ end
114
+ end