Method: MixinBot::CLI#initialize
- Defined in:
- lib/mixin_bot/cli.rb
#initialize(*args) ⇒ CLI
Returns a new instance of CLI.
22 23 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 57 58 59 60 61 62 |
# File 'lib/mixin_bot/cli.rb', line 22 def initialize(*args) super if [:keystore].blank? @api_instance = MixinBot::API.new return end keystore = if File.file? [:keystore] File.read [:keystore] else [:keystore] end @keystore = begin JSON.parse keystore rescue JSON::ParserError log UI.fmt( format( '{{x}} falied to parse keystore.json: %<keystore>s', keystore: [:keystore] ) ) end return unless @keystore MixinBot.config.api_host = [:apihost] @api_instance ||= begin MixinBot::API.new( app_id: @keystore['app_id'] || @keystore['client_id'], session_id: @keystore['session_id'], server_public_key: @keystore['server_public_key'] || @keystore['pin_token'], session_private_key: @keystore['session_private_key'] || @keystore['private_key'] ) rescue StandardError => e log UI.fmt '{{x}}: Failed to initialize api, maybe your keystore is incorrect: %<error>s', error: e. end end |