Module: Socialcast::CommandLine

Defined in:
lib/socialcast.rb,
lib/socialcast/command_line/cli.rb,
lib/socialcast/command_line/message.rb,
lib/socialcast/command_line/version.rb,
lib/socialcast/command_line/provisioner.rb,
lib/socialcast/command_line/authenticate.rb,
lib/socialcast/command_line/ldap_connector.rb,
lib/socialcast/command_line/provision_user.rb,
lib/socialcast/command_line/provision_photo.rb

Defined Under Namespace

Modules: Provisioner Classes: Authenticate, CLI, LDAPConnector, Message, ProvisionPhoto, ProvisionUser

Constant Summary collapse

VERSION =
'1.4.2'

Class Method Summary collapse

Class Method Details

.authentication(options) ⇒ Object



51
52
53
54
55
56
57
# File 'lib/socialcast.rb', line 51

def self.authentication(options)
  if options[:external_system]
    { :headers => { :Authorization => "SocialcastApiClient #{credentials[:api_client_identifier]}:#{credentials[:api_client_secret]}" } }
  else
    { :user => credentials[:user], :password => credentials[:password] }
  end
end

.config_dirObject



16
17
18
19
20
# File 'lib/socialcast.rb', line 16

def self.config_dir
  config_dir = File.expand_path '~/.socialcast'
  FileUtils.mkdir config_dir, :mode => 0700 unless File.exist?(config_dir)
  config_dir
end

.credentialsObject



26
27
28
29
# File 'lib/socialcast.rb', line 26

def self.credentials
  fail 'Unknown Socialcast credentials.  Run `socialcast authenticate` to initialize' unless File.exist?(credentials_file)
  YAML.load_file(credentials_file)
end

.credentials=(options) ⇒ Object



31
32
33
34
35
36
37
38
# File 'lib/socialcast.rb', line 31

def self.credentials=(options)
  File.open(credentials_file, "a+") do |f|
    existing_content = YAML.load(f.read) || {}
    f.truncate(0)
    f.write(existing_content.merge(options).to_yaml)
  end
  File.chmod 0600, credentials_file
end

.credentials_fileObject



22
23
24
# File 'lib/socialcast.rb', line 22

def self.credentials_file
  ENV['SC_CREDENTIALS_FILE'] || File.join(config_dir, 'credentials.yml')
end

.resource_for_path(path, options = {}, debug = false) ⇒ Object

configure restclient for api call



41
42
43
44
45
46
47
48
49
# File 'lib/socialcast.rb', line 41

def self.resource_for_path(path, options = {}, debug = false)
  RestClient.log = Logger.new(STDOUT) if debug
  RestClient.proxy = credentials[:proxy] if credentials[:proxy]

  rest_client_options = options.merge(authentication(options))
  rest_client_options[:verify_ssl] = OpenSSL::SSL::VERIFY_NONE if rest_client_options.delete('skip_ssl_validation')
  url = ['https://', credentials[:domain], path].join
  RestClient::Resource.new url, rest_client_options
end