Class: Salopulse::DSN
- Inherits:
-
Object
- Object
- Salopulse::DSN
- Defined in:
- lib/salopulse/dsn.rb
Instance Attribute Summary collapse
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#ingest_url ⇒ Object
readonly
Returns the value of attribute ingest_url.
-
#scheme ⇒ Object
readonly
Returns the value of attribute scheme.
Instance Method Summary collapse
-
#initialize(dsn_string) ⇒ DSN
constructor
A new instance of DSN.
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_key ⇒ Object (readonly)
Returns the value of attribute api_key.
6 7 8 |
# File 'lib/salopulse/dsn.rb', line 6 def api_key @api_key end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
6 7 8 |
# File 'lib/salopulse/dsn.rb', line 6 def host @host end |
#ingest_url ⇒ Object (readonly)
Returns the value of attribute ingest_url.
6 7 8 |
# File 'lib/salopulse/dsn.rb', line 6 def ingest_url @ingest_url end |
#scheme ⇒ Object (readonly)
Returns the value of attribute scheme.
6 7 8 |
# File 'lib/salopulse/dsn.rb', line 6 def scheme @scheme end |