lib/infoblox/resource.rb in infoblox-0.0.11 vs lib/infoblox/resource.rb in infoblox-0.1.0

- old
+ new

@@ -1,8 +1,8 @@ module Infoblox class Resource - attr_accessor :_ref + attr_accessor :_ref, :connection def self.wapi_object(obj=nil) obj.nil? ? @wapi_object : @wapi_object = obj end @@ -59,13 +59,13 @@ end ## # Return an array of all records for this resource. # - def self.all + def self.all(connection) JSON.parse(connection.get(resource_uri, default_params).body).map do |item| - new(item) + new(item.merge({:connection => connection})) end end ## # Find resources with query parameters. @@ -74,25 +74,17 @@ # {"_return_fields" => "extensible_attributes"} # # Example: filter resources by name. # {"name~" => "foo.*bar"} # - def self.find(params) + def self.find(connection, params) params = default_params.merge(params) JSON.parse(connection.get(resource_uri, params).body).map do |item| - new(item) + new(item.merge({:connection => connection})) end end - def self.connection - @@connection - end - - def self.connection=(con) - @@connection = con - end - def self.resource_uri BASE_PATH + self.wapi_object end def initialize(attrs={}) @@ -100,11 +92,11 @@ self.send("#{k}=", v) end end def post - self._ref = connection.post(resource_uri, remote_attribute_hash(write = true, post = true)).body + self._ref = unquote(connection.post(resource_uri, remote_attribute_hash(write = true, post = true)).body) true end alias_method :create, :post def delete @@ -114,11 +106,12 @@ def get(params={}) connection.get(resource_uri, params) end def put - connection.put(resource_uri, remote_attribute_hash(write = true)) + self._ref = unquote(connection.put(resource_uri, remote_attribute_hash(write = true)).body) + true end def resource_uri self._ref.nil? ? self.class.resource_uri : (BASE_PATH + self._ref) end @@ -136,12 +129,11 @@ end if post end end private - - def connection - self.class.connection + def unquote(str) + str.gsub(/\A['"]+|['"]+\Z/, "") end - end + end \ No newline at end of file