Class: ForestAdminDatasourceZendesk::Collections::Ticket

Inherits:
BaseCollection
  • Object
show all
Includes:
CommentsEmbedder, RelationEmbedder, SchemaDefinition, Serializer
Defined in:
lib/forest_admin_datasource_zendesk/collections/ticket.rb,
lib/forest_admin_datasource_zendesk/collections/ticket/serializer.rb,
lib/forest_admin_datasource_zendesk/collections/ticket/comments_embedder.rb,
lib/forest_admin_datasource_zendesk/collections/ticket/relation_embedder.rb,
lib/forest_admin_datasource_zendesk/collections/ticket/schema_definition.rb

Defined Under Namespace

Modules: CommentsEmbedder, RelationEmbedder, SchemaDefinition, Serializer

Constant Summary collapse

ManyToOneSchema =
ForestAdminDatasourceToolkit::Schema::Relations::ManyToOneSchema
ZENDESK_SORTABLE =
{
  'updated_at' => 'updated_at',
  'created_at' => 'created_at',
  'priority' => 'priority',
  'status' => 'status',
  'ticket_type' => 'ticket_type'
}.freeze
COMMENT_THREAD_SCHEMA =
{
  'id' => 'Number',
  'body' => 'String',
  'html_body' => 'String',
  'public' => 'Boolean',
  'author_email' => 'String',
  'author_name' => 'String',
  'created_at' => 'Date'
}.freeze

Constants included from SchemaDefinition

SchemaDefinition::ColumnSchema, SchemaDefinition::DATE_OPS, SchemaDefinition::NUMBER_OPS, SchemaDefinition::Operators, SchemaDefinition::STRING_OPS

Constants inherited from BaseCollection

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

Instance Method Summary collapse

Methods inherited from BaseCollection

#aggregate

Constructor Details

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

Returns a new instance of Ticket.



29
30
31
32
33
34
35
36
# File 'lib/forest_admin_datasource_zendesk/collections/ticket.rb', line 29

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

Instance Method Details

#create(_caller, data) ⇒ Object



47
48
49
50
51
# File 'lib/forest_admin_datasource_zendesk/collections/ticket.rb', line 47

def create(_caller, data)
  payload = build_payload(data, on_create: true)
  created = datasource.client.create_ticket(payload)
  serialize(created)
end

#delete(caller, filter) ⇒ Object



59
60
61
# File 'lib/forest_admin_datasource_zendesk/collections/ticket.rb', line 59

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

#list(caller, filter, projection) ⇒ Object



38
39
40
41
42
43
44
45
# File 'lib/forest_admin_datasource_zendesk/collections/ticket.rb', line 38

def list(caller, filter, projection)
  records = fetch_records(caller, filter)
  emails  = needs_requester_email?(projection) ? bulk_fetch_emails(records) : {}
  rows    = records.map { |t| project(serialize(t, emails), projection) }
  embed_relations(records, rows, projection)
  embed_comments(records, rows) if want_comments?(projection)
  rows
end

#update(caller, filter, patch) ⇒ Object



53
54
55
56
57
# File 'lib/forest_admin_datasource_zendesk/collections/ticket.rb', line 53

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