Sha256: 439e7d6b1bdee0f4c2d3efd94c3f508233f4d3ecfba31ef73a519da5b54de4ef

Contents?: true

Size: 1.04 KB

Versions: 30

Compression:

Stored size: 1.04 KB

Contents

require "uri"

module Sentry
  class DSN
    PORT_MAP = { 'http' => 80, 'https' => 443 }.freeze
    REQUIRED_ATTRIBUTES = %w(host path public_key project_id).freeze

    attr_reader :scheme, :secret_key, :port, *REQUIRED_ATTRIBUTES

    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

    def valid?
      REQUIRED_ATTRIBUTES.all? { |k| public_send(k) }
    end

    def to_s
      @raw_value
    end

    def server
      server = "#{scheme}://#{host}"
      server += ":#{port}" unless port == PORT_MAP[scheme]
      server += path
      server
    end

    def envelope_endpoint
      "#{path}/api/#{project_id}/envelope/"
    end
  end
end

Version data entries

30 entries across 30 versions & 2 rubygems

Version Path
sentry-ruby-core-4.6.1 lib/sentry/dsn.rb
sentry-ruby-core-4.6.0 lib/sentry/dsn.rb
sentry-ruby-core-4.6.0.pre.beta.0 lib/sentry/dsn.rb
sentry-ruby-core-4.5.2 lib/sentry/dsn.rb
sentry-ruby-core-4.5.1 lib/sentry/dsn.rb
sentry-ruby-core-4.5.0 lib/sentry/dsn.rb
sentry-ruby-core-4.5.0.pre.beta.1 lib/sentry/dsn.rb
sentry-ruby-core-4.4.2 lib/sentry/dsn.rb
sentry-ruby-core-4.4.1 lib/sentry/dsn.rb
sentry-ruby-core-4.4.0 lib/sentry/dsn.rb
sentry-ruby-core-4.4.0.pre.beta.0 lib/sentry/dsn.rb
sentry-ruby-core-4.3.2 lib/sentry/dsn.rb
sentry-ruby-core-4.3.1 lib/sentry/dsn.rb
sentry-ruby-core-4.3.0 lib/sentry/dsn.rb
sentry-ruby-core-4.2.2 lib/sentry/dsn.rb
sentry-ruby-core-4.2.1 lib/sentry/dsn.rb
sentry-ruby-core-4.2.0 lib/sentry/dsn.rb
sentry-ruby-core-4.1.6 lib/sentry/dsn.rb
sentry-ruby-core-4.1.5 lib/sentry/dsn.rb
sentry-ruby-core-4.1.5.pre.beta.1 lib/sentry/dsn.rb