Class: Trellodon::Executor

Inherits:
Object
  • Object
show all
Defined in:
lib/trellodon/executor.rb

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ Executor

Returns a new instance of Executor.



8
9
10
11
12
13
14
15
16
17
# File 'lib/trellodon/executor.rb', line 8

def initialize(opts)
  @api_key = opts.fetch(:api_key)
  @api_token = opts.fetch(:api_token)
  @formatter = opts.fetch(:formatter)
  @logger = opts.fetch(:logger) { Config.logger }
  @scheduler = opts.fetch(:scheduler)
  check_credentials!

  @client = Client.new(api_key: @api_key, api_token: @api_token)
end

Instance Method Details

#download(board_pointer) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/trellodon/executor.rb', line 19

def download(board_pointer)
  extract_board_id(board_pointer)

  startup_time = Time.now
  logger.debug "Fetching board 🚀️️"
  board = scheduler.post do
    client.fetch_board(board_id).tap { formatter.board_added(_1) }
  end.value

  logger.debug "Fetching #{board.card_ids.size} cards from the board with comments and attachments 🐢"
  board.card_ids.map do |card_id|
    scheduler.post do
      client.fetch_card(card_id).tap { formatter.card_added(_1) }
    end
  end.map(&:value)

  formatter.finish
  logger.debug "All Trello API requests finished in #{(Time.now - startup_time).to_i} seconds ⌛"
end