lib/socialcast.rb in socialcast-1.3.6 vs lib/socialcast.rb in socialcast-1.3.7
- old
+ new
@@ -1,10 +1,11 @@
require 'yaml'
require 'fileutils'
require_relative 'socialcast/command_line/ldap_connector'
require_relative 'socialcast/command_line/provision'
+require_relative 'socialcast/command_line/authenticate'
require_relative 'socialcast/command_line/message'
require_relative 'socialcast/command_line/cli'
require_relative 'socialcast/command_line/version'
module Socialcast
@@ -23,21 +24,31 @@
fail 'Unknown Socialcast credentials. Run `socialcast authenticate` to initialize' unless File.exist?(credentials_file)
YAML.load_file(credentials_file)
end
def self.credentials=(options)
- File.open(credentials_file, "w") do |f|
- f.write(options.to_yaml)
+ 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
# configure restclient for api call
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] })
+ RestClient::Resource.new url, options.merge(authentication(options))
+ end
+
+ 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
end
end