Module: ZendeskAPI::Read::ClassMethods
- Defined in:
- lib/zendesk_api/actions.rb
Instance Method Summary collapse
-
#find(client, options = {}, &block) ⇒ Object
Finds, returning nil if it fails.
-
#find!(client, options = {}) ⇒ Object
Finds a resource by an id and any options passed in.
Instance Method Details
#find(client, options = {}, &block) ⇒ Object
Finds, returning nil if it fails
130 131 132 133 134 |
# File 'lib/zendesk_api/actions.rb', line 130 def find(client, = {}, &block) find!(client, , &block) rescue ZendeskAPI::Error::ClientError => e 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.
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, = {}) @client = client # so we can use client.logger in rescue raise ArgumentError, "No :id given" unless [:id] || ["id"] || ancestors.include?(SingularResource) association = .delete(:association) || Association.new(:class => self) includes = Array([:include]) [:include] = includes.join(",") if includes.any? response = client.connection.get(association.generate_path()) do |req| req.params = yield req if block_given? end new_from_response(client, response, includes) end |