Class: Salopulse::DSN

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dsn_string) ⇒ DSN

Returns a new instance of DSN.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/salopulse/dsn.rb', line 8

def initialize(dsn_string)
  raise Salopulse::Error::InvalidDSN, "DSN boş" if dsn_string.nil? || dsn_string.to_s.empty?

  uri =
    begin
      URI.parse(dsn_string)
    rescue URI::InvalidURIError
      raise Salopulse::Error::InvalidDSN, "geçersiz URL"
    end

  raise Salopulse::Error::InvalidDSN, "scheme http veya https olmalı" unless %w[http https].include?(uri.scheme)
  raise Salopulse::Error::InvalidDSN, "api_key eksik" if uri.userinfo.nil? || uri.userinfo.empty?
  raise Salopulse::Error::InvalidDSN, "host eksik" if uri.host.nil? || uri.host.empty?

  @scheme = uri.scheme
  @api_key = uri.userinfo
  @host = uri.host

  default_port = uri.scheme == "https" ? 443 : 80
  port_part = (uri.port && uri.port != default_port) ? ":#{uri.port}" : ""
  @ingest_url = "#{uri.scheme}://#{uri.host}#{port_part}/api/v1/ingest"
end

Instance Attribute Details

#api_keyObject (readonly)

Returns the value of attribute api_key.



6
7
8
# File 'lib/salopulse/dsn.rb', line 6

def api_key
  @api_key
end

#hostObject (readonly)

Returns the value of attribute host.



6
7
8
# File 'lib/salopulse/dsn.rb', line 6

def host
  @host
end

#ingest_urlObject (readonly)

Returns the value of attribute ingest_url.



6
7
8
# File 'lib/salopulse/dsn.rb', line 6

def ingest_url
  @ingest_url
end

#schemeObject (readonly)

Returns the value of attribute scheme.



6
7
8
# File 'lib/salopulse/dsn.rb', line 6

def scheme
  @scheme
end