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
@param
asana_event. -
#enrich_event_resource!(asana_event) ⇒ void
@param
asana_event. -
#enrich_filter(filter) ⇒ ::Hash[String, (String | ::Array[String])]
@param
filter. -
#enrich_filter_parent_gid!(filter) ⇒ void
@param
filter. -
#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
- #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
189 190 191 |
# File 'lib/checkoff/internal/asana_event_enrichment.rb', line 189 def client @client end |
#projects ⇒ Checkoff::Projects (readonly)
174 175 176 |
# File 'lib/checkoff/internal/asana_event_enrichment.rb', line 174 def projects @projects end |
#resources ⇒ Checkoff::Resources (readonly)
186 187 188 |
# File 'lib/checkoff/internal/asana_event_enrichment.rb', line 186 def resources @resources end |
#sections ⇒ Checkoff::Sections (readonly)
177 178 179 |
# File 'lib/checkoff/internal/asana_event_enrichment.rb', line 177 def sections @sections end |
#tasks ⇒ Checkoff::Tasks (readonly)
180 181 182 |
# File 'lib/checkoff/internal/asana_event_enrichment.rb', line 180 def tasks @tasks end |
#workspaces ⇒ Checkoff::Workspaces (readonly)
183 184 185 |
# File 'lib/checkoff/internal/asana_event_enrichment.rb', line 183 def workspaces @workspaces end |
Instance Method Details
#debug ⇒ void
This method returns an undefined value.
@param message
2722 |
# File 'sig/checkoff.rbs', line 2722
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.
@param asana_event
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/checkoff/internal/asana_event_enrichment.rb', line 137 def enrich_event_parent!(asana_event) # @type [Hash{String => String }] 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.
@param asana_event
156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/checkoff/internal/asana_event_enrichment.rb', line 156 def enrich_event_resource!(asana_event) # @type [Hash{String => String}] resource = asana_event['resource'] # @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) ⇒ void
This method returns an undefined value.
@param filter
100 101 102 103 104 105 106 107 |
# File 'lib/checkoff/internal/asana_event_enrichment.rb', line 100 def enrich_filter_parent_gid!(filter) parent_gid = filter['checkoff:parent.gid'] return unless parent_gid.is_a?(String) 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
112 113 114 115 116 117 118 119 120 |
# File 'lib/checkoff/internal/asana_event_enrichment.rb', line 112 def enrich_filter_resource!(filter) resource_gid = filter['checkoff:resource.gid'] return unless resource_gid.is_a?(String) 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
125 126 127 128 129 130 131 132 |
# File 'lib/checkoff/internal/asana_event_enrichment.rb', line 125 def enrich_filter_section!(filter) section_gid = filter['checkoff:fetched.section.gid'] return unless section_gid.is_a?(String) 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) return if webhook_subscription.nil? 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 webhook_subscription['checkoff:enriched:name'] = name if name webhook_subscription['checkoff:enriched:resource_type'] = resource_type if resource_type end |
#error ⇒ void
This method returns an undefined value.
@param message
2713 |
# File 'sig/checkoff.rbs', line 2713
def error: (?Object? message) -> void
|
#finer ⇒ void
This method returns an undefined value.
@param message
2725 |
# File 'sig/checkoff.rbs', line 2725
def finer: (?Object? message) -> void
|
#info ⇒ void
This method returns an undefined value.
@param message
2719 |
# File 'sig/checkoff.rbs', line 2719
def info: (?Object? message) -> void
|
#log_level ⇒ Symbol
2727 |
# File 'sig/checkoff.rbs', line 2727
def log_level: () -> Symbol
|
#logger ⇒ ::Logger
2710 |
# File 'sig/checkoff.rbs', line 2710
def logger: () -> ::Logger
|
#warn ⇒ void
This method returns an undefined value.
@param message
2716 |
# File 'sig/checkoff.rbs', line 2716
def warn: (?Object? message) -> void
|