Module: ZendeskAPI::Read
- Included in:
- ReadResource, Resource, TicketMetric, Topic::TopicComment, User::TopicComment
- Defined in:
- lib/zendesk_api/actions.rb
Instance Method Summary (collapse)
-
- (Object) find(client, options = {})
Finds, returning nil if it fails.
-
- (Object) find!(client, options = {})
Finds a resource by an id and any options passed in.
Instance Method Details
- (Object) find(client, options = {})
Finds, returning nil if it fails
99 100 101 102 103 |
# File 'lib/zendesk_api/actions.rb', line 99 def find(client, = {}) find!(client, ) rescue ZendeskAPI::Error::ClientError => e nil end |
- (Object) find!(client, options = {})
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.
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/zendesk_api/actions.rb', line 80 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 = end new(client, response.body[singular_resource_name]).tap do |resource| resource.set_includes(resource, includes, response.body) end end |