class MxHero::API::Directories
Attributes
Public Class Methods
@param [String] domain @param [Hash] config the options of configuration @option config [String] :api_url The URL to consume the API
@option config [String] :username The username for access the API
@option config [String] :password The password for the user that access the API
@option config [Boolean] :verbose (false) If true puts information about http operations @option config [String] :as_user Send to the API
to indentify the end user (app user email)
# File lib/directories.rb, line 108 def initialize(domain, config = {}) @domain = domain @service_url = config[:api_url] @username = config[:username] @password = config[:password] @verbose = config[:verbose] || false @as_user = config[:as_user] end
Public Instance Methods
Create a directory configuration
@return [MxHero::API::Response] that Directory
created
In case on error, may be one of the following: + domain.ldap.alredy.exists
# File lib/directories.rb, line 136 def create(directory) directory.domain = domain response = call(:post, directories_url, directory.to_json, throw_exception: false) wrap_response_from response end
Delete the directory configuration
@return [MxHero::API::Response] with empty content.
In case on error, may be one of the following: + domain.ldap.not.found : Inexistent group
# File lib/directories.rb, line 159 def delete response = call(:delete, directories_url, throw_exception: false) wrap_response_from response end
Fetch the directory information
@return [MxHero::API::Directory | nil] the directory or nil when not exist.
# File lib/directories.rb, line 121 def fetch response = call(:get, directories_url) if (200..299).include? response.code hash = json_parse response.content return Directory.new hash end nil end
Request to refresh the accounts information
@return [MxHero::API::Response] with empty content.
In case on error, may be one of the following: + domain.ldap.not.found : Inexistent group
# File lib/directories.rb, line 169 def refresh response = call(:post, directories_url + '/refresh', throw_exception: false) wrap_response_from response end
Update the directory configuration
@return [MxHero::API::Response] that Directory
updated
In case on error, may be one of the following: + domain.ldap.not.found
# File lib/directories.rb, line 148 def update(directory) directory.domain = domain response = call(:put, directories_url, directory.to_json, throw_exception: false) wrap_response_from response end
Private Instance Methods
# File lib/directories.rb, line 188 def directories_url domain_by_id_url(domain) + '/adldap' end
# File lib/directories.rb, line 182 def directory_from(response) return nil if response.content.nil? || response.content.empty? hash = json_parse response.content Directory.new hash end
# File lib/directories.rb, line 177 def wrap_response_from(response) content = (200..299).include?(response.code) ? directory_from(response) : json_parse(response.content) Response.new(response.status, content) end