Class: Socialcast::CommandLine::Authenticate

Inherits:
Object
  • Object
show all
Defined in:
lib/socialcast/command_line/authenticate.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(authenticate_type, options, params, headers = {}) ⇒ Authenticate

Returns a new instance of Authenticate.



6
7
8
9
10
11
# 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

Instance Attribute Details

#authenticate_typeObject

Returns the value of attribute authenticate_type.



4
5
6
# File 'lib/socialcast/command_line/authenticate.rb', line 4

def authenticate_type
  @authenticate_type
end

#headersObject

Returns the value of attribute headers.



4
5
6
# File 'lib/socialcast/command_line/authenticate.rb', line 4

def headers
  @headers
end

#optionsObject

Returns the value of attribute options.



4
5
6
# File 'lib/socialcast/command_line/authenticate.rb', line 4

def options
  @options
end

#paramsObject

Returns the value of attribute params.



4
5
6
# File 'lib/socialcast/command_line/authenticate.rb', line 4

def params
  @params
end

Class Method Details

.current_userObject



13
14
15
# File 'lib/socialcast/command_line/authenticate.rb', line 13

def self.current_user
  @current_user ||= find_current_user
end

.find_current_userObject



17
18
19
20
21
22
23
24
25
# 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

Instance Method Details

#requestObject



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

def request
  @request ||= send_request
end