module Delphix

A library for supporting connections to the Delphix API. The module Delphix is based on the singleton pattern, which restricts instantiation of a class to only one instance that is globally available.

@example

To establish a session with the Delphix appliance and get a cookies for
your effort you issue the following sequence:

* Configure the Delphix client to use the specified version of the API, in
  hash format as `{ major: 1, micro: 0, minor: 0 }`, for example:
    Delphix.api_version = {
      type: 'APIVersion',
      version: { major: 1, micro: 0, minor: 0 }
    }
* Specify the Delphix server to connect to.
    Delphix.server = 'delphix.example.com'
* Specify the Delphix username to connect with.
    Delphix.api_user = 'delphix'
* Specify the Delphix password to use.
    Delphix.api_passwd = 'delphix'
* Now you have an established session, go crazy.

Author: Stefano Harding <riddopic@gmail.com> 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.

The version number of the Delphix Gem

@return [String]

@api public

Constants

API_ENDPOINT
HTTP_HEADERS
VERSION

Attributes

api_passwd[RW]

@!attribute [rw] api_passwd

@return [String] password for authentication
api_user[RW]

@!attribute [rw] api_user

@return [String] username to authenticate with
api_version[RW]

@!attribute [rw] api_version

@return [Hash] containing the major, minor and micro version numbers.
last_request[RW]

@!attribute [rw] last_request

@return [Hash] retruns the last request
last_response[RW]

@!attribute [rw] last_response

@return [Hash] retruns the last response
server[RW]

@!attribute [rw] server

@return [String] Delphix server address
session[RW]

@!attribute [rw] session

@return [Hash] retruns current session state
@return [#code] the response code from Delphix engine
@return [#headers] beautified with symbols and underscores
@return [#body] parsed response body
@return [#raw_body] un-parsed response body
verbose[RW]

@!attribute [rw] verbose

@return [Nothing] enables verbosity

Public Class Methods

api_url(resource = nil) click to toggle source

Returns the API endpoint for a given resource namespace by combining the server address with the appropriate HTTP headers.

@param resource [Resource] namespace

@return [URL] return the URL for the API endpoint

@api public

# File lib/delphix.rb, line 105
def self.api_url(resource = nil)
  'http://' + @server + resource
end
clear_default_headers() click to toggle source

@return [Hash]

The HTTP headers sent with a POST/GET/DELETE.
# File lib/delphix/client.rb, line 104
def self.clear_default_headers
  @@default_headers = {}
end
cookies() click to toggle source

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.

@return [Hash] cookies

containing the new session cookies

@api public

# File lib/delphix.rb, line 123
def self.cookies
  @resp ||= Delphix.post session_url,
    type: 'APISession', version: @api_version
  @resp.cookies
end
default_header(name, value) click to toggle source

@param [String, Symbol] name

A string or symbol used to identify the key portion of the HTTP headers.

@param [String, Symbol, Array] value

A string, symbol or array containing the values of the HTTP header.

@return [Hash]

The result of the key/value pair.
# File lib/delphix/client.rb, line 97
def self.default_header(name, value)
  @@default_headers[name] = value
end
login(user = @api_user, passwd = @api_passwd) click to toggle source

Authenticates the session so that API calls can be made. Only supports basic password authentication.

@param [String] user

user name to authenticate with

@param [String] passwd

password to authenticate with

@return [Fixnum, code]

the response code from Delphix engine

@return [Hash, headers]

headers, beautified with symbols and underscores

@return [Hash, body] body

parsed response body where applicable (JSON responses are parsed to
Objects/Associative Arrays)

@return [Hash, raw_body] raw_body

un-parsed response body

@api public

# File lib/delphix.rb, line 148
def self.login(user = @api_user, passwd = @api_passwd)
  Delphix.post login_url,
    type: 'LoginRequest', username: user, password: passwd
end
timeout(seconds) click to toggle source

@param [Integer] seconds

Set the number of seconds to wait for an HTTP timeout.

@return [undefined]

# File lib/delphix/client.rb, line 113
def self.timeout(seconds)
  @@timeout = seconds
end

Public Instance Methods

inspect() click to toggle source

@return [String] object inspection @!visibility private

# File lib/delphix.rb, line 244
def inspect
  instance_variables.inject([
    "\n#<#{self.class}:0x#{object_id.to_s(16)}>",
    "\tInstance variables:"
  ]) do |result, item|
    result << "\t\t#{item} = #{instance_variable_get(item)}"
    result
  end.join("\n")
end
to_s() click to toggle source

@return [String] string of instance @!visibility private

# File lib/delphix.rb, line 256
def to_s
  "<#{self.class}:0x#{object_id.to_s(16)} session=#{@session}>"
end