Class: Keycloak::HTTPClient
- Inherits:
-
Object
- Object
- Keycloak::HTTPClient
- Defined in:
- lib/keycloak-api-rails/http_client.rb
Instance Method Summary collapse
- #get(realm_id, path) ⇒ Object
-
#initialize(configuration, logger) ⇒ HTTPClient
constructor
A new instance of HTTPClient.
Constructor Details
#initialize(configuration, logger) ⇒ HTTPClient
Returns a new instance of HTTPClient.
3 4 5 6 7 8 9 10 |
# File 'lib/keycloak-api-rails/http_client.rb', line 3 def initialize(configuration, logger) @server_url = configuration.server_url @ca_certificate_file = configuration.ca_certificate_file @logger = logger @x509_store = OpenSSL::X509::Store.new @x509_store.set_default_paths @x509_store.add_file(@ca_certificate_file) if @ca_certificate_file end |
Instance Method Details
#get(realm_id, path) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/keycloak-api-rails/http_client.rb', line 12 def get(realm_id, path) uri = build_uri(realm_id, path) use_ssl = uri.scheme == "http" ? false : true Net::HTTP.start(uri.host, uri.port, :use_ssl => use_ssl, :cert_store => @x509_store) do |http| request = Net::HTTP::Get.new(uri) response = http.request(request) begin response.value JSON.parse(response.body) rescue @logger.error("Keycloak responded with an error when calling '#{path}'. Status #{response.code}. Payload: #{response.body}") end end end |