Class: ForestAdminDatasourceZendesk::Collections::Ticket
- Inherits:
-
BaseCollection
- Object
- ForestAdminDatasourceToolkit::Collection
- BaseCollection
- ForestAdminDatasourceZendesk::Collections::Ticket
- 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
- ENUM_STATUS =
%w[new open pending hold solved closed].freeze
- ENUM_PRIORITY =
%w[low normal high urgent].freeze
- ENUM_TYPE =
%w[problem incident question task].freeze
- 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
- #create(_caller, data) ⇒ Object
- #delete(caller, filter) ⇒ Object
-
#initialize(datasource, custom_fields: []) ⇒ Ticket
constructor
A new instance of Ticket.
- #list(caller, filter, projection) ⇒ Object
- #update(caller, filter, patch) ⇒ Object
Methods inherited from BaseCollection
Constructor Details
#initialize(datasource, custom_fields: []) ⇒ Ticket
Returns a new instance of Ticket.
33 34 35 36 37 38 39 40 |
# File 'lib/forest_admin_datasource_zendesk/collections/ticket.rb', line 33 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
51 52 53 54 55 |
# File 'lib/forest_admin_datasource_zendesk/collections/ticket.rb', line 51 def create(_caller, data) payload = build_payload(data, on_create: true) created = datasource.client.create_ticket(payload) serialize(created) end |
#delete(caller, filter) ⇒ Object
63 64 65 |
# File 'lib/forest_admin_datasource_zendesk/collections/ticket.rb', line 63 def delete(caller, filter) ids_for(caller, filter).each { |id| datasource.client.delete_ticket(id) } end |
#list(caller, filter, projection) ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/forest_admin_datasource_zendesk/collections/ticket.rb', line 42 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) } (records, rows, projection) (records, rows) if want_comments?(projection) rows end |
#update(caller, filter, patch) ⇒ Object
57 58 59 60 61 |
# File 'lib/forest_admin_datasource_zendesk/collections/ticket.rb', line 57 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 |