Method: Chatterbot::UI#get_api_key
- Defined in:
- lib/chatterbot/ui.rb
#get_api_key ⇒ Object
Ask the user to get an API key from Twitter.
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/chatterbot/ui.rb', line 103 def get_api_key green "****************************************" green "****************************************" green "**** API SETUP TIME! ****" green "****************************************" green "****************************************" puts "\n\nWelcome to Chatterbot. Let's walk through the steps to get a bot running.\n\n" # # At this point, we don't have any API credentials at all for # this bot, but it's possible the user has already setup an app. # Let's ask! # puts "Hey, looks like you need to get an API key from Twitter before you can get started.\n\n" app_already_exists = ask_yes_no("Have you already set up an app with Twitter?") if app_already_exists puts "Terrific! Let's get your bot running!\n\n" else puts "OK, I can help with that!\n\n" send_to_app_creation end print "\n\nPaste the 'Consumer Key' here: " STDOUT.flush config[:consumer_key] = STDIN.readline.chomp.strip print "Paste the 'Consumer Secret' here: " STDOUT.flush config[:consumer_secret] = STDIN.readline.chomp.strip puts "\n\nNow it's time to authorize your bot!\n\n" if ! app_already_exists && ask_yes_no("Do you want to authorize a bot using the account that created the app?") puts "OK, on the app page, you can click the 'Create my access token' button to proceed.\n\n" print "Paste the 'Access Token' here: " STDOUT.flush config[:access_token] = STDIN.readline.chomp.strip print "\n\nPaste the 'Access Token Secret' here: " STDOUT.flush config[:access_token_secret] = STDIN.readline.chomp.strip # reset the client so we can re-init with new OAuth credentials reset_client # at this point we should have a fully validated client, so grab # the screen name @screen_name = client.user.screen_name rescue nil else reset_client end # # capture ctrl-c and exit without a stack trace # rescue Interrupt => e exit end |