Class: MooMoo::BaseCommand
- Inherits:
-
Object
- Object
- MooMoo::BaseCommand
- 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
Instance Attribute Summary collapse
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#password ⇒ Object
readonly
Returns the value of attribute password.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
-
#username ⇒ Object
readonly
Returns the value of attribute username.
Class Method Summary collapse
-
.register_service(action_name, object) ⇒ Object
Register an api service for the current class.
Instance Method Summary collapse
-
#attributes ⇒ Object
Returns the response attributes.
-
#initialize(params = {}) ⇒ BaseCommand
constructor
Constructor.
-
#message ⇒ Object
Returns the response message if one is present.
-
#successful? ⇒ Boolean
Returns whether or not the command executed was successful.
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
#host ⇒ Object (readonly)
Returns the value of attribute host.
16 17 18 |
# File 'lib/moo_moo/base_command.rb', line 16 def host @host end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
16 17 18 |
# File 'lib/moo_moo/base_command.rb', line 16 def key @key end |
#password ⇒ Object (readonly)
Returns the value of attribute password.
16 17 18 |
# File 'lib/moo_moo/base_command.rb', line 16 def password @password end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
16 17 18 |
# File 'lib/moo_moo/base_command.rb', line 16 def port @port end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
16 17 18 |
# File 'lib/moo_moo/base_command.rb', line 16 def response @response end |
#username ⇒ Object (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
#attributes ⇒ Object
Returns the response attributes.
63 64 65 |
# File 'lib/moo_moo/base_command.rb', line 63 def attributes response.body['attributes'] end |
#message ⇒ Object
Returns the response message if one is present
58 59 60 |
# File 'lib/moo_moo/base_command.rb', line 58 def response.body['response_text'] end |
#successful? ⇒ Boolean
Returns whether or not the command executed was successful
53 54 55 |
# File 'lib/moo_moo/base_command.rb', line 53 def successful? response.body['is_success'].to_i == 1 end |