Class: Cloudcover::Okta::Client
- Inherits:
-
Object
- Object
- Cloudcover::Okta::Client
- Includes:
- HTTParty
- Defined in:
- lib/cloudcover/okta/client.rb
Instance Attribute Summary collapse
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
Class Method Summary collapse
Instance Method Summary collapse
- #get_json(path, options = {}) ⇒ Object
- #groups ⇒ Object
-
#initialize ⇒ Client
constructor
A new instance of Client.
- #logged_in? ⇒ Boolean
- #login(username, password) ⇒ Object
- #login_id ⇒ Object
- #me ⇒ Object
- #myApps ⇒ Object
- #remove_header(key) ⇒ Object
- #set_headers(headers) ⇒ Object
- #test_get(path) ⇒ Object
Constructor Details
#initialize ⇒ Client
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
#headers ⇒ Object (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.login(username, password) new.tap { |instance| instance.login(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, = {}) JSON.parse(self.class.get(path, ).body, symbolize_names: true) end |
#groups ⇒ Object
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
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 login(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" (resp.parsed_response['cookieToken']) else resp.parsed_response end end |
#login_id ⇒ Object
49 50 51 |
# File 'lib/cloudcover/okta/client.rb', line 49 def login_id me[:profile][:login] end |
#me ⇒ Object
37 38 39 |
# File 'lib/cloudcover/okta/client.rb', line 37 def me get_json('/api/v1/users/me', headers: @headers) end |
#myApps ⇒ Object
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 |