Class: Zendesk2::DestroyUser

Inherits:
Object
  • Object
show all
Includes:
Request
Defined in:
lib/zendesk2/destroy_user.rb

Instance Attribute Summary

Attributes included from Request

#params

Instance Method Summary collapse

Methods included from Request

#call, cistern_included, #data, #delete!, #error!, #find!, #html_url_for, included, #mock_response, #page, #page_params!, #page_params?, #pluralize, #real, #real_request, #request_body, #request_params, #request_path, #resources, #response, #timestamp, #url_for

Instance Method Details

#mockObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/zendesk2/destroy_user.rb', line 12

def mock
  ticket_count = cistern.data[:tickets].values.select { |t| t['requester_id'].to_i == user_id }.size

  if ticket_count < 1
    cistern.data[:identities].each { |k, v| cistern.data[:identities].delete(k) if v['user_id'] == user_id }

    mock_response('user' => delete!(:users, user_id))
  else
    error!(:invalid, 'details' => {
             'base' => [{
               'type'        => "User is requester on #{ticket_count} ticket(s) that are not closed.",
               'description' => "Base User is requester on #{ticket_count} ticket(s) that are not closed.",
             },],
           })
  end
end

#user_idObject



8
9
10
# File 'lib/zendesk2/destroy_user.rb', line 8

def user_id
  @_user_id ||= params.fetch('user').fetch('id').to_i
end