-
Notifications
You must be signed in to change notification settings - Fork 31
India and Richelle - Water #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
cf13667
5e8cfc9
af96987
fba233e
c3077ca
6392025
13c6c31
068e8d7
7e934e0
9eb1c83
d09c02d
fbfa3c9
3c904ff
7486479
b207eb4
8c2bb7a
8943a7a
376426a
e3a0142
089fea0
6f1ae30
03b62a7
5890086
faf2b63
41f1836
2b6472e
5b6bc2c
ea7c181
182a9a3
0d93bf5
17a9fc6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,3 +4,4 @@ | |
|
|
||
| # Ignore environemnt variables | ||
| .env | ||
| .idea/ | ||
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| require 'awesome_print' | ||
| require_relative 'recipient' | ||
|
|
||
| class Channel < Recipient | ||
| attr_reader :topic, :member_count | ||
|
|
||
| def initialize(slack_id, name, topic, member_count) | ||
| super(slack_id, name) | ||
| @topic = topic | ||
| @member_count = member_count | ||
| empty_topic | ||
| end | ||
|
|
||
| def self.list_all | ||
| base_url = "https://slack.com/api/conversations.list" | ||
|
|
||
| response = self.get(base_url) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good helper method |
||
|
|
||
| return response["channels"].map do |channel| | ||
| Channel.new(channel["id"], channel["name"], channel["topic"]["value"], channel["num_members"] ) | ||
| end | ||
| end | ||
|
|
||
| def details | ||
| return "This channel's id is: #{@slack_id}, the name is: #{@name}. This channel has #{@member_count} members and is about #{@topic}" | ||
| end | ||
|
|
||
| private | ||
| def empty_topic | ||
| if @topic == "" | ||
| @topic = "N/A" | ||
| end | ||
| end | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| class SlackApiError < StandardError; end | ||
|
|
||
| class Recipient | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great abstract class! 😍 |
||
| attr_reader :slack_id, :name | ||
|
|
||
| def initialize(slack_id, name) | ||
| @slack_id = slack_id | ||
| @name = name | ||
| end | ||
|
|
||
| def send_message(message) | ||
| url = "https://slack.com/api/chat.postMessage" | ||
|
|
||
| response = HTTParty.post(url, body: { | ||
| token: ENV["SLACK_TOKEN"], | ||
| text: message, | ||
| channel: @slack_id | ||
| } | ||
| ) | ||
| unless response.code == 200 && response.parsed_response["ok"] | ||
| raise SlackApiError, "Error when posting #{message} to #{@name}, error: #{response.parsed_response["error"]}" | ||
| end | ||
| return response.code == 200 && response.parsed_response["ok"] | ||
| end | ||
|
|
||
| def self.get(url) | ||
| response = HTTParty.get(url, query: { | ||
| token: ENV["SLACK_TOKEN"] | ||
| } | ||
| ) | ||
| unless response.code == 200 && response.parsed_response["ok"] | ||
| raise SlackApiError, "Error connecting to Slack API: #{response.code} - #{response.parsed_response["error"]} - url: #{url}, please try again later." | ||
| end | ||
| return response | ||
| end | ||
|
|
||
| def self.list_all | ||
| raise NotImplementedError | ||
| end | ||
|
|
||
| def self.details | ||
| raise NotImplementedError | ||
| end | ||
|
|
||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,75 @@ | ||
| #!/usr/bin/env ruby | ||
| require_relative 'workspace' | ||
| require_relative 'user' | ||
| require_relative 'channel' | ||
| require 'table_print' | ||
| require 'httparty' | ||
| require 'dotenv' | ||
| Dotenv.load | ||
|
|
||
| def print_options | ||
| puts "Your options are: \n1. List users \n2. List channels \n3. Select User \n4. Select Channel \n5. Details \n6. Send message \n7. Quit \n\nPlease enter the number of your choice: " | ||
| end | ||
|
|
||
| def main_select_user(workspace) | ||
| puts "Please enter the id or name of the user you seek:" | ||
| workspace.select_user(gets.chomp) | ||
| if workspace.selected.nil? | ||
| puts "User not found" | ||
| else | ||
| puts "User selected: #{workspace.selected.name}" | ||
| end | ||
| return workspace.selected | ||
| end | ||
|
|
||
| def main_select_channel(workspace) | ||
| puts "Please enter the id or name of the channel you seek:" | ||
| workspace.select_channel(gets.chomp) | ||
| if workspace.selected.nil? | ||
| puts "Channel not found" | ||
| else | ||
| puts "Channel selected: #{workspace.selected.name}" | ||
| end | ||
| return workspace.selected | ||
| end | ||
|
|
||
| def main | ||
| puts "Welcome to the Ada Slack CLI!" | ||
| workspace = Workspace.new | ||
| puts "There are #{workspace.channels.length} channels, and #{workspace.users.length} users." | ||
|
|
||
| print_options | ||
| choice = gets.chomp.downcase | ||
|
|
||
| # TODO project | ||
| until choice == "7" || choice == "quit" | ||
| case choice | ||
| when "1", "list users" | ||
| tp workspace.users, :name, :slack_id, :real_name | ||
| when "2", "list channels" | ||
| tp workspace.channels, :name, :slack_id, :topic, :member_count | ||
| when "3", "select user" | ||
| main_select_user(workspace) | ||
| when "4", "select channel" | ||
| main_select_channel(workspace) | ||
| when "5", "details" | ||
| workspace.selected.nil? ? (puts "No user or channel selected"): (puts workspace.show_details) | ||
| when "6", "send message" | ||
| if workspace.selected.nil? | ||
| puts "A valid user or channel has not been selected." | ||
| else | ||
| puts "Please enter message to post:" | ||
| message = gets.chomp | ||
| workspace.send_message(message) | ||
| end | ||
| else | ||
| puts "not a valid choice, please try again" | ||
| end | ||
| puts "" | ||
| print_options | ||
| choice = gets.chomp.downcase | ||
| end | ||
|
|
||
| puts "Thank you for using the Ada Slack CLI" | ||
| puts "Thank you for using India & Richelle's Ada Slack CLI" | ||
| end | ||
|
|
||
| main if __FILE__ == $PROGRAM_NAME |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| require 'awesome_print' | ||
| require_relative 'recipient' | ||
|
|
||
| class User < Recipient | ||
| attr_reader :real_name, :status_emoji, :status_text | ||
|
|
||
| def initialize(slack_id, name, real_name, status_text, status_emoji) | ||
| super(slack_id, name) | ||
| @real_name = real_name | ||
| @status_text = status_text | ||
| @status_emoji = status_emoji | ||
| empty_status | ||
| end | ||
|
|
||
| def self.list_all | ||
| base_url = "https://slack.com/api/users.list" | ||
|
|
||
| response = self.get(base_url) | ||
|
|
||
| return response["members"].map do |user| | ||
| User.new(user["id"], user["name"], user["profile"]["real_name"], user["profile"]["status_text"], user["profile"]["status_emoji"] ) | ||
| end | ||
| end | ||
|
|
||
| def details | ||
| return "This user's id is: #{@slack_id}, the username is: #{@name} and their real name is: #{@real_name}. They have a status emoji of: #{@status_emoji} and their status text is: #{@status_text}" | ||
| end | ||
|
|
||
| private | ||
| def empty_status | ||
| if @status_emoji == "" | ||
| @status_emoji = "N/A" | ||
| end | ||
|
|
||
| if @status_text == "" | ||
| @status_text = "N/A" | ||
| end | ||
| end | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| require_relative 'user' | ||
| require_relative 'channel' | ||
|
|
||
| class Workspace | ||
| attr_reader :users, :channels | ||
| attr_accessor :selected | ||
|
|
||
| def initialize | ||
| @users = User.list_all | ||
| @channels = Channel.list_all | ||
| @selected = nil | ||
| end | ||
|
|
||
| def select_user(input) | ||
| @selected = @users.find { |user| user.name == input } | ||
| if @selected | ||
| return @selected | ||
| else | ||
| @selected = @users.find { |user| user.slack_id == input } | ||
| end | ||
| return @selected | ||
| end | ||
|
Comment on lines
+14
to
+22
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Notice that select user and channel do the same thing, just to different arrays, can you make a helper method? |
||
|
|
||
| def select_channel(input) | ||
| @selected = @channels.find { |channel| channel.name == input } | ||
| if @selected | ||
| return @selected | ||
| else | ||
| @selected = @channels.find { |channel| channel.slack_id == input } | ||
| end | ||
| return @selected | ||
| end | ||
|
|
||
| def show_details | ||
| @selected.details | ||
| end | ||
|
|
||
| def send_message(message) | ||
| @selected.send_message(message) | ||
| end | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| require_relative 'test_helper' | ||
|
|
||
| describe "Channel class" do | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should also have tests for the attr_reader attributes for channels, and the constructor. |
||
| it "channel list all method" do | ||
|
|
||
| VCR.use_cassette("channel_instances") do | ||
|
|
||
| all_channels = Channel.list_all | ||
|
|
||
| expect(all_channels).must_be_instance_of Array | ||
|
|
||
| all_channels.each do |channel| | ||
| expect(channel).must_be_instance_of Channel | ||
| end | ||
| end | ||
| end | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| { | ||
| "result": { | ||
| "covered_percent": 100.0 | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "Unit Tests": { | ||
| "coverage": { | ||
| }, | ||
| "timestamp": 1602005599 | ||
| } | ||
| } |
Large diffs are not rendered by default.
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| <!DOCTYPE html> | ||
| <html xmlns='http://www.w3.org/1999/xhtml'> | ||
| <head> | ||
| <title>Code coverage for Test</title> | ||
| <meta http-equiv="content-type" content="text/html; charset=utf-8" /> | ||
| <script src='./assets/0.12.3/application.js' type='text/javascript'></script> | ||
| <link href='./assets/0.12.3/application.css' media='screen, projection, print' rel='stylesheet' type='text/css' /> | ||
| <link rel="shortcut icon" type="image/png" href="./assets/0.12.3/favicon_green.png" /> | ||
| <link rel="icon" type="image/png" href="./assets/0.12.3/favicon.png" /> | ||
| </head> | ||
|
|
||
| <body> | ||
| <div id="loading"> | ||
| <img src="./assets/0.12.3/loading.gif" alt="loading"/> | ||
| </div> | ||
| <div id="wrapper" class="hide"> | ||
| <div class="timestamp">Generated <abbr class="timeago" title="2020-10-06T10:33:19-07:00">2020-10-06T10:33:19-07:00</abbr></div> | ||
| <ul class="group_tabs"></ul> | ||
|
|
||
| <div id="content"> | ||
| <div class="file_list_container" id="AllFiles"> | ||
| <h2> | ||
| <span class="group_name">All Files</span> | ||
| (<span class="covered_percent"> | ||
| <span class="green"> | ||
| 100.0% | ||
| </span> | ||
|
|
||
| </span> | ||
| covered at | ||
| <span class="covered_strength"> | ||
| <span class="red"> | ||
| 0.0 | ||
| </span> | ||
| </span> hits/line | ||
| ) | ||
| </h2> | ||
|
|
||
| <a name="AllFiles"></a> | ||
|
|
||
| <div> | ||
| <b>0</b> files in total. | ||
| </div> | ||
|
|
||
| <div class="t-line-summary"> | ||
| <b>0</b> relevant lines, | ||
| <span class="green"><b>0</b> lines covered</span> and | ||
| <span class="red"><b>0</b> lines missed. </span> | ||
| (<span class="green"> | ||
| 100.0% | ||
| </span> | ||
| ) | ||
| </div> | ||
|
|
||
|
|
||
|
|
||
| <div class="file_list--responsive"> | ||
| <table class="file_list"> | ||
| <thead> | ||
| <tr> | ||
| <th>File</th> | ||
| <th class="cell--number">% covered</th> | ||
| <th class="cell--number">Lines</th> | ||
| <th class="cell--number">Relevant Lines</th> | ||
| <th class="cell--number">Lines covered</th> | ||
| <th class="cell--number">Lines missed</th> | ||
| <th class="cell--number">Avg. Hits / Line</th> | ||
|
|
||
| </tr> | ||
| </thead> | ||
| <tbody> | ||
|
|
||
| </tbody> | ||
| </table> | ||
| </div> | ||
| </div> | ||
|
|
||
|
|
||
|
|
||
| </div> | ||
|
|
||
| <div id="footer"> | ||
| Generated by <a href="https://github.com/simplecov-ruby/simplecov">simplecov</a> v0.19.0 | ||
| and simplecov-html v0.12.3<br/> | ||
| using Unit Tests | ||
| </div> | ||
|
|
||
| <div class="source_files"> | ||
|
|
||
| </div> | ||
| </div> | ||
| </body> | ||
| </html> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! However also please add coverage, it makes for a smaller PR.