lib/esgob/client.rb
# Call a named Esgob API function.
#
# @param [String] function_name The name of API function.
# @param [Hash] args Pairs of argument keys and values.
# @return [Hash] The response from the Esgob service, with symbols as keys.
# @example client.call('domains.slaves.add', :domain => 'example.com', :masterip => '192.168.0.1')
Call a named Esgob API function.
Call a named Esgob API function .
def call(function_name, args = {})
    uri = URI(config.endpoint + function_name)
    uri.query = build_query(default_arguments.merge(args))
    res = Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |http|
      req = Net::HTTP::Get.new(uri.request_uri)
      req['Accept'] = 'application/json'
      http.request(req)
    end
    if res.content_type == 'application/json'
      data = symbolize_keys! JSON.parse(res.body)
      if data.key?(:error)
        raise Esgob::ServerError.new(
          data[:error][:message],
          data[:error][:code].to_s
        )
      elsif res.code !~ /^2/
        raise Esgob::ServerError.new(res.message, res.code)
      else
        return data
      end
    else
      raise "HTTP response from ESGOB is not of type JSON"
    end
  end
def call ( function_name , args = { } ) uri = URI ( config . endpoint + function_name ) uri . query = build_query ( default_arguments . merge ( args ) ) res = Net :: HTTP . start ( uri . host , uri . port , :use_ssl => uri . scheme == 'https' ) do | http | req = Net :: HTTP :: Get . new ( uri . request_uri ) req [ 'Accept' ] = 'application/json' http . request ( req ) end if res . content_type == 'application/json' data = symbolize_keys! JSON . parse ( res . body ) if data . key? ( :error ) raise Esgob :: ServerError . new ( data [ :error ] [ :message ] , data [ :error ] [ :code ] . to_s ) elsif res . code !~ / ^2 / raise Esgob :: ServerError . new ( res . message , res . code ) else return data end else raise "HTTP response from ESGOB is not of type JSON" end end
Call a named Esgob API function.
Call a named Esgob API function .
The response from the Esgob service, with symbols as keys.
The response from the Esgob service with symbols as keys .
Hash
function_name
args
args Pairs of argument keys and values.
args Pairs of argument keys and values .
example
None