Class: MooMoo::BaseCommand

Inherits:
Object
  • Object
show all
Defined in:
lib/moo_moo/base_command.rb

Overview

Defines the basic command structure.

For OpenSRS api methods, create them like this, using the proper api action name and object:

register_service :action_one, :object_one

If you need customized responses, create a custom method:

def custom_action(parameter)
  api_action_one(... custom parameter ...)
  ... custom response processing ...
end

Direct Known Subclasses

Cookie, DnsZone, Lookup, Nameserver, Provisioning, Transfer

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ BaseCommand

Constructor

Required

* <tt>:host</tt> - host of the OpenSRS server
* <tt>:key</tt> - private key
* <tt>:username</tt> - username of the reseller
* <tt>:password</tt> - password of the rseller

Optional

* <tt>:port</tt> - port to connect on


44
45
46
47
48
49
50
# File 'lib/moo_moo/base_command.rb', line 44

def initialize(params = {})
  @host     = params[:host]     || MooMoo.config.host     || raise(OpenSRSException, "Host is required")
  @key      = params[:key]      || MooMoo.config.key      || raise(OpenSRSException, "Key is required")
  @username = params[:username] || MooMoo.config.username || raise(OpenSRSException, "Username is required")
  @password = params[:password] || MooMoo.config.password || raise(OpenSRSException, "Password is required")
  @port     = params[:port]     || MooMoo.config.port     || 55443
end

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



16
17
18
# File 'lib/moo_moo/base_command.rb', line 16

def host
  @host
end

#keyObject (readonly)

Returns the value of attribute key.



16
17
18
# File 'lib/moo_moo/base_command.rb', line 16

def key
  @key
end

#passwordObject (readonly)

Returns the value of attribute password.



16
17
18
# File 'lib/moo_moo/base_command.rb', line 16

def password
  @password
end

#portObject (readonly)

Returns the value of attribute port.



16
17
18
# File 'lib/moo_moo/base_command.rb', line 16

def port
  @port
end

#responseObject (readonly)

Returns the value of attribute response.



16
17
18
# File 'lib/moo_moo/base_command.rb', line 16

def response
  @response
end

#usernameObject (readonly)

Returns the value of attribute username.



16
17
18
# File 'lib/moo_moo/base_command.rb', line 16

def username
  @username
end

Class Method Details

.register_service(action_name, object) ⇒ Object

Register an api service for the current class.

register_service :action_one, :object_one

A method called “api_action_one” will then be created.

Parameters

  • action_name - the api action to be called

  • object - the object



28
29
30
31
32
# File 'lib/moo_moo/base_command.rb', line 28

def self.register_service(action_name, object)
  define_method("api_#{action_name}") do |*args|
    perform(action_name, object, args.first || {})
  end
end

Instance Method Details

#attributesObject

Returns the response attributes.



63
64
65
# File 'lib/moo_moo/base_command.rb', line 63

def attributes
  response.body['attributes']
end

#messageObject

Returns the response message if one is present



58
59
60
# File 'lib/moo_moo/base_command.rb', line 58

def message
  response.body['response_text']
end

#successful?Boolean

Returns whether or not the command executed was successful

Returns:

  • (Boolean)


53
54
55
# File 'lib/moo_moo/base_command.rb', line 53

def successful?
  response.body['is_success'].to_i == 1
end