Class: Imap::Backup::Configuration::GmailOauth2
- Inherits:
-
Object
- Object
- Imap::Backup::Configuration::GmailOauth2
- Defined in:
- lib/imap/backup/configuration/gmail_oauth2.rb
Constant Summary collapse
- BANNER =
"GMail OAuth2 Setup\n\nYou need to authorize imap_backup to get access to your email.\nTo do so, please follow the instructions here:\n\nhttps://github.com/joeyates/imap-backup/docs/setting-up-gmail.md\n\n".freeze
- GMAIL_READ_SCOPE =
"https://mail.google.com/".freeze
- OOB_URI =
"urn:ietf:wg:oauth:2.0:oob".freeze
Instance Attribute Summary collapse
-
#account ⇒ Object
readonly
Returns the value of attribute account.
-
#client_id ⇒ Object
readonly
Returns the value of attribute client_id.
-
#client_secret ⇒ Object
readonly
Returns the value of attribute client_secret.
Instance Method Summary collapse
-
#initialize(account) ⇒ GmailOauth2
constructor
A new instance of GmailOauth2.
- #run ⇒ Object
Constructor Details
#initialize(account) ⇒ GmailOauth2
Returns a new instance of GmailOauth2.
22 23 24 |
# File 'lib/imap/backup/configuration/gmail_oauth2.rb', line 22 def initialize(account) @account = account end |
Instance Attribute Details
#account ⇒ Object (readonly)
Returns the value of attribute account.
18 19 20 |
# File 'lib/imap/backup/configuration/gmail_oauth2.rb', line 18 def account @account end |
#client_id ⇒ Object (readonly)
Returns the value of attribute client_id.
19 20 21 |
# File 'lib/imap/backup/configuration/gmail_oauth2.rb', line 19 def client_id @client_id end |
#client_secret ⇒ Object (readonly)
Returns the value of attribute client_secret.
20 21 22 |
# File 'lib/imap/backup/configuration/gmail_oauth2.rb', line 20 def client_secret @client_secret end |
Instance Method Details
#run ⇒ Object
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 |
# File 'lib/imap/backup/configuration/gmail_oauth2.rb', line 26 def run Kernel.system("clear") Kernel.puts BANNER @client_id = highline.ask("client_id: ") @client_secret = highline.ask("client_secret: ") Kernel.puts "\n Open the following URL in your browser\n\n \#{authorization_url}\n\n Then copy the success code\n\n MESSAGE\n\n @code = highline.ask(\"success code: \")\n @credentials = authorizer.get_and_store_credentials_from_code(\n user_id: email, code: @code, base_url: OOB_URI\n )\n\n raise \"Failed\" if !@credentials\n\n token = JSON.parse(token_store.load(email))\n token[\"client_secret\"] = client_secret\n token.to_json\nend\n" |