Class: Checkoff::Events

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

Overview

Methods related to the Asana events / webhooks APIs

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config: Checkoff::Internal::ConfigLoader.load(:asana), workspaces: Checkoff::Workspaces.new(config: config), clients: Checkoff::Clients.new(config: config), client: clients.client, asana_event_filter_class: Checkoff::Internal::AsanaEventFilter) ⇒ Events

Returns a new instance of Events.

Parameters:

  • config (Hash) (defaults to: Checkoff::Internal::ConfigLoader.load(:asana))
  • workspaces (Checkoff::Workspaces) (defaults to: Checkoff::Workspaces.new(config: config))
  • clients (Checkoff::Clients) (defaults to: Checkoff::Clients.new(config: config))
  • client (Asana::Client) (defaults to: clients.client)
  • asana_event_filter_class (Class<Checkoff::Internal::AsanaEventFilter>) (defaults to: Checkoff::Internal::AsanaEventFilter)


38
39
40
41
42
43
44
45
46
# File 'lib/checkoff/events.rb', line 38

def initialize(config: Checkoff::Internal::ConfigLoader.load(:asana),
               workspaces: Checkoff::Workspaces.new(config: config),
               clients: Checkoff::Clients.new(config: config),
               client: clients.client,
               asana_event_filter_class: Checkoff::Internal::AsanaEventFilter)
  @workspaces = workspaces
  @client = client
  @asana_event_filter_class = asana_event_filter_class
end

Class Method Details

.runvoid

This method returns an undefined value.



69
70
71
72
73
74
75
76
77
78
79
# File 'lib/checkoff/events.rb', line 69

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

#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



52
53
54
55
# File 'lib/checkoff/events.rb', line 52

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