Sha256: 03e1a0ad83baeb290135282053cda6725e40b3fb629c3839a0c37e3826b726d4

Contents?: true

Size: 1.33 KB

Versions: 21

Compression:

Stored size: 1.33 KB

Contents

class Zendesk2::Client::CreateUserField < Zendesk2::Client::Request
  request_method :post
  request_path { |_| "/user_fields.json" }
  request_body { |r| { "user_field" => r.user_field_params } }

  def self.accepted_attributes
    %w[key type title description position active, regexp_for_validation tag custom_field_options]
  end

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

  def mock
    identity = service.serial_id

    record = {
      "active"                => true,
      "collapsed_for_agents"  => false,
      "created_at"            => Time.now.iso8601,
      "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"            => Time.now.iso8601,
      "url"                   => url_for("/user_fields/#{identity}.json"),
      "visible_in_portal"     => false,
    }.merge(user_field_params)

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

    mock_response("user_field" => record)
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
zendesk2-1.7.5 lib/zendesk2/client/requests/create_user_field.rb
zendesk2-1.7.4 lib/zendesk2/client/requests/create_user_field.rb
zendesk2-1.7.2 lib/zendesk2/client/requests/create_user_field.rb
zendesk2-1.7.1 lib/zendesk2/client/requests/create_user_field.rb
zendesk2-1.7.0 lib/zendesk2/client/requests/create_user_field.rb
zendesk2-1.6.1 lib/zendesk2/client/requests/create_user_field.rb
zendesk2-1.5.17 lib/zendesk2/client/requests/create_user_field.rb
zendesk2-1.5.16 lib/zendesk2/client/requests/create_user_field.rb
zendesk2-1.5.15 lib/zendesk2/client/requests/create_user_field.rb
zendesk2-1.5.14 lib/zendesk2/client/requests/create_user_field.rb
zendesk2-1.5.13 lib/zendesk2/client/requests/create_user_field.rb
zendesk2-1.5.12 lib/zendesk2/client/requests/create_user_field.rb
zendesk2-1.5.11 lib/zendesk2/client/requests/create_user_field.rb
zendesk2-1.5.10 lib/zendesk2/client/requests/create_user_field.rb
zendesk2-1.5.9 lib/zendesk2/client/requests/create_user_field.rb
zendesk2-1.5.8 lib/zendesk2/client/requests/create_user_field.rb
zendesk2-1.5.7 lib/zendesk2/client/requests/create_user_field.rb
zendesk2-1.5.6 lib/zendesk2/client/requests/create_user_field.rb
zendesk2-1.5.5 lib/zendesk2/client/requests/create_user_field.rb
zendesk2-1.5.4 lib/zendesk2/client/requests/create_user_field.rb