Module: Delphix
- Includes:
- Utils
- Defined in:
- lib/delphix.rb,
lib/delphix/utils.rb,
lib/delphix/version.rb,
lib/delphix/web_client.rb,
lib/delphix/web_request.rb,
lib/delphix/web_response.rb
Overview
Author: Stefano Harding <[email protected]> License: Apache License, Version 2.0 Copyright: © 2014-2015 Stefano Harding
Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Defined Under Namespace
Modules: ClassMethods, InstanceMethods, Utils, Version Classes: WebClient, WebRequest, WebResponse
Constant Summary collapse
- API_ENDPOINT =
'/resources/json/delphix'
- HTTP_HEADERS =
{ 'Accept' => 'application/json; charset=UTF-8', 'Content-Type' => 'application/json; charset=UTF-8', 'User-Agent' => 'Delphix-Ruby-Client/1.0.0' }
- VERSION =
Delphix::Version.string
- @@timeout =
Default timeout value in seconds.
10
- @@default_headers =
Default headers
{}
Class Attribute Summary collapse
-
.api_passwd ⇒ String
Password for authentication.
-
.api_user ⇒ String
Username to authenticate with.
-
.api_version ⇒ Hash
Containing the major, minor and micro version numbers.
-
.last_request ⇒ Hash
Retruns the last request.
-
.last_response ⇒ Hash
Retruns the last response.
-
.server ⇒ String
Delphix server address.
- .session ⇒ Hash, ...
-
.verbose ⇒ Nothing
Enables verbosity.
Class Method Summary collapse
-
.api_url(resource = nil) ⇒ URL
Returns the API endpoint for a given resource namespace by combining the server address with the appropriate HTTP headers.
-
.clear_default_headers ⇒ Hash
The HTTP headers sent with a POST/GET/DELETE.
-
.cookies ⇒ Hash
Establish a session with the Delphix engine and return an identifier through browser cookies.
-
.default_header(name, value) ⇒ Hash
The result of the key/value pair.
-
.login(user = @api_user, passwd = @api_passwd) ⇒ Fixnum, ...
Authenticates the session so that API calls can be made.
- .timeout(seconds) ⇒ undefined
Instance Method Summary collapse
-
#alert ⇒ String
A helper method to return the URL for the resource by using the resource_url shorthand.
-
#container ⇒ String
A helper method to return the URL for the resource by using the resource_url shorthand.
-
#database ⇒ String
A helper method to return the URL for the resource by using the resource_url shorthand.
-
#environment ⇒ String
A helper method to return the URL for the resource by using the resource_url shorthand.
-
#group ⇒ String
A helper method to return the URL for the resource by using the resource_url shorthand.
-
#host ⇒ String
A helper method to return the URL for the resource by using the resource_url shorthand.
-
#job ⇒ String
A helper method to return the URL for the resource by using the resource_url shorthand.
-
#login ⇒ String
A helper method to return the URL for the resource by using the resource_url shorthand.
-
#method ⇒ Fixnum, ...
Define the #get, #post, and #delete helper methods for sending HTTP requests to the Delphix engine.
-
#policy ⇒ String
A helper method to return the URL for the resource by using the resource_url shorthand.
-
#repository ⇒ String
A helper method to return the URL for the resource by using the resource_url shorthand.
-
#session ⇒ String
A helper method to return the URL for the resource by using the resource_url shorthand.
-
#snapshot ⇒ String
A helper method to return the URL for the resource by using the resource_url shorthand.
-
#source ⇒ String
A helper method to return the URL for the resource by using the resource_url shorthand.
-
#sourceconfig ⇒ String
A helper method to return the URL for the resource by using the resource_url shorthand.
-
#template ⇒ String
A helper method to return the URL for the resource by using the resource_url shorthand.
-
#timeflow ⇒ String
A helper method to return the URL for the resource by using the resource_url shorthand.
-
#user ⇒ String
A helper method to return the URL for the resource by using the resource_url shorthand.
Methods included from Utils
Class Attribute Details
.api_passwd ⇒ String
Returns password for authentication.
90 91 92 |
# File 'lib/delphix.rb', line 90 def api_passwd @api_passwd end |
.api_user ⇒ String
Returns username to authenticate with.
87 88 89 |
# File 'lib/delphix.rb', line 87 def api_user @api_user end |
.api_version ⇒ Hash
Returns containing the major, minor and micro version numbers.
81 82 83 |
# File 'lib/delphix.rb', line 81 def api_version @api_version end |
.last_request ⇒ Hash
Returns retruns the last request.
68 69 70 |
# File 'lib/delphix.rb', line 68 def last_request @last_request end |
.last_response ⇒ Hash
Returns retruns the last response.
71 72 73 |
# File 'lib/delphix.rb', line 71 def last_response @last_response end |
.server ⇒ String
Returns Delphix server address.
84 85 86 |
# File 'lib/delphix.rb', line 84 def server @server end |
.verbose ⇒ Nothing
Returns enables verbosity.
93 94 95 |
# File 'lib/delphix.rb', line 93 def verbose @verbose end |
Class Method Details
.api_url(resource = nil) ⇒ URL
Returns the API endpoint for a given resource namespace by combining the server address with the appropriate HTTP headers.
104 105 106 |
# File 'lib/delphix.rb', line 104 def self.api_url(resource = nil) 'http://' + @server + resource end |
.clear_default_headers ⇒ Hash
Returns The HTTP headers sent with a POST/GET/DELETE.
89 90 91 |
# File 'lib/delphix/web_client.rb', line 89 def self.clear_default_headers @@default_headers = {} end |
.cookies ⇒ Hash
Establish a session with the Delphix engine and return an identifier through browser cookies. This session will be reused in subsequent calls, the same session credentials and state are preserved without requiring a re-authentication call. Sessions do not persisit between incovations.
122 123 124 125 126 |
# File 'lib/delphix.rb', line 122 def self. @resp ||= Delphix.post session_url, type: 'APISession', version: @api_version @resp. end |
.default_header(name, value) ⇒ Hash
Returns The result of the key/value pair.
82 83 84 |
# File 'lib/delphix/web_client.rb', line 82 def self.default_header(name, value) @@default_headers[name] = value end |
.login(user = @api_user, passwd = @api_passwd) ⇒ Fixnum, ...
Authenticates the session so that API calls can be made. Only supports basic password authentication.
147 148 149 150 |
# File 'lib/delphix.rb', line 147 def self.login(user = @api_user, passwd = @api_passwd) Delphix.post login_url, type: 'LoginRequest', username: user, password: passwd end |
.timeout(seconds) ⇒ undefined
98 99 100 |
# File 'lib/delphix/web_client.rb', line 98 def self.timeout(seconds) @@timeout = seconds end |
Instance Method Details
#alert ⇒ String
A helper method to return the URL for the resource by using the resource_url shorthand.
237 238 239 240 241 242 243 244 |
# File 'lib/delphix.rb', line 237 [ :alert, :container, :database, :environment, :group, :host, :job, :login, :policy, :repository, :session, :snapshot, :source, :sourceconfig, :template, :timeflow, :user ].each do |name| define_singleton_method(name.to_s + '_url') do api_url('/resources/json/delphix/' + name.to_s) end end |
#container ⇒ String
A helper method to return the URL for the resource by using the resource_url shorthand.
237 238 239 240 241 242 243 244 |
# File 'lib/delphix.rb', line 237 [ :alert, :container, :database, :environment, :group, :host, :job, :login, :policy, :repository, :session, :snapshot, :source, :sourceconfig, :template, :timeflow, :user ].each do |name| define_singleton_method(name.to_s + '_url') do api_url('/resources/json/delphix/' + name.to_s) end end |
#database ⇒ String
A helper method to return the URL for the resource by using the resource_url shorthand.
237 238 239 240 241 242 243 244 |
# File 'lib/delphix.rb', line 237 [ :alert, :container, :database, :environment, :group, :host, :job, :login, :policy, :repository, :session, :snapshot, :source, :sourceconfig, :template, :timeflow, :user ].each do |name| define_singleton_method(name.to_s + '_url') do api_url('/resources/json/delphix/' + name.to_s) end end |
#environment ⇒ String
A helper method to return the URL for the resource by using the resource_url shorthand.
237 238 239 240 241 242 243 244 |
# File 'lib/delphix.rb', line 237 [ :alert, :container, :database, :environment, :group, :host, :job, :login, :policy, :repository, :session, :snapshot, :source, :sourceconfig, :template, :timeflow, :user ].each do |name| define_singleton_method(name.to_s + '_url') do api_url('/resources/json/delphix/' + name.to_s) end end |
#group ⇒ String
A helper method to return the URL for the resource by using the resource_url shorthand.
237 238 239 240 241 242 243 244 |
# File 'lib/delphix.rb', line 237 [ :alert, :container, :database, :environment, :group, :host, :job, :login, :policy, :repository, :session, :snapshot, :source, :sourceconfig, :template, :timeflow, :user ].each do |name| define_singleton_method(name.to_s + '_url') do api_url('/resources/json/delphix/' + name.to_s) end end |
#host ⇒ String
A helper method to return the URL for the resource by using the resource_url shorthand.
237 238 239 240 241 242 243 244 |
# File 'lib/delphix.rb', line 237 [ :alert, :container, :database, :environment, :group, :host, :job, :login, :policy, :repository, :session, :snapshot, :source, :sourceconfig, :template, :timeflow, :user ].each do |name| define_singleton_method(name.to_s + '_url') do api_url('/resources/json/delphix/' + name.to_s) end end |
#job ⇒ String
A helper method to return the URL for the resource by using the resource_url shorthand.
237 238 239 240 241 242 243 244 |
# File 'lib/delphix.rb', line 237 [ :alert, :container, :database, :environment, :group, :host, :job, :login, :policy, :repository, :session, :snapshot, :source, :sourceconfig, :template, :timeflow, :user ].each do |name| define_singleton_method(name.to_s + '_url') do api_url('/resources/json/delphix/' + name.to_s) end end |
#login ⇒ String
A helper method to return the URL for the resource by using the resource_url shorthand.
237 238 239 240 241 242 243 244 |
# File 'lib/delphix.rb', line 237 [ :alert, :container, :database, :environment, :group, :host, :job, :login, :policy, :repository, :session, :snapshot, :source, :sourceconfig, :template, :timeflow, :user ].each do |name| define_singleton_method(name.to_s + '_url') do api_url('/resources/json/delphix/' + name.to_s) end end |
#method ⇒ Fixnum, ...
Define the #get, #post, and #delete helper methods for sending HTTP requests to the Delphix engine. You shouldn’t need to use these methods directly, but they can be useful for debugging.
The following HTTP methods are supported by the Delphix Appliance:
GET - Retrieve data from the server where complex input is not needed.
All GET requests are guaranteed to be read-only, but not all
read-only requests are required to use GET. Simple input
(strings, number, boolean values) can be passed as query
parameters.
POST - Issue a read/write operation, or make a read-only call that
requires complex input. The optional body of the call is
expressed as JSON.
DELETE - Delete an object on the system. For languages that don't provide
a native wrapper for DELETE, or for delete operations with
optional input, all delete operations can also be invoked as POST
to the same URL with /delete appended to it.
Each method returns a hash that responds to #code, #headers, #body and #raw_body obtained from parsing the JSON object in the response body.
API request responses are parsed to Objects/Associative Arrays)
135 136 137 138 139 140 |
# File 'lib/delphix/web_client.rb', line 135 [:get, :post, :delete].each do |method| define_singleton_method(method) do |url, parameters = {}, &callback| WebClient.request(method.to_sym, url, @@default_headers, parameters.to_json, @@timeout, &callback) end end |
#policy ⇒ String
A helper method to return the URL for the resource by using the resource_url shorthand.
237 238 239 240 241 242 243 244 |
# File 'lib/delphix.rb', line 237 [ :alert, :container, :database, :environment, :group, :host, :job, :login, :policy, :repository, :session, :snapshot, :source, :sourceconfig, :template, :timeflow, :user ].each do |name| define_singleton_method(name.to_s + '_url') do api_url('/resources/json/delphix/' + name.to_s) end end |
#repository ⇒ String
A helper method to return the URL for the resource by using the resource_url shorthand.
237 238 239 240 241 242 243 244 |
# File 'lib/delphix.rb', line 237 [ :alert, :container, :database, :environment, :group, :host, :job, :login, :policy, :repository, :session, :snapshot, :source, :sourceconfig, :template, :timeflow, :user ].each do |name| define_singleton_method(name.to_s + '_url') do api_url('/resources/json/delphix/' + name.to_s) end end |
#session ⇒ String
A helper method to return the URL for the resource by using the resource_url shorthand.
237 238 239 240 241 242 243 244 |
# File 'lib/delphix.rb', line 237 [ :alert, :container, :database, :environment, :group, :host, :job, :login, :policy, :repository, :session, :snapshot, :source, :sourceconfig, :template, :timeflow, :user ].each do |name| define_singleton_method(name.to_s + '_url') do api_url('/resources/json/delphix/' + name.to_s) end end |
#snapshot ⇒ String
A helper method to return the URL for the resource by using the resource_url shorthand.
237 238 239 240 241 242 243 244 |
# File 'lib/delphix.rb', line 237 [ :alert, :container, :database, :environment, :group, :host, :job, :login, :policy, :repository, :session, :snapshot, :source, :sourceconfig, :template, :timeflow, :user ].each do |name| define_singleton_method(name.to_s + '_url') do api_url('/resources/json/delphix/' + name.to_s) end end |
#source ⇒ String
A helper method to return the URL for the resource by using the resource_url shorthand.
237 238 239 240 241 242 243 244 |
# File 'lib/delphix.rb', line 237 [ :alert, :container, :database, :environment, :group, :host, :job, :login, :policy, :repository, :session, :snapshot, :source, :sourceconfig, :template, :timeflow, :user ].each do |name| define_singleton_method(name.to_s + '_url') do api_url('/resources/json/delphix/' + name.to_s) end end |
#sourceconfig ⇒ String
A helper method to return the URL for the resource by using the resource_url shorthand.
237 238 239 240 241 242 243 244 |
# File 'lib/delphix.rb', line 237 [ :alert, :container, :database, :environment, :group, :host, :job, :login, :policy, :repository, :session, :snapshot, :source, :sourceconfig, :template, :timeflow, :user ].each do |name| define_singleton_method(name.to_s + '_url') do api_url('/resources/json/delphix/' + name.to_s) end end |
#template ⇒ String
A helper method to return the URL for the resource by using the resource_url shorthand.
237 238 239 240 241 242 243 244 |
# File 'lib/delphix.rb', line 237 [ :alert, :container, :database, :environment, :group, :host, :job, :login, :policy, :repository, :session, :snapshot, :source, :sourceconfig, :template, :timeflow, :user ].each do |name| define_singleton_method(name.to_s + '_url') do api_url('/resources/json/delphix/' + name.to_s) end end |
#timeflow ⇒ String
A helper method to return the URL for the resource by using the resource_url shorthand.
237 238 239 240 241 242 243 244 |
# File 'lib/delphix.rb', line 237 [ :alert, :container, :database, :environment, :group, :host, :job, :login, :policy, :repository, :session, :snapshot, :source, :sourceconfig, :template, :timeflow, :user ].each do |name| define_singleton_method(name.to_s + '_url') do api_url('/resources/json/delphix/' + name.to_s) end end |
#user ⇒ String
A helper method to return the URL for the resource by using the resource_url shorthand.
237 238 239 240 241 242 243 244 |
# File 'lib/delphix.rb', line 237 [ :alert, :container, :database, :environment, :group, :host, :job, :login, :policy, :repository, :session, :snapshot, :source, :sourceconfig, :template, :timeflow, :user ].each do |name| define_singleton_method(name.to_s + '_url') do api_url('/resources/json/delphix/' + name.to_s) end end |