Sha256: 0ce7661c96f813bd65c029896bb2d6472c8f3ae7ac1522ddf510c4423052fc02

Contents?: true

Size: 1.37 KB

Versions: 27

Compression:

Stored size: 1.37 KB

Contents

#!/usr/bin/env ruby

# frozen_string_literal: true

require_relative 'simple_param_converter'
require_relative 'custom_field_param_converter'

module Checkoff
  module Internal
    module SearchUrl
      # Parse Asana search URLs into parameters suitable to pass into
      # the /workspaces/{workspace_gid}/tasks/search endpoint
      class Parser
        def initialize(_deps = {})
          # allow dependencies to be passed in by tests
        end

        def convert_params(url)
          url_params = CGI.parse(URI.parse(url).query)
          custom_field_params, simple_url_params = partition_url_params(url_params)
          custom_field_args, task_selector = convert_custom_field_params(custom_field_params)
          simple_url_args = convert_simple_params(simple_url_params)
          [custom_field_args.merge(simple_url_args), task_selector]
        end

        private

        def convert_simple_params(simple_url_params)
          SimpleParamConverter.new(simple_url_params: simple_url_params).convert
        end

        def convert_custom_field_params(custom_field_params)
          CustomFieldParamConverter.new(custom_field_params: custom_field_params).convert
        end

        def partition_url_params(url_params)
          url_params.to_a.partition do |key, _values|
            key.start_with? 'custom_field_'
          end.map(&:to_h)
        end
      end
    end
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
checkoff-0.36.1 lib/checkoff/internal/search_url/parser.rb
checkoff-0.36.0 lib/checkoff/internal/search_url/parser.rb
checkoff-0.35.1 lib/checkoff/internal/search_url/parser.rb
checkoff-0.35.0 lib/checkoff/internal/search_url/parser.rb
checkoff-0.34.1 lib/checkoff/internal/search_url/parser.rb
checkoff-0.34.0 lib/checkoff/internal/search_url/parser.rb
checkoff-0.33.2 lib/checkoff/internal/search_url/parser.rb
checkoff-0.33.1 lib/checkoff/internal/search_url/parser.rb
checkoff-0.33.0 lib/checkoff/internal/search_url/parser.rb
checkoff-0.32.0 lib/checkoff/internal/search_url/parser.rb
checkoff-0.31.0 lib/checkoff/internal/search_url/parser.rb
checkoff-0.30.0 lib/checkoff/internal/search_url/parser.rb
checkoff-0.29.4 lib/checkoff/internal/search_url/parser.rb
checkoff-0.29.3 lib/checkoff/internal/search_url/parser.rb
checkoff-0.29.2 lib/checkoff/internal/search_url/parser.rb
checkoff-0.29.1 lib/checkoff/internal/search_url/parser.rb
checkoff-0.29.0 lib/checkoff/internal/search_url/parser.rb
checkoff-0.28.0 lib/checkoff/internal/search_url/parser.rb
checkoff-0.27.0 lib/checkoff/internal/search_url/parser.rb
checkoff-0.26.1 lib/checkoff/internal/search_url/parser.rb