Module: FreshdeskAPI::Read

Included in:
Resource
Defined in:
lib/freshdesk_api/actions.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(klass) ⇒ Object



13
14
15
# File 'lib/freshdesk_api/actions.rb', line 13

def self.extended(klass)
  klass.send(:include, ResponseHandler)
end

Instance Method Details

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

Finds, returning nil if it fails



35
36
37
38
39
# File 'lib/freshdesk_api/actions.rb', line 35

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

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

Finds a resource by an id and any options passed in

Parameters:

  • client (Client)

    The Client object to be used

  • option (Hash)

    Any additional GET parameters to be added

Raises:

  • (ArgumentError)


20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/freshdesk_api/actions.rb', line 20

def find!(client, options = {})
  @client = client # so we can use client.logger in rescue
  raise ArgumentError, 'No :id given' unless options[:id]

  path = api_url(options) + "/#{options[:id]}"

  response = client.make_request!(path, :get)

  new(@client).tap do |resource|
    resource.attributes.merge!(options)
    resource.handle_response(response)
  end
end