Class: MxHero::API::Directories

Inherits:
Object
  • Object
show all
Includes:
Communication, Urls
Defined in:
lib/directories.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Urls

#domain_by_id_url, #domains_url, #service_url

Methods included from Communication

#call, #headers, #json_parse

Constructor Details

#initialize(domain, config = {}) ⇒ Directories

Returns a new instance of Directories.

Parameters:

  • domain (String)
  • config (Hash) (defaults to: {})

    the options of configuration

Options Hash (config):

  • :api_url (String)

    The URL to consume the API

  • :username (String)

    The username for access the API

  • :password (String)

    The password for the user that access the API

  • :verbose (Boolean) — default: false

    If true puts information about http operations

  • :as_user (String)

    Send to the API to indentify the end user (app user email)



108
109
110
111
112
113
114
115
# 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

Instance Attribute Details

#domainObject (readonly)

Returns the value of attribute domain.



99
100
101
# File 'lib/directories.rb', line 99

def domain
  @domain
end

Instance Method Details

#create(directory) ⇒ MxHero::API::Response

Create a directory configuration

Returns:

  • (MxHero::API::Response)

    that Directory created In case on error, may be one of the following:

    + domain.ldap.alredy.exists
    


136
137
138
139
140
# 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

#deleteMxHero::API::Response

Delete the directory configuration

Returns:

  • (MxHero::API::Response)

    with empty content. In case on error, may be one of the following:

    + domain.ldap.not.found : Inexistent group
    


159
160
161
162
# File 'lib/directories.rb', line 159

def delete
  response = call(:delete, directories_url, throw_exception: false)
  wrap_response_from response
end

#fetchMxHero::API::Directory | nil

Fetch the directory information

Returns:



121
122
123
124
125
126
127
128
# 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

#refreshMxHero::API::Response

Request to refresh the accounts information

Returns:

  • (MxHero::API::Response)

    with empty content. In case on error, may be one of the following:

    + domain.ldap.not.found : Inexistent group
    


169
170
171
172
# File 'lib/directories.rb', line 169

def refresh
  response = call(:post, directories_url + '/refresh', throw_exception: false)
  wrap_response_from response
end

#update(directory) ⇒ MxHero::API::Response

Update the directory configuration

Returns:

  • (MxHero::API::Response)

    that Directory updated In case on error, may be one of the following:

    + domain.ldap.not.found
    


148
149
150
151
152
# 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