Class: Lionel::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/lionel/cli.rb

Instance Method Summary collapse

Instance Method Details

#authorize(provider) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/lionel/cli.rb', line 6

def authorize(provider)
  case provider
  when 'trello'
    auth = Lionel::TrelloAuthentication.new

    if options['new-client'] || !auth.configured?
      Launchy.open(auth.trello_key_url)
      auth.trello_key = ask "Enter trello key:"

      Launchy.open(auth.trello_token_url)
      auth.trello_token = ask "Enter trello token:"

      auth.save_configuration
    else
      say "Trello is already configured. Run 'lionel authorize trello -n' to reset."
    end
  when 'google'
    auth = Lionel::GoogleAuthentication.new

    if options['new-client'] || !auth.configured?
      Launchy.open(auth.api_console_url)
      auth.google_client_id = ask("Enter your google client id:")
      auth.google_client_secret = ask("Enter your google client secret:")
    end

    Launchy.open(auth.authorize_url)
    auth.retrieve_access_token ask("Enter your google key:")

    auth.save_configuration
  else
    "Provider not recognized: #{provider}"
  end
end

#exportObject



47
48
49
50
51
52
53
54
55
56
57
58
59
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
# File 'lib/lionel/cli.rb', line 47

def export
  lionel_file = options['configuration'] || './Lionelfile'
  eval(File.read(lionel_file)) if File.exists?(lionel_file)

  export = Lionel::Export.new(options)

  if options['google-doc-id']
    export.google_doc_id = options['google-doc-id']
  elsif !export.google_doc_id
    export.google_doc_id = ask("Enter a google doc id to export to:")
  end

  if options['trello-board-id']
    export.trello_board_id = options['trello-board-id']
  elsif !export.trello_board_id
    export.trello_board_id = ask("Enter a trello board id to export from:")
  end

  export.save_configuration if options['save']

  begin
    export.authenticate
  rescue GoogleDrive::Error, GoogleDrive::AuthenticationError
    @google_attempts ||= 0
    @google_attempts += 1
    Lionel::GoogleAuthentication.new.refresh
    if @google_attempts < 2
      retry
    else
      invoke :authorize, ['google'], {}
    end
  rescue Trello::Error, Trello::InvalidAccessToken
    invoke :authorize, ['trello'], {}
  ensure
    export = Lionel::Export.new(options)
    export.authenticate
  end

  welcome = "Trello? Is it me you're looking for?"
  say welcome
  say '=' * welcome.size

  export.process
end