Class: Checkoff::Internal::SearchUrl::SimpleParamConverter

Inherits:
Object
  • Object
show all
Defined in:
lib/checkoff/internal/search_url/simple_param_converter.rb,
sig/checkoff.rbs

Overview

Convert simple parameters - ones where the param name itself doesn't encode any parameters'

Constant Summary collapse

ARGS =

Returns:

  • (Object)
{
  'portfolios.ids' => SimpleParam::PortfoliosIds,
  'any_projects.ids' => SimpleParam::AnyProjectsIds,
  'not_projects.ids' => SimpleParam::NotProjectsIds,
  'completion' => SimpleParam::Completion,
  'not_tags.ids' => SimpleParam::NotTagsIds,
  'any_tags.ids' => SimpleParam::AnyTagsIds,
  'all_tags.ids' => SimpleParam::AllTagsIds,
  'subtask' => SimpleParam::Subtask,
  'sort' => SimpleParam::Sort,
  'milestone' => SimpleParam::Milestone,
  'approval' => SimpleParam::Approval,
  'searched_type' => SimpleParam::SearchedType,
  'locatedIn' => SimpleParam::LocatedIn,
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(simple_url_params:) ⇒ SimpleParamConverter

@param simple_url_params — the simple params

Parameters:

  • simple_url_params: (::Hash[String, ::Array[String]])


222
223
224
# File 'lib/checkoff/internal/search_url/simple_param_converter.rb', line 222

def initialize(simple_url_params:)
  @simple_url_params = simple_url_params
end

Instance Attribute Details

#simple_url_paramsHash{String => Array<String>} (readonly)

Returns:

  • (Hash{String => Array<String>})


280
281
282
# File 'lib/checkoff/internal/search_url/simple_param_converter.rb', line 280

def simple_url_params
  @simple_url_params
end

Instance Method Details

#convert::Hash[String, String]

@return — the converted params

Returns:

  • (::Hash[String, String])


227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
# File 'lib/checkoff/internal/search_url/simple_param_converter.rb', line 227

def convert
  # @type [Array<Array(String, String)>]
  # @sg-ignore
  arr_of_tuples = simple_url_params.to_a.flat_map do |key, values|
    # @type
    entry = convert_arg(key, values).each_slice(2).to_a
    entry
  end
  # @type [Hash{String => String}]
  out = T.cast(arr_of_tuples.to_h, T::Hash[String, String])
  unless out.include? 'sort_by'
    # keep results consistent between calls; API using default
    # sort_by does not seem to be.
    out['sort_by'] = 'created_at'
  end
  out
end

#convert_arg(key, values) ⇒ ::Hash[String, String]

https://developers.asana.com/docs/search-tasks-in-a-workspace @sg-ignore

@param key — the name of the search url param

@param values — the values of the search url param

@return — the converted params

Parameters:

  • key (String)
  • values (::Array[String])

Returns:

  • (::Hash[String, String])


270
271
272
273
274
275
276
277
# File 'lib/checkoff/internal/search_url/simple_param_converter.rb', line 270

def convert_arg(key, values)
  # @type [Class<SimpleParam::SimpleParam>]
  clazz = ARGS.fetch(key)
  # @type [SimpleParam::SimpleParam]
  obj = clazz.new(key:, values:)
  # @sg-ignore
  obj.convert
end