lib/survey_gizmo/resource.rb in survey-gizmo-ruby-0.6.0 vs lib/survey_gizmo/resource.rb in survey-gizmo-ruby-0.7.0

- old
+ new

@@ -50,10 +50,18 @@ resource = new(attributes) resource.__send__(:_create) resource end + # Deleted the Resource from Survey Gizmo + # @param [Hash] conditions + # @return [Boolean] + def destroy(conditions) + response = Response.new SurveyGizmo.delete(handle_route(:delete, conditions)) + response.ok? + end + # Define the path where a resource is located # @param [String] path # the path in Survey Gizmo for the resource # @param [Hash] options # @option options [Array] :via @@ -101,10 +109,12 @@ # @api private def handle_route(key, *interp) path = @paths[key] raise "No routes defined for `#{key}` in #{self.name}" unless path options = interp.last.is_a?(Hash) ? interp.pop : path.scan(/:(\w+)/).inject({}){|hash, k| hash.merge(k.to_sym => interp.shift) } - path.gsub(/:(\w+)/){|m| options[$1.to_sym] } + path.gsub(/:(\w+)/) do |m| + options[$1.to_sym].tap{ |result| raise(SurveyGizmo::URLError, "Missing parameters in request: `#{m}`") unless result } + end end end # Updates attributes and saves this Resource instance # \ No newline at end of file