Sha256: ab0c9391b1099abc082b37a9ccd0558599bd2fe932e17a419b9268a7ca4211bf

Contents?: true

Size: 1.55 KB

Versions: 3

Compression:

Stored size: 1.55 KB

Contents

# typed: false
module Researchable
  module FreedcampApi
    class ListTasks < Endpoint
      integer :task_id, default: nil
      integer :f_with_archived, default: 0
      array :status, default: []

      # Accepts "active", "archived", "all" values. Omitting is equal to "active".
      string :lists_status, default: 'active'
      string :assigned_to_id, default: nil
      integer :f_cf, default: 1
      boolean :include_subtasks, default: true

      # @api private
      def execute
        list_tasks(task_id)
      end

      sig do
        params(
          task_id: T.nilable(Integer)
        ).returns(
          T::Array[Researchable::FreedcampApi::Structs::Task]
        )
      end
      def list_tasks(task_id)
        task_query = task_id ? "/#{task_id}" : '/'
        assigned_to_id_query = assigned_to_id ? "&assigned_to_id[]=#{assigned_to_id}" : ''
        f_with_archived_query = f_with_archived ? "&f_with_archived=#{f_with_archived}" : ''
        status_query = status.reduce('') { |tot, cur| "#{tot}&status[]=#{cur}" }
        # status[]=&status[]=2
        tasks = fetch_all('tasks') do |limit, offset|
          url = "/tasks#{task_query}?limit=#{limit}
                   &offset=#{offset}
                   #{assigned_to_id_query}
                   #{f_with_archived_query}
                   #{status_query}
                   &f_cf=#{f_cf}
                   &lists_status=#{lists_status}"
          session.get(url)
        end

        return tasks if include_subtasks

        tasks.select { |task| task['h_top_id'].blank? }
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
researchable-freedcamp-api-0.1.8 lib/researchable/freedcamp_api/list_tasks.rb
researchable-freedcamp-api-0.1.7 lib/researchable/freedcamp_api/list_tasks.rb
researchable-freedcamp-api-0.1.6 lib/researchable/freedcamp_api/list_tasks.rb