Class: Checkoff::Internal::AsanaEventEnrichment
- Inherits:
-
Object
- Object
- Checkoff::Internal::AsanaEventEnrichment
- Includes:
- Logging
- Defined in:
- lib/checkoff/internal/asana_event_enrichment.rb,
sig/checkoff.rbs
Overview
Add useful info (like resource task names) into an Asana event/event filters/webhook subscription for human consumption
Instance Attribute Summary collapse
-
#client ⇒ Asana::Client
readonly
sord warn - Asana::Client wasn't able to be resolved to a constant in this project.
- #projects ⇒ Checkoff::Projects readonly
- #resources ⇒ Checkoff::Resources readonly
- #sections ⇒ Checkoff::Sections readonly
- #tasks ⇒ Checkoff::Tasks readonly
- #workspaces ⇒ Checkoff::Workspaces readonly
Instance Method Summary collapse
-
#debug ⇒ void
@param
message. -
#enrich_event(asana_event) ⇒ ::Hash[untyped, untyped]
Add useful info (like resource task names) into an event for human consumption.
-
#enrich_event_parent!(asana_event) ⇒ void
sord warn - "'resource'" does not appear to be a type @param
asana_event. -
#enrich_event_resource!(asana_event) ⇒ void
sord warn - "'resource'" does not appear to be a type @param
asana_event. -
#enrich_filter(filter) ⇒ ::Hash[String, (String | ::Array[String])]
@param
filter. -
#enrich_filter_parent_gid!(filter) ⇒ String?
@sg-ignore.
-
#enrich_filter_resource!(filter) ⇒ void
@param
filter. -
#enrich_filter_section!(filter) ⇒ void
@param
filter. -
#enrich_gid(gid, resource_type: nil) ⇒ [untyped, untyped, untyped, untyped]
sord warn - "[String" does not appear to be a type sord warn - "nil]" does not appear to be a type sord warn - "[String" does not appear to be a type sord warn - "nil]" does not appear to be a type Attempt to look up a GID in situations where we don't have a resource type provided, and returns the name of the resource.
-
#enrich_webhook_subscription!(webhook_subscription) ⇒ void
@param
webhook_subscription— Hash of the request made to webhook POST endpoint - https://app.asana.com/api/1.0/webhooks https://developers.asana.com/reference/createwebhook. -
#error ⇒ void
@param
message. -
#finer ⇒ void
@param
message. -
#info ⇒ void
@param
message. -
#initialize(config: Checkoff::Internal::ConfigLoader.load(:asana), workspaces: Checkoff::Workspaces.new(config:), tasks: Checkoff::Tasks.new(config:), sections: Checkoff::Sections.new(config:), projects: Checkoff::Projects.new(config:), resources: Checkoff::Resources.new(config:), clients: Checkoff::Clients.new(config:), client: clients.client) ⇒ Object
constructor
sord warn - Asana::Client wasn't able to be resolved to a constant in this project @param
config. -
#log_level ⇒ Symbol
@sg-ignore.
- #logger ⇒ ::Logger
-
#warn ⇒ void
@param
message.
Constructor Details
#initialize(config: Checkoff::Internal::ConfigLoader.load(:asana), workspaces: Checkoff::Workspaces.new(config:), tasks: Checkoff::Tasks.new(config:), sections: Checkoff::Sections.new(config:), projects: Checkoff::Projects.new(config:), resources: Checkoff::Resources.new(config:), clients: Checkoff::Clients.new(config:), client: clients.client) ⇒ Object
sord warn - Asana::Client wasn't able to be resolved to a constant in this project
@param config
@param workspaces
@param tasks
@param sections
@param projects
@param resources
@param clients
@param client
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/checkoff/internal/asana_event_enrichment.rb', line 25 def initialize(config: Checkoff::Internal::ConfigLoader.load(:asana), workspaces: Checkoff::Workspaces.new(config:), tasks: Checkoff::Tasks.new(config:), sections: Checkoff::Sections.new(config:), projects: Checkoff::Projects.new(config:), resources: Checkoff::Resources.new(config:), clients: Checkoff::Clients.new(config:), client: clients.client) @workspaces = workspaces @tasks = tasks @sections = sections @projects = projects @resources = resources @client = client end |
Instance Attribute Details
#client ⇒ Asana::Client (readonly)
sord warn - Asana::Client wasn't able to be resolved to a constant in this project
193 194 195 |
# File 'lib/checkoff/internal/asana_event_enrichment.rb', line 193 def client @client end |
#projects ⇒ Checkoff::Projects (readonly)
178 179 180 |
# File 'lib/checkoff/internal/asana_event_enrichment.rb', line 178 def projects @projects end |
#resources ⇒ Checkoff::Resources (readonly)
190 191 192 |
# File 'lib/checkoff/internal/asana_event_enrichment.rb', line 190 def resources @resources end |
#sections ⇒ Checkoff::Sections (readonly)
181 182 183 |
# File 'lib/checkoff/internal/asana_event_enrichment.rb', line 181 def sections @sections end |
#tasks ⇒ Checkoff::Tasks (readonly)
184 185 186 |
# File 'lib/checkoff/internal/asana_event_enrichment.rb', line 184 def tasks @tasks end |
#workspaces ⇒ Checkoff::Workspaces (readonly)
187 188 189 |
# File 'lib/checkoff/internal/asana_event_enrichment.rb', line 187 def workspaces @workspaces end |
Instance Method Details
#debug ⇒ void
This method returns an undefined value.
@param message
2757 |
# File 'sig/checkoff.rbs', line 2757
def debug: (?Object? message) -> void
|
#enrich_event(asana_event) ⇒ ::Hash[untyped, untyped]
Add useful info (like resource task names) into an event for human consumption
@param asana_event
47 48 49 50 51 52 53 |
# File 'lib/checkoff/internal/asana_event_enrichment.rb', line 47 def enrich_event(asana_event) finer { "Enriching event: #{asana_event}" } asana_event = asana_event.dup enrich_event_resource!(asana_event) enrich_event_parent!(asana_event) asana_event end |
#enrich_event_parent!(asana_event) ⇒ void
This method returns an undefined value.
sord warn - "'resource'" does not appear to be a type
@param asana_event
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/checkoff/internal/asana_event_enrichment.rb', line 140 def enrich_event_parent!(asana_event) # @type [Hash{String => String }] # @sg-ignore parent = asana_event['parent'] return unless parent # @type [String] resource_type = parent.fetch('resource_type') # @type [String] gid = parent.fetch('gid') name, _resource_type = enrich_gid(gid, resource_type:) parent['checkoff:enriched:name'] = name if name nil end |
#enrich_event_resource!(asana_event) ⇒ void
This method returns an undefined value.
sord warn - "'resource'" does not appear to be a type
@param asana_event
160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/checkoff/internal/asana_event_enrichment.rb', line 160 def enrich_event_resource!(asana_event) # @type [Hash{String => String}] resource = T.cast(asana_event['resource'], T::Hash[String, String]) # @type [String] resource_type = resource.fetch('resource_type') # @type [String] gid = resource.fetch('gid') name, _resource_type = enrich_gid(gid, resource_type:) resource['checkoff:enriched:name'] = name if name nil end |
#enrich_filter(filter) ⇒ ::Hash[String, (String | ::Array[String])]
@param filter
58 59 60 61 62 63 64 |
# File 'lib/checkoff/internal/asana_event_enrichment.rb', line 58 def enrich_filter(filter) filter = filter.dup enrich_filter_section!(filter) enrich_filter_resource!(filter) enrich_filter_parent_gid!(filter) filter end |
#enrich_filter_parent_gid!(filter) ⇒ String?
@sg-ignore
@param filter
101 102 103 104 105 106 107 108 109 |
# File 'lib/checkoff/internal/asana_event_enrichment.rb', line 101 def enrich_filter_parent_gid!(filter) parent_gid = filter['checkoff:parent.gid'] return unless parent_gid # @sg-ignore name, resource_type = enrich_gid(parent_gid) filter['checkoff:enriched:parent.name'] = name if name filter['checkoff:enriched:parent.resource_type'] = resource_type if resource_type end |
#enrich_filter_resource!(filter) ⇒ void
This method returns an undefined value.
@param filter
114 115 116 117 118 119 120 121 122 123 |
# File 'lib/checkoff/internal/asana_event_enrichment.rb', line 114 def enrich_filter_resource!(filter) resource_gid = filter['checkoff:resource.gid'] return unless resource_gid # @sg-ignore task = tasks.task_by_gid(resource_gid) task_name = task&.name filter['checkoff:enriched:resource.name'] = task_name if task_name end |
#enrich_filter_section!(filter) ⇒ void
This method returns an undefined value.
@param filter
128 129 130 131 132 133 134 135 |
# File 'lib/checkoff/internal/asana_event_enrichment.rb', line 128 def enrich_filter_section!(filter) section_gid = T.cast(filter['checkoff:fetched.section.gid'], T.nilable(String)) return unless section_gid section = sections.section_by_gid(section_gid) name = section&.name filter['checkoff:enriched:fetched.section.name'] = name if name end |
#enrich_gid(gid, resource_type: nil) ⇒ [untyped, untyped, untyped, untyped]
sord warn - "[String" does not appear to be a type sord warn - "nil]" does not appear to be a type sord warn - "[String" does not appear to be a type sord warn - "nil]" does not appear to be a type Attempt to look up a GID in situations where we don't have a resource type provided, and returns the name of the resource.
@param gid
@param resource_type
92 93 94 95 |
# File 'lib/checkoff/internal/asana_event_enrichment.rb', line 92 def enrich_gid(gid, resource_type: nil) resource, resource_type = resources.resource_by_gid(gid, resource_type:) [resource&.name, resource_type] end |
#enrich_webhook_subscription!(webhook_subscription) ⇒ void
This method returns an undefined value.
@param webhook_subscription — Hash of the request made to webhook POST endpoint - https://app.asana.com/api/1.0/webhooks https://developers.asana.com/reference/createwebhook
71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/checkoff/internal/asana_event_enrichment.rb', line 71 def enrich_webhook_subscription!(webhook_subscription) webhook_subscription&.fetch('filters', nil)&.map! do |filter| enrich_filter(filter) end resource = webhook_subscription&.fetch('resource', nil) name, resource_type = enrich_gid(resource) if resource # @sg-ignore webhook_subscription['checkoff:enriched:name'] = name if name # @sg-ignore webhook_subscription['checkoff:enriched:resource_type'] = resource_type if resource_type end |
#error ⇒ void
This method returns an undefined value.
@param message
2748 |
# File 'sig/checkoff.rbs', line 2748
def error: (?Object? message) -> void
|
#finer ⇒ void
This method returns an undefined value.
@param message
2760 |
# File 'sig/checkoff.rbs', line 2760
def finer: (?Object? message) -> void
|
#info ⇒ void
This method returns an undefined value.
@param message
2754 |
# File 'sig/checkoff.rbs', line 2754
def info: (?Object? message) -> void
|
#log_level ⇒ Symbol
@sg-ignore
2763 |
# File 'sig/checkoff.rbs', line 2763
def log_level: () -> Symbol
|
#logger ⇒ ::Logger
2745 |
# File 'sig/checkoff.rbs', line 2745
def logger: () -> ::Logger
|
#warn ⇒ void
This method returns an undefined value.
@param message
2751 |
# File 'sig/checkoff.rbs', line 2751
def warn: (?Object? message) -> void
|