lib/slackdo.rb in slackdo-0.3.2 vs lib/slackdo.rb in slackdo-0.3.3
- old
+ new
@@ -13,17 +13,29 @@
hash = {
"slack_webhook" => "",
"allow_trello_pushing" => "false",
"trello_public_key" => "",
"trello_member_token" => "",
- "trello_list_id" => ""
+ "trello_list_id" => "",
+ "trello_label_list_ids" => []
}
File.open("#{ENV['HOME']}/.slackdo/config.json",'w') do |f|
f.write(hash.to_json)
end
end
end
+ def add_label
+ cli = HighLine.new
+ file = File.read("#{ENV['HOME']}/.slackdo/config.json")
+ hash = JSON.parse(file)
+ id = cli.ask 'What is the ID of the label you wish to add?'.strip
+ hash['trello_label_list_ids'] << id
+ File.open("#{ENV['HOME']}/.slackdo/config.json",'w') do |f|
+ f.write(hash.to_json)
+ end
+ puts "Label with ID '#{id}' was added..."
+ end
def enable_trello
file = File.read("#{ENV['HOME']}/.slackdo/config.json")
hash = JSON.parse(file)
hash["allow_trello_pushing"] = "true"
File.open("#{ENV['HOME']}/.slackdo/config.json",'w') do |f|
@@ -76,47 +88,63 @@
Trello.configure do |config|
config.developer_public_key = hash['trello_public_key']
config.member_token = hash['trello_member_token']
end
end
- def add_card(card_name, card_desc)
+ def add_card(card_category, card_name, card_desc)
file = File.read("#{ENV['HOME']}/.slackdo/config.json")
hash = JSON.parse(file)
configure_trello
+ card_name_full = ''
+ card_name_full << "[#{card_category}]"
+ card_name_full << " #{card_name}"
+ label_id = ''
+ hash['trello_label_list_ids'].each do |id|
+ label = Trello::Label.find(id)
+ label_id = id if label.name == card_category
+ end
card = Trello::Card.create(
- name: card_name,
+ name: card_name_full,
desc: card_desc,
- list_id: hash['trello_list_id'],
+ list_id: hash['trello_list_id'],
pos: 'top',
+ card_labels: label_id
)
card.save
puts 'Card was created on Trello...'
end
end
class Task
$note_content = ''
$message = ''
+ $category = ''
+ def set_category(cat)
+ $category = cat
+ end
+ def get_category
+ return $category
+ end
def set_message(text)
- $message = text
+ $message = text
end
+ def get_message
+ return $message
+ end
def set_notes(notes)
- $note_content = notes
+ $note_content = notes
end
- def get_message
- return $message
- end
def get_notes
return $note_content
end
def add_task
file = File.read("#{ENV['HOME']}/.slackdo/config.json")
hash = JSON.parse(file)
webhook = hash['slack_webhook']
notifier = Slack::Notifier.new webhook
cli = HighLine.new
- category = cli.ask 'What is the category of this new task? eg. DEV or GENERAL'
+ cli_category = cli.ask 'What is the category of this new task? eg. DEV or GENERAL'
cli_message = cli.ask 'Type your new task:'
want_note = cli.ask 'Do you want to add a note to this new task? y/n'
cli_note = ''
while want_note == 'y'
note_text = cli.ask 'Type your note:'
@@ -127,12 +155,13 @@
fallback: "This should've been a new note but looks like something went wrong...",
text: cli_note,
color: "gray",
mrkdwn_in: ["text"]
}
- set_message("[#{category}] #{cli_message}")
+ set_message(cli_message)
+ set_category(cli_category)
set_notes(cli_note)
- notifier.post text: "• [#{category}] #{cli_message}", attachments: [note]
+ notifier.post text: "• [#{cli_category}] #{cli_message}", attachments: [note]
puts 'Item was posted to Slack...'
end
end
class Reminder