Class: MxHero::API::Directories
- Inherits:
-
Object
- Object
- MxHero::API::Directories
- Includes:
- Communication, Urls
- Defined in:
- lib/directories.rb
Instance Attribute Summary collapse
-
#domain ⇒ Object
readonly
Returns the value of attribute domain.
Instance Method Summary collapse
-
#create(directory) ⇒ MxHero::API::Response
Create a directory configuration.
-
#delete ⇒ MxHero::API::Response
Delete the directory configuration.
-
#fetch ⇒ MxHero::API::Directory | nil
Fetch the directory information.
-
#initialize(domain, config = {}) ⇒ Directories
constructor
A new instance of Directories.
-
#refresh ⇒ MxHero::API::Response
Request to refresh the accounts information.
-
#update(directory) ⇒ MxHero::API::Response
Update the directory configuration.
Methods included from Urls
#domain_by_id_url, #domains_url, #service_url
Methods included from Communication
Constructor Details
#initialize(domain, config = {}) ⇒ Directories
Returns a new instance of Directories.
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
#domain ⇒ Object (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
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 |
#delete ⇒ MxHero::API::Response
Delete the directory configuration
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 |
#fetch ⇒ MxHero::API::Directory | nil
Fetch the directory information
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 |
#refresh ⇒ MxHero::API::Response
Request to refresh the accounts information
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
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 |