Class: TrelloTracker

Inherits:
Object
  • Object
show all
Includes:
Trello, TrelloAuthorize
Defined in:
lib/trello_effort_tracker/trello_tracker.rb

Instance Method Summary collapse

Methods included from TrelloAuthorize

#authorize_on_trello

Methods included from TrelloConfiguration

#authorization_params_from_config_file, #tracker_username

Constructor Details

#initialize(custom_config_params = {}) ⇒ TrelloTracker

Returns a new instance of TrelloTracker.



7
8
9
10
# File 'lib/trello_effort_tracker/trello_tracker.rb', line 7

def initialize(custom_config_params = {})
  authorize_on_trello(custom_config_params)
  tracker_username(custom_config_params[:tracker_username])
end

Instance Method Details

#track(starting_date = Date.today) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/trello_effort_tracker/trello_tracker.rb', line 12

def track(starting_date=Date.today)
  notifications = tracker.notifications_from(starting_date)

  oldest, latest = boundary_dates_in(notifications)
  Trello.logger.info "Processing #{notifications.size} tracking notifications (from #{oldest} to #{latest}) starting from #{starting_date}..."

  notifications.each do |notification|
    tracking = TrackingFactory.build_from(notification)
    begin
      tracked_card = TrackedCard.update_or_create_with(notification.card)
      tracked_card.add!(tracking)
      Trello.logger.info tracking

    rescue StandardError => e
      Trello.logger.warn "skipping tracking: #{e.message}".color(:magenta)
      Trello.logger.debug "#{e.backtrace}"
    end
  end
  Trello.logger.info "Done tracking cards!".color(:green)
end