Sha256: 60969627bf9ed47aa0c71233c9a1a28eb33a2c32bca93ef48de767ddb380af0a

Contents?: true

Size: 988 Bytes

Versions: 23

Compression:

Stored size: 988 Bytes

Contents

# frozen_string_literal: true

module LedgerSync
  module Util
    class URLHelpers
      def self.merge_params_in_url(args = {})
        params = args.fetch(:params)
        uri    = args.fetch(:url)

        uri = URI.parse(uri) unless uri.is_a?(URI::HTTPS) || uri.is_a?(URI::HTTP)
        uri.query = URI.encode_www_form(
          params.inject(URI.decode_www_form(String(uri.query))) { |prev, param| prev << param }
        )

        uri.to_s
      end

      def self.merge_params_in_path(args = {})
        params = args.fetch(:params)
        path   = args.fetch(:path)

        root, str_params = path.split('?')
        str_params = Rack::Utils.parse_nested_query(str_params)

        [
          root,
          Rack::Utils.build_query(str_params.merge(HashHelpers.deep_stringify_keys(params)))
        ].compact.join('?')
      end

      def self.id_from_url(args = {})
        uri = args.fetch(:url)

        URI.parse(uri).path.split('/').last
      end
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
ledger_sync-3.0.0 lib/ledger_sync/util/url_helpers.rb
ledger_sync-2.6.0 lib/ledger_sync/util/url_helpers.rb
ledger_sync-2.5.0 lib/ledger_sync/util/url_helpers.rb
ledger_sync-2.4.4 lib/ledger_sync/util/url_helpers.rb
ledger_sync-2.3.1 lib/ledger_sync/util/url_helpers.rb
ledger_sync-2.2.3 lib/ledger_sync/util/url_helpers.rb
ledger_sync-2.2.1 lib/ledger_sync/util/url_helpers.rb
ledger_sync-2.2.0 lib/ledger_sync/util/url_helpers.rb
ledger_sync-2.0.2 lib/ledger_sync/util/url_helpers.rb
ledger_sync-2.0.1 lib/ledger_sync/util/url_helpers.rb
ledger_sync-2.0.0 lib/ledger_sync/util/url_helpers.rb
ledger_sync-2.0.0.pre.1 lib/ledger_sync/util/url_helpers.rb
ledger_sync-1.8.1 lib/ledger_sync/util/url_helpers.rb
ledger_sync-1.8.0 lib/ledger_sync/util/url_helpers.rb
ledger_sync-1.7.0 lib/ledger_sync/util/url_helpers.rb
ledger_sync-1.6.0 lib/ledger_sync/util/url_helpers.rb
ledger_sync-1.5.2 lib/ledger_sync/util/url_helpers.rb
ledger_sync-1.5.1 lib/ledger_sync/util/url_helpers.rb
ledger_sync-1.5.0 lib/ledger_sync/util/url_helpers.rb
ledger_sync-1.4.4 lib/ledger_sync/util/url_helpers.rb