Class: ExceptionNotifier::AsanaNotifier

Inherits:
BaseNotifier
  • Object
show all
Includes:
AsanaExceptionNotifier::ApplicationHelper
Defined in:
lib/asana_exception_notifier/classes/asana.rb

Overview

module that is used for formatting numbers using metrics

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from AsanaExceptionNotifier::ApplicationHelper

add_files_to_zip, archive_files, ensure_thread_running, escape, execute_with_rescue, expanded_path, extract_body, force_utf8_encoding, get_extension_and_name_from_file, get_hash_rows, get_table_headers, get_table_rows, hash_to_html_attributes, inspect_value, log_bactrace, log_exception, logger, mount_table_for_hash, path_is_a_template?, permitted_options, prepare_archive_creation, rails_logger, remove_blank, rescue_interrupt, root, run_new_thread, set_fieldset_key, split_archive, tempfile_details, template_dir, template_path_exist

Methods included from AsanaExceptionNotifier::HeredocHelper

link_helper, mount_table

Constructor Details

#initialize(options) ⇒ void

Initializes the instance with the options from the configuration and parses the options

Parameters:

  • options (options)

    The options that can be set in the configuration block

  • params (Hash)

    a customizable set of options

See Also:

  • #parse_options


56
57
58
59
60
# File 'lib/asana_exception_notifier/classes/asana.rb', line 56

def initialize(options)
  super
  @initial_options = options.symbolize_keys.reject { |_key, value| value.blank? }
  parse_options(@initial_options)
end

Instance Attribute Details

#default_optionsHash (readonly)

The resulting options after merging with permitted_options and with initial_options

Returns:

  • (Hash)

    The permitted_options that are merged with initial options ( blank values are filtered )



20
21
22
# File 'lib/asana_exception_notifier/classes/asana.rb', line 20

def default_options
  @default_options
end

#initial_optionsHash (readonly)

The initial options that the middleware was configured with

Returns:

  • (Hash)

    THe initial options that the notifier received ( blank values are filtered )



16
17
18
# File 'lib/asana_exception_notifier/classes/asana.rb', line 16

def initial_options
  @initial_options
end

Instance Method Details

#active?Boolean

Method that is used by the ExceptionNotifier gem to check if this notifier can be activated. The method checks if the asana api key and workspace ID were provided

Returns:

  • (Boolean)

    returns true if the asana api key and the workspace ID were provided in the configuration, otherwise false



146
147
148
# File 'lib/asana_exception_notifier/classes/asana.rb', line 146

def active?
  asana_api_key.present? && workspace.present?
end

#asana_api_keyString?

Method that is used to fetch the Asana api key from the default_options

Returns:

  • (String, nil)

    returns the asana api key if was provided in configuration, or nil otherwise



117
118
119
# File 'lib/asana_exception_notifier/classes/asana.rb', line 117

def asana_api_key
  @default_options.fetch(:asana_api_key, nil)
end

#asana_clientAsana::Client

Returns the asana client that will be used to connect to Asana API and sets the configuration for the client

Returns:

  • (Asana::Client)

    Returns the client used for connecting to Asana API’s

See Also:



66
67
68
69
70
71
72
73
# File 'lib/asana_exception_notifier/classes/asana.rb', line 66

def asana_client
  @asana_client = Asana::Client.new do |config|
    config.authentication :access_token, asana_api_key
    config.debug_mode
    config.faraday_adapter :typhoeus
    faraday_configuration(config)
  end
end

#call(exception, options = {}) ⇒ void

This method returns an undefined value.

When a exception is caught , this method will be called to publish to Asana the exception details In order not to block the main thread, while we are parsing the exception, and constructing the template date, and connecting to asana, this will spawn a new thread to ensure that the processing of the exception is deferred from the main thread. This method will also create the asana task after the processing of the exception and all the other data is gathered by the AsanaExceptionNotifier::ErrorPage class

Parameters:

  • exception (Exception)

    The exception that was caught by the middleware

  • options (Hash) (defaults to: {})

    Additional options that the middleware can send ( Default : {})

See Also:

  • AsanaExceptionNotifier::ApplicationHelper#ensure_thread_running
  • AsanaExceptionNotifier::ApplicationHelper#execute_with_rescue
  • AsanaExceptionNotifier::ErrorPage#new
  • #create_asana_task


105
106
107
108
109
110
111
112
# File 'lib/asana_exception_notifier/classes/asana.rb', line 105

def call(exception, options = {})
  ensure_thread_running do
    execute_with_rescue do
      error_page = AsanaExceptionNotifier::ErrorPage.new(template_path, exception, options)
      create_asana_task(error_page) if active?
    end
  end
end

#faraday_configuration(config) ⇒ void

This method returns an undefined value.

Returns the asana client that will be used to connect to Asana API

Parameters:

  • config (Asana::Configuration)

    The configuration object that will be used to set the faraday adapter options for connecting to API’s



79
80
81
82
83
84
85
86
# File 'lib/asana_exception_notifier/classes/asana.rb', line 79

def faraday_configuration(config)
  config.configure_faraday do |conn|
    conn.request :url_encoded
    conn.use :instrumentation
    conn.response :logger
    conn.response :follow_redirects
  end
end

#notesString?

Method that is used to fetch the notes from the default_options

Returns:

  • (String, nil)

    returns the notes if they were provided in configuration, or nil otherwise



131
132
133
# File 'lib/asana_exception_notifier/classes/asana.rb', line 131

def notes
  @default_options.fetch(:notes, nil)
end

#task_nameString?

Method that is used to fetch the task name from the default_options

Returns:

  • (String, nil)

    returns the task name if was were provided in configuration, or nil otherwise



138
139
140
# File 'lib/asana_exception_notifier/classes/asana.rb', line 138

def task_name
  @default_options.fetch(:name, nil)
end

#template_pathString?

Method that retrieves the template_path for rendering the exception details

Returns:

  • (String, nil)

    returns the template_path if was were provided in configuration, or nil otherwise



153
154
155
# File 'lib/asana_exception_notifier/classes/asana.rb', line 153

def template_path
  @default_options.fetch(:template_path, nil)
end

#workspaceString?

Method that is used to fetch the workspace ID from the default_options

Returns:

  • (String, nil)

    returns the workspace ID if was provided in configuration, or nil otherwise



124
125
126
# File 'lib/asana_exception_notifier/classes/asana.rb', line 124

def workspace
  @default_options.fetch(:workspace, nil)
end