Class | NFSN::APIObject |
In: |
nfsn-api.rb
|
Parent: | Object |
An abstract API object.
# File nfsn-api.rb, line 246 def initialize(mgr, type, instance_id) @mgr = mgr @type = type @instance_id = instance_id end
Defines a method. For example:
nfsn_method :addAlias, [:alias]
declares a method called addAlias that takes a single argument called alias. This will declare a method that takes the correct number of arguments.
# File nfsn-api.rb, line 315 def self.nfsn_method(symbol, arg_list = []) args = arg_list.map { |a| "arg_#{a}" }.join(",") args_map = arg_list.map { |a| "\"#{a}\" => arg_#{a}" }.join(",\n") args_sym = arg_list.map { |a| ":#{a}" }.join(",") class_eval %{ def #{symbol}(#{args}) uri = uriForAttribute("#{symbol}") data = { #{args_map} } @mgr.doOp(:POST, uri, data) end } end
Defines a read-only property. For example:
nfsn_property_ro :balance, Integer
declares an Integer property called balance. Supported types are String and Integer at the moment. This will declare a getter (balance).
# File nfsn-api.rb, line 277 def self.nfsn_property_ro(symbol, rtype = String) # Define reader class_eval %{ def #{symbol} uri = uriForAttribute("#{symbol}") val = @mgr.doOp(:GET, uri) return val if val.nil? if #{rtype} == String return val.to_s elsif #{rtype} == Integer return val.to_i else fail "Unknown type #{rtype}" end end } end
In descendent classes, use something like:
nfsn_property_rw :minTTL, Integer
to declare an Integer property called minTTL. Supported types are String and Integer at the moment. This will declare both a getter (minTTL) and a setter (minTTL=).
# File nfsn-api.rb, line 267 def self.nfsn_property_rw(symbol, rtype = String) self.nfsn_property_ro(symbol, rtype) self.nfsn_property_wo(symbol, rtype) end
Defines a write-only property. For example:
nfsn_property_wo :password, String
declares an String property called password. Supported types are String and Integer at the moment. This will declare a setter (password=).
# File nfsn-api.rb, line 300 def self.nfsn_property_wo(symbol, rtype = String) # Define writer class_eval %{ def #{symbol}=(val) uri = uriForAttribute("#{symbol}") @mgr.doOp(:PUT, uri, val) end } end