Class: ForestAdminDatasourceZendesk::Collections::User

Inherits:
BaseCollection
  • Object
show all
Includes:
Searchable
Defined in:
lib/forest_admin_datasource_zendesk/collections/user.rb

Constant Summary collapse

ManyToOneSchema =
ForestAdminDatasourceToolkit::Schema::Relations::ManyToOneSchema
OneToManySchema =
ForestAdminDatasourceToolkit::Schema::Relations::OneToManySchema
ENUM_ROLE =
%w[end-user agent admin].freeze
BASE_ATTR_KEYS =
%w[id email name role phone organization_id time_zone locale verified suspended
created_at updated_at].freeze
ZENDESK_SORTABLE =
{
  'created_at' => 'created_at',
  'updated_at' => 'updated_at',
  'name' => 'name'
}.freeze

Constants inherited from BaseCollection

BaseCollection::ColumnSchema, BaseCollection::DATE_OPS, BaseCollection::Leaf, BaseCollection::NUMBER_OPS, BaseCollection::Operators, BaseCollection::STRING_OPS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Searchable

#list

Methods inherited from BaseCollection

#aggregate

Constructor Details

#initialize(datasource, custom_fields: []) ⇒ User

Returns a new instance of User.



20
21
22
23
24
25
26
27
# File 'lib/forest_admin_datasource_zendesk/collections/user.rb', line 20

def initialize(datasource, custom_fields: [])
  super(datasource, 'ZendeskUser')
  define_schema
  define_relations
  @custom_fields = add_custom_fields(custom_fields)
  enable_search
  enable_count
end

Instance Attribute Details

#custom_fieldsObject (readonly)

Returns the value of attribute custom_fields.



6
7
8
# File 'lib/forest_admin_datasource_zendesk/collections/user.rb', line 6

def custom_fields
  @custom_fields
end

Instance Method Details

#create(_caller, data) ⇒ Object



29
30
31
32
33
# File 'lib/forest_admin_datasource_zendesk/collections/user.rb', line 29

def create(_caller, data)
  payload = build_payload(data)
  created = datasource.client.create_user(payload)
  serialize(created)
end

#delete(caller, filter) ⇒ Object



41
42
43
# File 'lib/forest_admin_datasource_zendesk/collections/user.rb', line 41

def delete(caller, filter)
  ids_for(caller, filter).each { |id| datasource.client.delete_user(id) }
end

#update(caller, filter, patch) ⇒ Object



35
36
37
38
39
# File 'lib/forest_admin_datasource_zendesk/collections/user.rb', line 35

def update(caller, filter, patch)
  ids = ids_for(caller, filter)
  payload = build_payload(patch)
  ids.each { |id| datasource.client.update_user(id, payload) }
end