Class: Zendesk2::CreateUserField

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

Instance Attribute Summary

Attributes included from Request

#params

Class Method Summary collapse

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

Class Method Details

.accepted_attributesObject



9
10
11
# File 'lib/zendesk2/create_user_field.rb', line 9

def self.accepted_attributes
  %w(key type title description position active regexp_for_validation tag custom_field_options)
end

Instance Method Details

#mockObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/zendesk2/create_user_field.rb', line 17

def mock
  identity = cistern.serial_id

  record = {
    'active'                => true,
    'collapsed_for_agents'  => false,
    'created_at'            => timestamp,
    'description'           => params['title'],
    'editable_in_portal'    => false,
    'id'                    => identity,
    'position'              => 9999,
    'regexp_for_validation' => '',
    'removable'             => true,
    'required'              => false,
    'required_in_portal'    => false,
    'tag'                   => '',
    'title_in_portal'       => params['title'],
    'updated_at'            => timestamp,
    'url'                   => url_for("/user_fields/#{identity}.json"),
    'visible_in_portal'     => false,
  }.merge(user_field_params)

  cistern.data[:user_fields][identity] = record

  mock_response('user_field' => record)
end

#user_field_paramsObject



13
14
15
# File 'lib/zendesk2/create_user_field.rb', line 13

def user_field_params
  Cistern::Hash.slice(params.fetch('user_field'), *self.class.accepted_attributes)
end