Class: Checkoff::Internal::AsanaEventEnrichment

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#clientAsana::Client (readonly)

sord warn - Asana::Client wasn't able to be resolved to a constant in this project

Returns:

  • (Asana::Client)


193
194
195
# File 'lib/checkoff/internal/asana_event_enrichment.rb', line 193

def client
  @client
end

#projectsCheckoff::Projects (readonly)

Returns:



178
179
180
# File 'lib/checkoff/internal/asana_event_enrichment.rb', line 178

def projects
  @projects
end

#resourcesCheckoff::Resources (readonly)

Returns:



190
191
192
# File 'lib/checkoff/internal/asana_event_enrichment.rb', line 190

def resources
  @resources
end

#sectionsCheckoff::Sections (readonly)

Returns:



181
182
183
# File 'lib/checkoff/internal/asana_event_enrichment.rb', line 181

def sections
  @sections
end

#tasksCheckoff::Tasks (readonly)

Returns:



184
185
186
# File 'lib/checkoff/internal/asana_event_enrichment.rb', line 184

def tasks
  @tasks
end

#workspacesCheckoff::Workspaces (readonly)



187
188
189
# File 'lib/checkoff/internal/asana_event_enrichment.rb', line 187

def workspaces
  @workspaces
end

Instance Method Details

#debugvoid

This method returns an undefined value.

@param message

Parameters:

  • message (Object, nil)


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

Parameters:

  • asana_event (::Hash[untyped, untyped])

Returns:

  • (::Hash[untyped, untyped])


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

Parameters:

  • asana_event (::Hash[untyped, ::Hash[untyped, untyped]])


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

Parameters:

  • asana_event (::Hash[untyped, ::Hash[untyped, untyped]])


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

Parameters:

  • filter (::Hash[String, (String | ::Array[String])])

Returns:

  • (::Hash[String, (String | ::Array[String])])


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

Parameters:

  • filter (::Hash[String, (String | ::Array[String])])

Returns:

  • (String, nil)


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

Parameters:

  • filter (::Hash[String, (String | ::Array[String])])


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

Parameters:

  • filter (::Hash[String, (String | ::Array[String])])


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

Parameters:

  • gid (String)
  • resource_type: (String, nil) (defaults to: nil)

Returns:

  • ([untyped, untyped, untyped, untyped])


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

Parameters:

  • webhook_subscription (::Hash[untyped, untyped], nil)


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

#errorvoid

This method returns an undefined value.

@param message

Parameters:

  • message (Object, nil)


2748
# File 'sig/checkoff.rbs', line 2748

def error: (?Object? message) -> void

#finervoid

This method returns an undefined value.

@param message

Parameters:

  • message (Object, nil)


2760
# File 'sig/checkoff.rbs', line 2760

def finer: (?Object? message) -> void

#infovoid

This method returns an undefined value.

@param message

Parameters:

  • message (Object, nil)


2754
# File 'sig/checkoff.rbs', line 2754

def info: (?Object? message) -> void

#log_levelSymbol

@sg-ignore

Returns:

  • (Symbol)


2763
# File 'sig/checkoff.rbs', line 2763

def log_level: () -> Symbol

#logger::Logger

Returns:

  • (::Logger)


2745
# File 'sig/checkoff.rbs', line 2745

def logger: () -> ::Logger

#warnvoid

This method returns an undefined value.

@param message

Parameters:

  • message (Object, nil)


2751
# File 'sig/checkoff.rbs', line 2751

def warn: (?Object? message) -> void