# File lib/infoblox/resource.rb, line 72 def self._return_fields remove = Infoblox.wapi_version < '1.2' ? :extattrs : :extensible_attributes ((self.remote_attrs + self.remote_read_only_attrs) - [remove]).join(",") end
Return an array of all records for this resource. You can use the default parameters _max_results an/or ::_return_fields as documented by Infoblox.
Example: return only 70 results
{"_max_results" => 70}
Example: return only 100 results, throw an error if there are more
{"_max_results" => -100}
# File lib/infoblox/resource.rb, line 91 def self.all(connection, params = {}) params = default_params.merge(params) JSON.parse(connection.get(resource_uri, params).body).map do |item| new(item.merge({:connection => connection})) end end
# File lib/infoblox/resource.rb, line 77 def self.default_params {:_return_fields => self._return_fields} end
Find resources with query parameters. You can use the default parameters _max_results an/or ::_return_fields as documented by Infoblox.
Example: return extensible attributes for every resource.
{"_return_fields" => "extensible_attributes"}
Example: filter resources by name, return 692 results or less
{"name~" => "foo.*bar", "_max_results" => 692}
# File lib/infoblox/resource.rb, line 108 def self.find(connection, params) params = default_params.merge(params) JSON.parse(connection.get(resource_uri, params).body).map do |item| new(item.merge({:connection => connection})) end end
# File lib/infoblox/resource.rb, line 127 def initialize(attrs={}) load_attributes(attrs) end
Define a writeable remote attribute, i.e. one that should show up in post / put operations.
# File lib/infoblox/resource.rb, line 18 def self.remote_attr_accessor(*args) args.each do |a| attr_accessor a remote_attrs << a end end
Define a read-only attribute
# File lib/infoblox/resource.rb, line 49 def self.remote_attr_reader(*args) args.each do |a| attr_reader a remote_read_only_attrs << a end end
Define a remote attribute that is write-only
# File lib/infoblox/resource.rb, line 39 def self.remote_attr_writer(*args) args.each do |a| attr_accessor a remote_write_only_attrs << a end end
# File lib/infoblox/resource.rb, line 56 def self.remote_attrs @remote_attrs ||= [] end
Define a remote attribute that can only be sent during a POST operation.
# File lib/infoblox/resource.rb, line 29 def self.remote_post_accessor(*args) args.each do |a| attr_accessor a remote_post_attrs << a end end
# File lib/infoblox/resource.rb, line 68 def self.remote_post_attrs @remote_post_attrs ||= [] end
# File lib/infoblox/resource.rb, line 64 def self.remote_read_only_attrs @remote_read_only_attrs ||= [] end
# File lib/infoblox/resource.rb, line 60 def self.remote_write_only_attrs @remote_write_only_attrs ||= [] end
# File lib/infoblox/resource.rb, line 115 def self.resource_uri Infoblox.base_path + self.wapi_object end
# File lib/infoblox/resource.rb, line 5 def self.wapi_object(obj=nil) if obj.nil? @wapi_object else self.resource_map[obj] = self @wapi_object = obj end end
# File lib/infoblox/resource.rb, line 137 def delete connection.delete(resource_uri).status == 200 end
# File lib/infoblox/resource.rb, line 141 def get(params=self.class.default_params) response = connection.get(resource_uri, params).body load_attributes(JSON.parse(response)) self end
# File lib/infoblox/resource.rb, line 131 def post self._ref = unquote(connection.post(resource_uri, remote_attribute_hash(write = true, post = true)).body) true end
# File lib/infoblox/resource.rb, line 147 def put self._ref = unquote(connection.put(resource_uri, remote_attribute_hash(write = true)).body) true end
# File lib/infoblox/resource.rb, line 156 def remote_attribute_hash(write=false, post=false) {}.tap do |hsh| self.class.remote_attrs.each do |k| hsh[k] = self.send(k) unless self.send(k).nil? end self.class.remote_write_only_attrs.each do |k| hsh[k] = self.send(k) unless self.send(k).nil? end if write self.class.remote_post_attrs.each do |k| hsh[k] = self.send(k) unless self.send(k).nil? end if post end end
# File lib/infoblox/resource.rb, line 152 def resource_uri self._ref.nil? ? self.class.resource_uri : (Infoblox.base_path + self._ref) end
# File lib/infoblox/resource.rb, line 175 def load_attributes(attrs) attrs.each do |k,v| # Some things have specialized writers, # like Host if respond_to?("#{k}=") send("#{k}=", v) # Some things don't have writers (i.e. remote_attr_reader fields) else instance_variable_set("@#{k}", v) end end end
# File lib/infoblox/resource.rb, line 171 def unquote(str) str.gsub(/\A['"]+|['"]+\Z/, "") end