class Socialcast::CommandLine::Authenticate
Attributes
authenticate_type[RW]
headers[RW]
options[RW]
params[RW]
Public Class Methods
current_user()
click to toggle source
# File lib/socialcast/command_line/authenticate.rb, line 13 def self.current_user @current_user ||= find_current_user end
find_current_user()
click to toggle source
# File lib/socialcast/command_line/authenticate.rb, line 17 def self.find_current_user response = Socialcast::CommandLine.resource_for_path('/api/userinfo.json').get json_body = JSON.parse(response.body) if json_body['user'] json_body['user'] else raise "Unable to find the current user: #{response.body}" end end
new(authenticate_type, options, params, headers = {})
click to toggle source
# File lib/socialcast/command_line/authenticate.rb, line 6 def initialize(authenticate_type, options, params, headers = {}) self.authenticate_type = authenticate_type self.options = options self.params = params self.headers = headers end
Public Instance Methods
request()
click to toggle source
# File lib/socialcast/command_line/authenticate.rb, line 27 def request @request ||= send_request end
Private Instance Methods
domain()
click to toggle source
# File lib/socialcast/command_line/authenticate.rb, line 55 def domain options[:domain] end
send_request()
click to toggle source
# File lib/socialcast/command_line/authenticate.rb, line 33 def send_request puts "Authenticating to #{url}" RestClient.log = Logger.new($stdout) if options[:trace] RestClient.proxy = options[:proxy] if options[:proxy] resource = RestClient::Resource.new url, headers response = resource.post params, :accept => :json puts "API response: #{response.body.to_s}" if options[:trace] set_default_credentials response end
set_default_credentials()
click to toggle source
# File lib/socialcast/command_line/authenticate.rb, line 44 def set_default_credentials Socialcast::CommandLine.credentials = { :domain => domain, :proxy => options[:proxy] } end
url()
click to toggle source
# File lib/socialcast/command_line/authenticate.rb, line 51 def url @url ||= File.join("https://", domain, 'api', (authenticate_type == :external_system ? 'external_systems/' : ''), 'authentication') end