Class: Slackdo::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/slackdo.rb

Instance Method Summary collapse

Instance Method Details

#add_labelObject



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/slackdo.rb', line 26

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

#configure_initObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/slackdo.rb', line 9

def configure_init
  system "mkdir #{ENV['HOME']}/.slackdo &> /dev/null"
	  unless File.exist?("#{ENV['HOME']}/.slackdo/config.json")
		system "touch #{ENV['HOME']}/.slackdo/config.json"
		hash = {
			"slack_webhook" => "",
			"allow_trello_pushing" => "false",
			"trello_public_key" => "",
			"trello_member_token" => "",
			"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

#configure_slack_webhookObject



71
72
73
74
75
76
77
78
79
80
81
# File 'lib/slackdo.rb', line 71

def configure_slack_webhook
  cli = HighLine.new
	  file = File.read("#{ENV['HOME']}/.slackdo/config.json")
  hash = JSON.parse(file)
	  webhook = cli.ask 'What is your Slack webhook?'.strip
  hash["slack_webhook"] = webhook
	  File.open("#{ENV['HOME']}/.slackdo/config.json",'w') do |f|
    f.write(hash.to_json)
  end
	  puts 'Slack API was configured...'
end

#configure_trello_apiObject



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/slackdo.rb', line 55

def configure_trello_api
  cli = HighLine.new
  file = File.read("#{ENV['HOME']}/.slackdo/config.json")
     hash = JSON.parse(file)
  public_key = cli.ask 'What is your Trello public key?'.strip
  member_token = cli.ask 'What is your Trello member token?'.strip
  list_id = cli.ask 'What is your board list ID where the cards should be created?'.strip
  hash["trello_public_key"] = public_key
  hash["trello_member_token"] = member_token
  hash["allow_trello_pushing"] = "true"
  hash["trello_list_id"] = list_id
  File.open("#{ENV['HOME']}/.slackdo/config.json",'w') do |f|
       f.write(hash.to_json)
     end
  puts 'Trello API was configured...'
end

#disable_trelloObject



46
47
48
49
50
51
52
53
54
# File 'lib/slackdo.rb', line 46

def disable_trello
     file = File.read("#{ENV['HOME']}/.slackdo/config.json")
     hash = JSON.parse(file)
  hash["allow_trello_pushing"] = "false"
  File.open("#{ENV['HOME']}/.slackdo/config.json",'w') do |f|
       f.write(hash.to_json)
     end
  puts 'Trello has been disabled...'
end

#enable_trelloObject



37
38
39
40
41
42
43
44
45
# File 'lib/slackdo.rb', line 37

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|
    f.write(hash.to_json)
  end
  puts 'Trello has been enabled...'
end