Skip to content

Instantly share code, notes, and snippets.

@fabiokr
Created February 10, 2012 19:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fabiokr/1791894 to your computer and use it in GitHub Desktop.
Save fabiokr/1791894 to your computer and use it in GitHub Desktop.
diff --git a/lib/moo_moo/base.rb b/lib/moo_moo/base.rb
index 43ed22a..f20a36e 100644
--- a/lib/moo_moo/base.rb
+++ b/lib/moo_moo/base.rb
@@ -2,6 +2,29 @@ module MooMoo
class Base
attr_reader :host, :key, :user, :pass, :port
+ # Register an api service for the current class.
+ #
+ # register_service :action_one, :object_one
+ #
+ # That will generate the following method for this class:
+ #
+ # def action_one(params)
+ # run_command :action_one, :object_one, params, cookie
+ # end
+ #
+ # === Parameters
+ #
+ # * <tt>method_name</tt> - the method name
+ # * <tt>object</tt> - the object
+ # * <tt>action_name</tt> - the api action to be called; by default it is the same as method_name
+ def self.register_service(method_name, object, action_name = nil)
+ send :define_method, method_name do |params = {}|
+ params[:key] = 'attributes'
+ cookie = params.delete :cookie
+ run_command action_name, object, params, cookie
+ end
+ end
+
# Constructor
#
# === Required
diff --git a/lib/moo_moo/provisioning.rb b/lib/moo_moo/provisioning.rb
index 627a02f..9dee18f 100644
--- a/lib/moo_moo/provisioning.rb
+++ b/lib/moo_moo/provisioning.rb
@@ -1,79 +1,13 @@
module MooMoo
class Provisioning < Base
- # Cancels a Trust Service order
- #
- # ==== Required
- # * <tt>:order_id</tt> - ID of the order
- def cancel_order(order_id)
- run_command :cancel_order, :trust_service, {
- :order_id => order_id,
- :key => 'attributes'
- }
- end
-
- # Cancels pending or declined orders
- #
- # ==== Required
- # * <tt>:to_date</tt> - date before which to cancel orders
- def cancel_pending_orders(to_date)
- run_command :cancel_pending_orders, :order, {
- :to_date => to_date,
- :key => 'attributes'
- }
- end
-
- # Changes information associated with a domain
- #
- # ==== Required
- # * <tt>:type</tt> - type of data to modify
- # * <tt>:params</tt> - new parameter values to set
- #
- # ==== Optional
- # * <tt>:cookie</tt> - cookie for the domain
- def modify(params)
- cookie = params.delete :cookie
-
- run_command :modify, :domain, params, cookie
- end
-
- # Processes or cancels a pending order
- #
- # ==== Required
- # * <tt>:order_id</tt> - ID of the pending order to process
- def process_pending(order_id)
- run_command :process_pending, :domain, {
- :order_id => order_id,
- :key => 'attributes'
- }
- end
-
- # Renews a domain name
- #
- # ==== Required
- # * <tt>:domain</tt> - domain name to renew
- # * <tt>:term</tt> - number of years to renew for
- # * <tt>:current_expiration_year</tt> - current expiration year in YYYY format
- def renew_domain(attribs)
- Args.new(attribs) do |c|
- c.requires :domain, :term, :current_expiration_year
- end
- attribs[:handle] = 'process' unless attribs[:handle]
- attribs[:key] = 'attributes'
-
- run_command :renew, :domain, attribs
- end
-
- # Removes the domain at the registry
- #
- # ==== Required
- # * <tt>:domain</tt> - domain name to remove
- # * <tt>:reseller</tt> - username of the reseller
- def revoke(params)
- params[:key] = 'attributes'
-
- run_command :revoke, :domain, params
- end
+ register_service :cancel_order, :trust_service, :parameter => :order_id
+ register_service :cancel_pending_orders, :order
+ register_service :modify, :domain
+ register_service :process_pending, :domain
+ register_service :renew_domain, :domain, :renew
+ register_service :revoke, :domain
+ register_service :register_domain, :domain
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment