Sha256: c0e83922cb6b314b037d079066e8e53b6ff194da05f79da279aedb188b09eeb0
Contents?: true
Size: 1.32 KB
Versions: 14
Compression:
Stored size: 1.32 KB
Contents
module ZendeskAPI # Creates put, post, delete class methods for custom resource methods. module Verbs class << self private # @macro [attach] container.create_verb # @method $1(method) # Executes a $1 using the passed in method as a path. # Reloads the resource's attributes if any are in the response body. # # Created method takes an optional options hash. Valid options to be passed in to the created method: reload (for caching, default: false) def create_verb(verb) define_method verb do |method| define_method method do |*method_args| opts = method_args.last.is_a?(Hash) ? method_args.pop : {} return instance_variable_get("@_#{verb}_#{method}") if instance_variable_defined?("@_#{verb}_#{method}") && !opts[:reload] response = @client.connection.send(verb, "#{path}/#{method}") do |req| req.body = opts end if (resources = response.body[self.class.resource_name]) && (res = resources.find {|res| res["id"] == id}) @attributes = ZendeskAPI::Trackie.new(res) @attributes.clear_changes end true end end end end create_verb :put create_verb :post create_verb :delete end end
Version data entries
14 entries across 14 versions & 1 rubygems