Class: Cloudcover::Okta::Client

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/cloudcover/okta/client.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeClient

Returns a new instance of Client.



11
12
13
14
15
16
17
18
19
# File 'lib/cloudcover/okta/client.rb', line 11

def initialize
  self.class.debug_output if Cloudcover::GlobalConfig.debug
  self.class.base_uri "https://#{Cloudcover::GlobalConfig.okta_domain}.okta.com"
  @headers = {
    'Content-Type' => "application/json",
    'Accept' => "application/json",
    'User-Agent' => "Cloudcover/#{Cloudcover::VERSION} (#{Socket.gethostname})"
  }
end

Instance Attribute Details

#headersObject (readonly)

Returns the value of attribute headers.



9
10
11
# File 'lib/cloudcover/okta/client.rb', line 9

def headers
  @headers
end

Class Method Details

.login(username, password) ⇒ Object



21
22
23
# File 'lib/cloudcover/okta/client.rb', line 21

def self.(username, password)
    new.tap { |instance| instance.(username, password) }
end

Instance Method Details

#get_json(path, options = {}) ⇒ Object



33
34
35
# File 'lib/cloudcover/okta/client.rb', line 33

def get_json(path, options = {})
  JSON.parse(self.class.get(path, options).body, symbolize_names: true)
end

#groupsObject



41
42
43
# File 'lib/cloudcover/okta/client.rb', line 41

def groups
  get_json('/api/v1/users/me/groups', headers: @headers)
end

#logged_in?Boolean

Returns:

  • (Boolean)


53
54
55
56
57
# File 'lib/cloudcover/okta/client.rb', line 53

def logged_in?
  me[:status] == "ACTIVE"
rescue
  false
end

#login(username, password) ⇒ Object



59
60
61
62
63
64
65
66
67
# File 'lib/cloudcover/okta/client.rb', line 59

def (username, password)
  post_body = {username: username, password: password}.to_json
  resp = self.class.post('/api/v1/sessions?additionalFields=cookieToken', {body: post_body, headers: @headers})
  if resp.parsed_response['status'] == "ACTIVE"
    set_session_cookie(resp.parsed_response['cookieToken'])
  else
    resp.parsed_response
  end
end

#login_idObject



49
50
51
# File 'lib/cloudcover/okta/client.rb', line 49

def 
  me[:profile][:login]
end

#meObject



37
38
39
# File 'lib/cloudcover/okta/client.rb', line 37

def me
  get_json('/api/v1/users/me', headers: @headers)
end

#myAppsObject



45
46
47
# File 'lib/cloudcover/okta/client.rb', line 45

def myApps
  get_json('/api/v1/users/me/appLinks', headers: @headers)
end

#remove_header(key) ⇒ Object



29
30
31
# File 'lib/cloudcover/okta/client.rb', line 29

def remove_header(key)
  @headers.delete(key)
end

#set_headers(headers) ⇒ Object



25
26
27
# File 'lib/cloudcover/okta/client.rb', line 25

def set_headers(headers)
  @headers.merge!(headers)
end

#test_get(path) ⇒ Object



69
70
71
# File 'lib/cloudcover/okta/client.rb', line 69

def test_get(path)
  self.class.get(path, headers: @headers)
end