Class: PdEventV2::Client
- Inherits:
-
Object
- Object
- PdEventV2::Client
- Defined in:
- lib/pd_event_v2/client.rb
Constant Summary collapse
- INITIALIZE_OPTIONS =
%i[ routing_key debug ].freeze
- DEFAULT_ADAPTERS =
[ Faraday::Adapter::NetHttp, Faraday::Adapter::Test, ].freeze
- USER_AGENT =
"PagerDuty Events API v2 Ruby Client #{PdEventV2::VERSION}"
- DEFAULT_API_URL =
'https://events.pagerduty.com/v2/enqueue'
- EVENT_ACTIONS =
%i[ trigger acknowledge resolve ].freeze
- PAYLOAD_KEYS =
{ summary: true, source: true, severity: true, timestamp: false, component: false, group: false, class: false, custom_details: false, }.freeze
Instance Method Summary collapse
-
#initialize(options) ⇒ Client
constructor
A new instance of Client.
Constructor Details
#initialize(options) ⇒ Client
Returns a new instance of Client.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/pd_event_v2/client.rb', line 39 def initialize() unless .is_a?(Hash) raise ArgumentError, "wrong type argument (given: #{}:#{.class}, expected Hash)" end @options = {} INITIALIZE_OPTIONS.each do |key| @options[key] = .delete(key) end raise ArgumentError, ':routing_key is required for initialize' unless @options[:routing_key] [:url] ||= DEFAULT_API_URL @conn = Faraday.new() do |faraday| faraday.request :url_encoded faraday.response :json, content_type: /\bjson\b/ faraday.response :raise_error faraday.response :logger, ::Logger.new(STDOUT), bodies: true if @options[:debug] yield(faraday) if block_given? unless DEFAULT_ADAPTERS.any? { |i| faraday.builder.handlers.include?(i) } faraday.adapter Faraday.default_adapter end end @conn.headers[:user_agent] = USER_AGENT end |