Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
.DS_Store

# Ignore environemnt variables
.env
.env
30 changes: 30 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug Open Ruby File",
"type": "Ruby",
"request": "launch",
"cwd": "${workspaceRoot}",
"program": "${file}"
},
{
"name": "Debug Ruby Test File",
"type": "Ruby",
"request": "launch",
"cwd": "${workspaceRoot}",
"program": "${file}",
"includes": ["test", "lib"]
},
{
"name": "Debug Highlighted Ruby Test",
"type": "Ruby",
"request": "launch",
"cwd": "${workspaceRoot}",
"program": "${file}",
"args": [
"-n", "/test_[0-9]{4}_${selectedText}/"
]
}
]
}
47 changes: 47 additions & 0 deletions lib/channel.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
require_relative 'recipient'

module SlackApi
class Channel < Recipient

attr_reader :topic, :member_count, :slack_id, :name

def initialize(
slack_id:,
name:,
topic:,
member_count:
)

super(slack_id: slack_id, name: name)

@topic = topic
@member_count = member_count
end

def show_details
end

# ################# Class Methods ########################

# https://api.slack.com/methods/conversations.list
def self.list_all
# This method exists in Class Workspace.
end

end

end














75 changes: 75 additions & 0 deletions lib/recipient.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
require 'httparty'
require 'dotenv'

Dotenv.load


module SlackApi
class Recipient
attr_reader :slack_id, :name


def initialize(
slack_id:,
name:

)
@slack_id = slack_id
@name = name

end

def show_details
raise NotImplementedError, "Define this method in a child class"
end


# ################## Class Methods #########################

# These methods are not implemented ########################
BASE_URL = "https://slack.com/api/"


def self.get(url, params)
# send message using HTTParty
# check for errors
end


# What is a 'factory' method???
def self.list_all
raise NotImplementedError, "Define this method in a child class"
end





def self.send_message(message, channel)

# endpoint = BASE_URL + "chat.postMessage"

# response = HTTParty.post(
# endpoint,
# body: {
# token: BOT_TOKEN,
# text: message,
# channel: channel
# },
# headers: { 'Content-Type' => 'application/x-www-form-urlencoded' }
# )

# unless response.code == 200 && response.parsed_response["ok"]
# raise SlackApiError, "Error when posting #{message} to #{channel}, error: #{response.parsed_response["error"]}"
# end

# return true


end
end

end


class SlackApiError < StandardError; end
42 changes: 38 additions & 4 deletions lib/slack.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,46 @@
#!/usr/bin/env ruby
require_relative 'workspace'
require_relative 'user'
require_relative 'channel'

# nice work :)

# helper method
def get_user_input
puts "Choose an action from the following list:
1. View Users => Enter: users
2. View Channels => Enter: channels
3. Quit => Type: quit "
return gets.chomp.upcase
end

def main
workspace = SlackApi::Workspace.new
puts "\n"
puts "Welcome to the Ada Slack CLI!"
workspace = Workspace.new
puts "\n"
puts "What would you like to do?"
puts "\n"

# TODO project
user_input = get_user_input
puts "\n"

puts "Thank you for using the Ada Slack CLI"
while user_input != "QUIT"
if user_input == "USERS"
workspace.list_all_users
puts "\n"
elsif user_input == "CHANNELS"
workspace.list_all_channels
puts "\n"
else
puts "Bad Entry: Try Again."
puts "\n"
end
user_input = get_user_input
puts "\n"
end
puts "Thank you for using the Ada Slack CLI"
puts "\n"
end

main if __FILE__ == $PROGRAM_NAME
main if __FILE__ == $PROGRAM_NAME
28 changes: 28 additions & 0 deletions lib/user.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
require_relative 'recipient'

module SlackApi
class User < Recipient

attr_reader :real_name, :slack_id, :name, :status_text, :status_emoji

def initialize(
slack_id:,
name:,
real_name:,
status_text: nil,
status_emoji: nil
)

super(slack_id: slack_id, name: name)

@real_name = real_name
@status_text = status_text
@status_emoji = status_emoji
end

def show_details
end

end

end
70 changes: 70 additions & 0 deletions lib/workspace.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
require 'httparty'
require 'dotenv'
require 'pry'
require 'table_print'

Dotenv.load

module SlackApi
class Workspace
attr_reader :users, :channels

def initialize(

)

@channels = get_channels_from_api
@users = get_users_from_api

end

BASE_URL = "https://slack.com/api/"


def get_users_from_api
query_parameters = {
token: ENV["SLACK_TOKEN"]
}
endpoint = BASE_URL + "users.list"
response = HTTParty.get(endpoint, query: query_parameters)
@users = response["members"].map do |member|
User.new(slack_id: member["id"], name: member["name"], real_name: member["real_name"])
end

end

def get_channels_from_api
query_parameters = {
token: ENV["SLACK_TOKEN"]
}
endpoint = BASE_URL + "channels.list"
response = HTTParty.get(endpoint, query: query_parameters)
@channels = response["channels"].map do |channel|
Channel.new(slack_id: channel["id"], name: channel["name"],
member_count: channel["members"].length, topic: channel["topic"]["value"])
end

end

def list_all_users
tp @users, "name", "real_name", "slack_id"
return
end

def list_all_channels
tp @channels, "name", "topic", "member_count", "slack_id"
return
end

end

end









Loading