Class: Condux::Dsn

Inherits:
Object
  • Object
show all
Defined in:
lib/condux/dsn.rb

Overview

A parsed DSN: the relay endpoint, the project id path segment, and the public key.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(endpoint, project_id, public_key) ⇒ Dsn

Returns a new instance of Dsn.



21
22
23
24
25
# File 'lib/condux/dsn.rb', line 21

def initialize(endpoint, project_id, public_key)
  @endpoint = endpoint
  @project_id = project_id
  @public_key = public_key
end

Instance Attribute Details

#endpointObject (readonly)

Returns the value of attribute endpoint.



8
9
10
# File 'lib/condux/dsn.rb', line 8

def endpoint
  @endpoint
end

#project_idObject (readonly)

Returns the value of attribute project_id.



8
9
10
# File 'lib/condux/dsn.rb', line 8

def project_id
  @project_id
end

#public_keyObject (readonly)

Returns the value of attribute public_key.



8
9
10
# File 'lib/condux/dsn.rb', line 8

def public_key
  @public_key
end

Class Method Details

.parse(dsn) ⇒ Object



10
11
12
13
14
15
16
17
18
19
# File 'lib/condux/dsn.rb', line 10

def self.parse(dsn)
  uri = URI(dsn)
  if uri.user.nil? || uri.user.empty? || uri.host.nil?
    raise ArgumentError, "Condux: DSN must be scheme://<key>@<host>/<projectId>"
  end

  endpoint = "#{uri.scheme}://#{uri.host}"
  endpoint += ":#{uri.port}" if uri.port && ![80, 443].include?(uri.port)
  new(endpoint, uri.path.sub(%r{\A/}, ""), uri.user)
end

Instance Method Details

#store_urlObject

The Sentry store endpoint an event is POSTed to.



28
29
30
# File 'lib/condux/dsn.rb', line 28

def store_url
  "#{endpoint}/api/#{project_id}/store/"
end