Class: Sentry::DSN
Constant Summary collapse
- PORT_MAP =
{ 'http' => 80, 'https' => 443 }.freeze
- REQUIRED_ATTRIBUTES =
%w(host path public_key project_id).freeze
Instance Method Summary collapse
- #envelope_endpoint ⇒ Object
-
#initialize(dsn_string) ⇒ DSN
constructor
A new instance of DSN.
- #server ⇒ Object
- #to_s ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(dsn_string) ⇒ DSN
Returns a new instance of DSN.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/sentry/dsn.rb', line 10 def initialize(dsn_string) @raw_value = dsn_string uri = URI.parse(dsn_string) uri_path = uri.path.split('/') if uri.user # DSN-style string @project_id = uri_path.pop @public_key = uri.user @secret_key = !(uri.password.nil? || uri.password.empty?) ? uri.password : nil end @scheme = uri.scheme @host = uri.host @port = uri.port if uri.port @path = uri_path.join('/') end |
Instance Method Details
#envelope_endpoint ⇒ Object
44 45 46 |
# File 'lib/sentry/dsn.rb', line 44 def envelope_endpoint "#{path}/api/#{project_id}/envelope/" end |
#server ⇒ Object
37 38 39 40 41 42 |
# File 'lib/sentry/dsn.rb', line 37 def server server = "#{scheme}://#{host}" server += ":#{port}" unless port == PORT_MAP[scheme] server += path server end |
#to_s ⇒ Object
33 34 35 |
# File 'lib/sentry/dsn.rb', line 33 def to_s @raw_value end |
#valid? ⇒ Boolean
29 30 31 |
# File 'lib/sentry/dsn.rb', line 29 def valid? REQUIRED_ATTRIBUTES.all? { |k| public_send(k) } end |