Module: TrelloDXY::Requests::Shared
- Included in:
- BoardForUrl
- Defined in:
- lib/trello_dxy/requests/shared.rb
Instance Method Summary collapse
- #connect_to_trello ⇒ Object
- #get_key(key_name) ⇒ Object
- #key ⇒ Object
- #make_dotfile ⇒ Object
- #token ⇒ Object
Instance Method Details
#connect_to_trello ⇒ Object
6 7 8 9 10 11 |
# File 'lib/trello_dxy/requests/shared.rb', line 6 def connect_to_trello Trello.configure do |config| config.developer_public_key = key config.member_token = token end end |
#get_key(key_name) ⇒ Object
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/trello_dxy/requests/shared.rb', line 21 def get_key(key_name) make_dotfile key = '' File.open(ENV['HOME'] + '/.trello_dxy').read.each_line do |line| if line.start_with? key_name key = line.split('=').last.strip end end key end |
#key ⇒ Object
13 14 15 |
# File 'lib/trello_dxy/requests/shared.rb', line 13 def key get_key 'TRELLO_DEVELOPER_PUBLIC_KEY' end |
#make_dotfile ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/trello_dxy/requests/shared.rb', line 32 def make_dotfile current = {} dotfile_path = ENV['HOME'] + '/.trello_dxy' template_path = TrelloDXY::Utils.gem_libdir + '/templates/trello_dxy.erb' if File.exist? dotfile_path template = File.readlines(template_path) env = File.readlines(dotfile_path).each do |line| kv = line.chomp.split('=', 2) current[kv[0]] = kv[1] unless kv[1].nil? || kv[1].empty? end end trello_developer_public_key = current['TRELLO_DEVELOPER_PUBLIC_KEY'] || ask('Trello developer public key (visit https://trello.com/app-key): ') trello_member_token = current['TRELLO_MEMBER_TOKEN'] || ask("Trello member token (visit https://trello.com/1/connect?key=#{trello_developer_public_key}&name=trello_dxy&response_type=token): ") template_file = File.open(template_path, 'r').read erb = ERB.new(template_file) File.open(dotfile_path, 'w+') { |file| file.write(erb.result(binding)) } end |
#token ⇒ Object
17 18 19 |
# File 'lib/trello_dxy/requests/shared.rb', line 17 def token get_key 'TRELLO_MEMBER_TOKEN' end |