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/provision.rb

Defined Under Namespace

Classes: CLI, Message, Provision

Constant Summary collapse

VERSION =
"1.3.1"

Class Method Summary collapse

Class Method Details

.config_dirObject



6
7
8
9
10
# File 'lib/socialcast.rb', line 6

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



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

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



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

def self.credentials=(options)
  File.open(credentials_file, "w") do |f|
    f.write(options.to_yaml)
  end
  File.chmod 0600, credentials_file
end

.credentials_fileObject



12
13
14
# File 'lib/socialcast.rb', line 12

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

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

configure restclient for api call



29
30
31
32
33
34
# File 'lib/socialcast.rb', line 29

def self.resource_for_path(path, options = {}, debug = true)
  RestClient.log = Logger.new(STDOUT) if debug
  RestClient.proxy = credentials[:proxy] if credentials[:proxy]
  url = ['https://', credentials[:domain], path].join
  RestClient::Resource.new url, options.merge({ :user => credentials[:user], :password => credentials[:password] })
end