Skip to main content

asana/model/
event_response.rs

1use serde::{Serialize, Deserialize};
2/**An *event* is an object representing a change to a resource that was
3observed by an event subscription or delivered asynchronously to
4the target location of an active webhook.
5
6The event may be triggered by a different `user` than the
7subscriber. For example, if user A subscribes to a task and user B
8modified it, the event’s user will be user B. Note: Some events
9are generated by the system, and will have `null` as the user. API
10consumers should make sure to handle this case.
11
12The `resource` that triggered the event may be different from the one
13that the events were requested for or the webhook is subscribed to. For
14example, a subscription to a project will contain events for tasks
15contained within the project.
16
17**Note:** pay close attention to the relationship between the fields
18`Event.action` and `Event.change.action`.
19`Event.action` represents the action taken on the resource
20itself, and `Event.change.action` represents how the information
21within the resource's fields have been modified.
22
23For instance, consider these scenarios:
24
25
26* When at task is added to a project, `Event.action` will be
27`added`, `Event.parent` will be an object with the `id` and
28`type` of the project, and there will be no `change` field.
29
30
31* When an assignee is set on the task, `Event.parent` will be
32`null`, `Event.action` will be `changed`,
33`Event.change.action` will be `changed`, and `new_value` will
34be an object with the user's `id` and `type`.
35
36
37* When a collaborator is added to the task, `Event.parent` will
38be `null`, `Event.action` will be `changed`,
39`Event.change.action` will be `added`, and `added_value` will be
40an object with the user's `id` and `type`.*/
41#[derive(Debug, Clone, Serialize, Deserialize, Default)]
42pub struct EventResponse {
43    ///The type of action taken on the **resource** that triggered the event.  This can be one of `changed`, `added`, `removed`, `deleted`, or `undeleted` depending on the nature of the event.
44    pub action: String,
45    ///Information about the type of change that has occurred. This field is only present when the value of the property `action`, describing the action taken on the **resource**, is `changed`.
46    pub change: serde_json::Value,
47    ///The timestamp when the event occurred.
48    pub created_at: chrono::DateTime<chrono::Utc>,
49    pub parent: serde_json::Value,
50    pub resource: serde_json::Value,
51    ///*Deprecated: Refer to the resource_type of the resource.* The type of the resource that generated the event.
52    #[serde(rename = "type")]
53    pub type_: String,
54    pub user: serde_json::Value,
55}
56impl std::fmt::Display for EventResponse {
57    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
58        write!(f, "{}", serde_json::to_string(self).unwrap())
59    }
60}