Module: ZendeskAPI::Read::ClassMethods

Defined in:
lib/zendesk_api/actions.rb

Instance Method Summary collapse

Instance Method Details

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

Finds, returning nil if it fails

Parameters:

  • client (Client)

    The Client object to be used

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

    Any additional GET parameters to be added



130
131
132
133
134
# File 'lib/zendesk_api/actions.rb', line 130

def find(client, options = {}, &block)
  find!(client, options, &block)
rescue ZendeskAPI::Error::ClientError
  nil
end

#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)


109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/zendesk_api/actions.rb', line 109

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

    yield req if block_given?
  end

  new_from_response(client, response, includes)
end