class Socialcast::CommandLine::CLI
Public Class Methods
new(*args)
click to toggle source
Calls superclass method
# File lib/socialcast/command_line/cli.rb, line 19 def initialize(*args); super; end
Public Instance Methods
authenticate()
click to toggle source
# File lib/socialcast/command_line/cli.rb, line 35 def authenticate user = options[:user] || ask('Socialcast login (email address): ') password = options[:password] || HighLine.new.ask("Socialcast password: ") { |q| q.echo = false }.to_s params = { :email => user, :password => password } response = Socialcast::CommandLine::Authenticate.new(:user, options, params).request communities = JSON.parse(response.body.to_s)['communities'] domain = communities.detect { |c| c['domain'] == options[:domain] } ? options[:domain] : communities.first['domain'] Socialcast::CommandLine.credentials = { :user => user, :password => password, :domain => domain } say "Authentication successful for #{domain}" end
authenticate_external_system()
click to toggle source
# File lib/socialcast/command_line/cli.rb, line 57 def authenticate_external_system api_client_identifier = options[:api_client_identifier] || ask("Socialcast external system identifier: ") api_client_secret = options[:api_client_secret] || ask("Socialcast external system API secret: ") headers = { :headers => { :Authorization => "SocialcastApiClient #{api_client_identifier}:#{api_client_secret}" } } Socialcast::CommandLine::Authenticate.new(:external_system, options, {}, headers).request Socialcast::CommandLine.credentials = { :api_client_identifier => api_client_identifier, :api_client_secret => api_client_secret, } end
info()
click to toggle source
# File lib/socialcast/command_line/cli.rb, line 23 def info if options["version"] say "Socialcast Command Line #{Socialcast::CommandLine::VERSION}" end end
ldap_config(options)
click to toggle source
# File lib/socialcast/command_line/cli.rb, line 145 def ldap_config(options) config_file = File.expand_path options[:config] if options[:setup] create_file config_file do File.read File.join(File.dirname(__FILE__), '..', '..', '..', 'config', 'ldap.yml') end say "Created config file: #{config_file}" Kernel.exit 0 end fail "Unable to load configuration file: #{config_file}" unless File.exists?(config_file) say "Using configuration file: #{config_file}" config = YAML.load_file config_file mappings = config.fetch 'mappings', {} required_mappings = %w{email first_name last_name} required_mappings.each do |field| unless mappings.has_key? field fail "Missing required mapping: #{field}" end end config end
load_plugins(options)
click to toggle source
# File lib/socialcast/command_line/cli.rb, line 135 def load_plugins(options) Array.wrap(options[:plugins]).each do |plugin| begin require plugin rescue LoadError => e fail "Unable to load #{plugin}: #{e}" end end end
provision()
click to toggle source
# File lib/socialcast/command_line/cli.rb, line 115 def provision config = ldap_config options load_plugins options Socialcast::CommandLine::ProvisionUser.new(config, options).provision rescue Socialcast::CommandLine::ProvisionUser::ProvisionError => e Kernel.abort e.message end
sync_photos()
click to toggle source
# File lib/socialcast/command_line/cli.rb, line 128 def sync_photos config = ldap_config options Socialcast::CommandLine::ProvisionPhoto.new(config, options).sync end