Module: ZendeskAPI::Read

Includes:
Rescue
Included in:
ReadResource, Resource
Defined in:
lib/zendesk_api/actions.rb

Instance Method Summary collapse

Instance Method Details

#find(client, options = {}) ⇒ Object

Finds a resource by an id and any options passed in. A custom path to search at can be passed into opts. It defaults to the Data.resource_name of the class.

Parameters:

  • client (Client)

    The Client object to be used

  • options (Hash) (defaults to: {})

    Any additional GET parameters to be added

Raises:

  • (ArgumentError)


77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/zendesk_api/actions.rb', line 77

def find(client, options = {})
  @client = client # so we can use client.logger in rescue

  raise ArgumentError, "No :id given" unless options[:id] || options["id"] || ancestors.include?(SingularResource)
  association = options.delete(:association) || Association.new(:class => self)

  includes = Array(options[:include])
  options[:include] = includes.join(",") if includes.any?

  response = client.connection.get(association.generate_path(options)) do |req|
    req.params = options
  end

  new(client, response.body[singular_resource_name]).tap do |resource|
    resource.set_includes(resource, includes, response.body)
  end
end