forked from AdaGold/slack-cli
-
Notifications
You must be signed in to change notification settings - Fork 26
Branches - Caroline & Emily #15
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
Open
eaball35
wants to merge
37
commits into
Ada-C12:master
Choose a base branch
from
eaball35:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
b63e0a5
tested
stupendousC 31db231
Halfway thru reading API response methods
stupendousC 8a389c4
success w/ httparty.get, tested
stupendousC d1fb25b
able to initialize @all_users in new Workspace obj, tested
stupendousC 31c79ea
nothing really changed
stupendousC 0f610dd
testing making new workspae & @all_channels, :-|
stupendousC d2cd820
Done with User.new() and reading from API. Testing ok
stupendousC 8aa2913
halfway done w/ initialization...
stupendousC da75190
all files up
stupendousC 832b730
User.load_users and all existing code tested w/ 100% coverage
stupendousC ffabc94
everything works EXCEPT .get_ids and therefore .load_all. work in pr…
stupendousC 43485bc
Channel.load tested w/ 100% coverage
stupendousC 50a1cf5
can add User and Channel instances from API, tested w/ 100% coverage
stupendousC a716232
show_meu in progress
stupendousC f3e9a2a
Added menu option functionality
stupendousC c10d5c2
refactored menu options
stupendousC 7b0020d
passed w/ 100% coverage
stupendousC 6a2941d
fixed bugs, tested w/ 100% coverage
stupendousC f8e746b
fixed bugs with 100% test coverage
stupendousC 87ec16b
formatting, cleaned up
stupendousC 27aeaf5
Working on testing the codes, currently 66% coverage
stupendousC 4cd392e
user interface works so far. will add send_msg function later
stupendousC 7256b19
cleaned up formatting. Everything tested 100% coverage except for wor…
stupendousC 4986838
changed workspace.show_menu name to workspace.menu_choices_hash, for …
stupendousC a783fd3
fixed typo, fat fingers
stupendousC 8f0daf3
deleted print statements
stupendousC 5e3d391
Will raise SlackAPIError when appropriate. Tested w/ 100% coverage
stupendousC 07c5b0c
added send_message, tested
stupendousC 475c093
halfway thru menu_action testing
stupendousC 724f0cc
almost one w/ testing menu_action. ~80% coverage
stupendousC 88e0489
Everything tested w/ 100% coverage, yay
stupendousC 7ec0f06
fixed all typos. everything tested at 100% coverage, yay
stupendousC c9765da
Delete WT2.yml
stupendousC 3b51ad3
Delete WT3.yml
stupendousC ebaf37d
Delete WT4.yml
stupendousC 0919a0e
Delete WT_BOGUS_KEY.yml
stupendousC 29fa31b
Add files via upload
stupendousC File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| require_relative 'lib_helper.rb' | ||
| require_relative 'recipient' | ||
|
|
||
| class Channel < Recipient | ||
| attr_reader :topic, :member_count | ||
|
|
||
| def initialize(id:, name:, topic:, member_count:) | ||
| super(id: id, name: name) | ||
| @topic = topic | ||
| @member_count = member_count | ||
| end | ||
|
|
||
| def details | ||
| return {id: id, name: name, topic: topic , member_count: member_count} | ||
| end | ||
|
|
||
|
|
||
| def self.get | ||
| url = "https://slack.com/api/conversations.list" | ||
| params = { token: KEY } | ||
| response = super(url, params) | ||
| # sleep(0.25) | ||
| return response | ||
| end | ||
|
|
||
| def self.get_ids | ||
| response = (self.get)["channels"] | ||
| all_channel_ids = response.map do |channel_info| | ||
| channel_info["id"] | ||
| end | ||
| return all_channel_ids | ||
| end | ||
|
|
||
| def self.get_names | ||
| response = (self.get)["channels"] | ||
| all_channel_names = response.map do |channel_info| | ||
| channel_info["name"] | ||
| end | ||
| return all_channel_names | ||
| end | ||
|
|
||
| def self.get_topics | ||
| response = (self.get)["channels"] | ||
| all_topics = response.map do |channel_info| | ||
| channel_info["topic"]["value"] | ||
| end | ||
| return all_topics | ||
| end | ||
|
|
||
| def self.get_member_counts | ||
| response = (self.get)["channels"] | ||
| member_counts = response.map do |channel_info| | ||
| channel_info["num_members"] | ||
| end | ||
| return member_counts | ||
| end | ||
|
|
||
| def self.load_all | ||
| names = self.get_names | ||
| ids = self.get_ids | ||
| member_counts = self.get_member_counts | ||
| topics = self.get_topics | ||
| all_channels = [] | ||
|
|
||
| ids.length.times do |index| | ||
| new_channel = Channel.new(name: names[index], id: ids[index], member_count:member_counts[index], topic:topics[index]) | ||
| all_channels << new_channel | ||
| end | ||
|
|
||
| return all_channels | ||
| end | ||
|
|
||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| require 'httparty' | ||
| require 'awesome_print' | ||
| require 'dotenv' | ||
| require 'terminal-table' | ||
|
|
||
|
|
||
| Dotenv.load | ||
|
|
||
|
|
||
| KEY = ENV["SLACK_KEY"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| require_relative 'lib_helper.rb' | ||
|
|
||
| class Recipient | ||
|
|
||
| attr_reader :id, :name | ||
|
|
||
| def initialize(id:, name:) | ||
| @id = id | ||
| @name = name | ||
| end | ||
|
|
||
| def self.get(url, params) | ||
| response = HTTParty.get(url, query: params) | ||
|
|
||
| if response["ok"] == true | ||
| return response | ||
| else | ||
| raise SlackAPIError, "API request failed!" | ||
| end | ||
| end | ||
|
|
||
| def details | ||
| raise NotImplementedError, "Do this either User or Channel" | ||
| end | ||
|
|
||
| def self.load_all | ||
| raise NotImplementedError, "Do this either User or Channel" | ||
| end | ||
|
|
||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,42 @@ | ||
| #!/usr/bin/env ruby | ||
| require 'awesome_print' | ||
| require 'httparty' | ||
| require 'dotenv' | ||
| Dotenv.load | ||
|
|
||
| def main | ||
| puts "Welcome to the Ada Slack CLI!" | ||
| require_relative 'lib_helper.rb' | ||
| require_relative 'recipient.rb' | ||
| require_relative 'user.rb' | ||
| require_relative 'channel.rb' | ||
| require_relative 'slackapierror.rb' | ||
| require_relative 'workspace.rb' | ||
|
|
||
| # TODO project | ||
|
|
||
| puts "Thank you for using the Ada Slack CLI" | ||
| def main | ||
| puts "\nWelcome to the Ada Slack CLI!\n\n" | ||
| ws1 = Workspace.new | ||
|
|
||
| choices_hash = ws1.menu_choices_hash | ||
| main_menu = ws1.main_menu(headings: ["", "MAIN MENU"], rows_as_hash: choices_hash) | ||
|
|
||
| quit_program = false | ||
| while quit_program == false | ||
| puts | ||
| puts main_menu | ||
| print "Please select from main menu: " | ||
| choice = gets.chomp() | ||
|
|
||
| result = ws1.menu_action(choice) | ||
|
|
||
| if result | ||
| if (result.class == User) || (result.class == Channel) | ||
| ws1.entity = result | ||
| end | ||
| end | ||
|
|
||
| puts "Press any key to get back to menu" | ||
| gets | ||
| end | ||
| end | ||
|
|
||
| main if __FILE__ == $PROGRAM_NAME |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| #!/usr/bin/env ruby | ||
| require 'awesome_print' | ||
| require 'httparty' | ||
| require 'dotenv' | ||
| Dotenv.load | ||
| # will raise error if key not found | ||
| Dotenv.require_keys("SLACK_KEY") | ||
| puts ENV["SLACK_KEY"] | ||
|
|
||
| # THESE ARE THE 3 THINGS WE'RE ALLOWED TO DO ON THIS API | ||
| # chat:write:bot | ||
| # channels:read | ||
| # users:read | ||
|
|
||
| def main | ||
| puts "\nWelcome to the Ada Slack CLI!\n\n" | ||
|
|
||
| url = "https://slack.com/api/channels.list" | ||
| query_params = { token: ENV["SLACK_KEY"] } | ||
| response = HTTParty.get(url, query: query_params) | ||
| ap response | ||
| puts | ||
| url = "https://slack.com/api/users.list" | ||
| query_params = { token: ENV["SLACK_KEY"] } | ||
| response = HTTParty.get(url, query: query_params) | ||
| ap response | ||
| puts | ||
| # url = "https://slack.com/api/chat.postMessage" | ||
| # query_params = { token: ENV["SLACK_KEY"], channel: "CN5R2SQ8L", text: "CHECK THIS OUT!!!"} | ||
| # response = HTTParty.get(url, query: query_params) | ||
| # # ap response | ||
| # puts | ||
|
|
||
|
|
||
| url = "https://slack.com/api/chat.postEphemeral" | ||
| query_params = { token: ENV["SLACK_KEY"], channel: "CN5R2SQ8L", text: "HI!!", user: "UN69JD3V3"} | ||
| response = HTTParty.get(url, query: query_params) | ||
| ap response | ||
| puts | ||
|
|
||
|
|
||
|
|
||
|
|
||
| puts "\nThank you for using the Ada Slack CLI\n\n" | ||
| end | ||
|
|
||
| main if __FILE__ == $PROGRAM_NAME |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| require_relative 'lib_helper.rb' | ||
|
|
||
| class SlackAPIError < StandardError | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| require_relative 'lib_helper.rb' | ||
| require_relative 'recipient' | ||
|
|
||
| class User < Recipient | ||
| attr_reader :real_name | ||
|
|
||
| def initialize(id:, name:, real_name:) | ||
| super(id: id, name: name) | ||
| @real_name = real_name | ||
| end | ||
|
|
||
| def details | ||
| return {id: id, name: name, real_name: real_name} | ||
| end | ||
|
|
||
| def self.get | ||
| url = "https://slack.com/api/users.list" | ||
| params = { token: KEY } | ||
| response = super(url, params) | ||
| # sleep(0.25) | ||
| return response | ||
| end | ||
|
|
||
| def self.get_real_names | ||
| response = (self.get)["members"] | ||
| all_real_names = response.map do |member_info| | ||
| member_info["real_name"] | ||
| end | ||
| return all_real_names | ||
| end | ||
|
|
||
| def self.get_names | ||
| response = (self.get)["members"] | ||
| all_names = response.map do |member_info| | ||
| member_info["name"] | ||
| end | ||
| return all_names | ||
| end | ||
|
|
||
| def self.get_ids | ||
| response = (self.get)["members"] | ||
| all_ids = response.map do |member_info| | ||
| member_info["id"] | ||
| end | ||
| return all_ids | ||
| end | ||
|
|
||
| def self.load_all | ||
| real_names = self.get_real_names | ||
| names = self.get_names | ||
| ids = self.get_ids | ||
| all_users = [] | ||
|
|
||
| ids.length.times do |index| | ||
| new_user = User.new(id: ids[index], name: names[index], real_name: real_names[index]) | ||
| all_users << new_user | ||
| end | ||
|
|
||
| return all_users | ||
| end | ||
|
|
||
|
|
||
| end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
The way these methods are seperated is a little awkward and inefficient because the same api ends up getting called 4 times when all of that information is available in the response from each call.
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.
I understand the tradeoff though because it enables smaller, succinct methods, one for each attribute. You could accomplish both of these things by pulling the call to
self.getout of these methods. Ifself.getwere called directing fromself.load_all, the results fromself.getcould be passed to each method like so:result = self.getself.get_names(result)...