Module: Chatterbot::UI

Included in:
Bot
Defined in:
lib/chatterbot/ui.rb

Overview

routines for outputting setup instructions

Constant Summary collapse

API_SIGNUP_URL =
"https://twitter.com/apps/new"

Instance Method Summary collapse

Instance Method Details

#display_oauth_errorObject

error message for auth



102
103
104
# File 'lib/chatterbot/ui.rb', line 102

def display_oauth_error
  STDERR.puts "Oops!  Looks like something went wrong there, please try again!"
end

#get_api_keyObject

Ask the user to get an API key from Twitter.



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/chatterbot/ui.rb', line 60

def get_api_key
  green "****************************************"
  green "****************************************"
  green "****        API SETUP TIME!         ****"
  green "****************************************"
  green "****************************************"      

  
  puts "Hey, looks like you need to get an API key from Twitter before you can get started."
  puts "Please hit enter, and I will send you to #{API_SIGNUP_URL} to start the process."
  puts "(If it doesn't work, you can open a browser and paste the URL in manually)"

  puts "\nHit Enter to continue."
  
  STDIN.readline

  Launchy.open(API_SIGNUP_URL)
  # pause to allow any launchy output
  sleep(1)

  puts "\n\n"
  
  print "\n\nPaste the 'API Key' here: "
  STDOUT.flush
  config[:consumer_key] = STDIN.readline.chomp

  print "Paste the 'API Secret' here: "
  STDOUT.flush
  config[:consumer_secret] = STDIN.readline.chomp

  # reset the client so we can re-init with new OAuth credentials
  reset_client
  
  #
  # capture ctrl-c and exit without a stack trace
  #
rescue Interrupt => e
  exit
end

#get_oauth_verifierObject

print out a message about getting a PIN from twitter, then output the URL the user needs to visit to authorize

:nocov:



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/chatterbot/ui.rb', line 24

def get_oauth_verifier
  green "****************************************"
  green "****************************************"
  green "****        BOT AUTH TIME!          ****"
  green "****************************************"
  green "****************************************"      

  puts "You need to authorize your bot with Twitter.\n\nPlease login to Twitter under the bot's account. When you're ready, hit Enter.\n\nYour browser will open with the following URL, where you can authorize the bot.\n\n"

  url = request_token.authorize_url

  puts url

  puts "\nIf that doesn't work, you can open the URL in your browser manually."

  puts "\n\nHit enter to start.\n\n"
  
  STDIN.readline.chomp
  
  Launchy.open(url)

  # sleep here so that if launchy has any output (which it does
  # sometimes), it doesn't interfere with our input prompt
 
  sleep(1)

  puts "Paste your PIN and hit enter when you have completed authorization.\n\n"
  print "> "

  STDIN.readline.chomp
rescue Interrupt => e
  exit
end

#green(str) ⇒ Object



15
16
17
# File 'lib/chatterbot/ui.rb', line 15

def green(str)
  puts str.colorize(:green)
end

#red(str) ⇒ Object



11
12
13
# File 'lib/chatterbot/ui.rb', line 11

def red(str)
  puts str.colorize(:red)
end