Class: Checkoff::Events

Inherits:
Object
  • Object
show all
Extended by:
CacheMethod::ClassMethods
Includes:
Logging
Defined in:
lib/checkoff/events.rb

Overview

Methods related to the Asana events / webhooks APIs

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Logging

#debug, #error, #finer, #info, #logger, #warn

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:), clients: Checkoff::Clients.new(config:), client: clients.client, asana_event_filter_class: Checkoff::Internal::AsanaEventFilter, asana_event_enrichment: Checkoff::Internal::AsanaEventEnrichment.new) ⇒ Events

Returns a new instance of Events.

Parameters:



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/checkoff/events.rb', line 45

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:),
               clients: Checkoff::Clients.new(config:),
               client: clients.client,
               asana_event_filter_class: Checkoff::Internal::AsanaEventFilter,
               asana_event_enrichment: Checkoff::Internal::AsanaEventEnrichment.new)
  @workspaces = workspaces
  @tasks = tasks
  @sections = sections
  @projects = projects
  @client = client
  @asana_event_filter_class = asana_event_filter_class
  @asana_event_enrichment = asana_event_enrichment
end

Class Method Details

.runvoid

This method returns an undefined value.



124
125
126
127
128
129
130
131
132
133
134
# File 'lib/checkoff/events.rb', line 124

def run
  # @sg-ignore
  # @type [String]
  # workspace_name = ARGV[0] || raise('Please pass workspace name as first argument')
  # @sg-ignore
  # @type [String]
  # event_name = ARGV[1] || raise('Please pass event name as second argument')
  # events = Checkoff::Events.new
  # event = events.event_or_raise(workspace_name, event_name)
  # puts "Results: #{event}"
end

Instance Method Details

#enrich_event(asana_event) ⇒ Hash

Add useful info (like resource task names) into an event for human consumption

Parameters:

  • asana_event (Hash)

Returns:

  • (Hash)


78
79
80
# File 'lib/checkoff/events.rb', line 78

def enrich_event(asana_event)
  asana_event_enrichment.enrich_event(asana_event)
end

#enrich_filter(filter) ⇒ Hash{String => String, Array<String>}

Parameters:

  • filter (Hash{String => String, Array<String>})

Returns:

  • (Hash{String => String, Array<String>})


85
86
87
# File 'lib/checkoff/events.rb', line 85

def enrich_filter(filter)
  asana_event_enrichment.enrich_filter(filter)
end

#enrich_webhook_subscription!(webhook_subscription) ⇒ void

This method returns an undefined value.

Parameters:



94
95
96
# File 'lib/checkoff/events.rb', line 94

def enrich_webhook_subscription!(webhook_subscription)
  asana_event_enrichment.enrich_webhook_subscription!(webhook_subscription)
end

#filter_asana_events(filters, asana_events) ⇒ Array<Hash>

Returns The events that should be acted on.

Parameters:

  • filters (Array<Hash>, nil)

    The filters to match against

  • asana_events (Array<Hash>)

    The events that Asana sent

Returns:

  • (Array<Hash>)

    The events that should be acted on



67
68
69
70
# File 'lib/checkoff/events.rb', line 67

def filter_asana_events(filters, asana_events)
  asana_event_filter = @asana_event_filter_class.new(filters:)
  asana_events.select { |event| asana_event_filter.matches?(event) }
end