Sha256: af1e8417d1c20c9e2c8ee14101cfab24db3527f6787750119c21b45985f1aeda

Contents?: true

Size: 1.64 KB

Versions: 11

Compression:

Stored size: 1.64 KB

Contents

# frozen_string_literal: true

require 'asana'
require 'forwardable'
require 'cache_method'
require_relative 'internal/config_loader'
require_relative 'clients'

# https://developers.asana.com/docs/workspaces

module Checkoff
  # Query different workspaces of Asana projects
  class Workspaces
    MINUTE = 60
    # @sg-ignore
    HOUR = MINUTE * 60
    DAY = 24 * HOUR
    # @sg-ignore
    REALLY_LONG_CACHE_TIME = HOUR * 1
    # @sg-ignore
    LONG_CACHE_TIME = MINUTE * 15
    SHORT_CACHE_TIME = MINUTE

    # @param client [Asana::Client]
    def initialize(config: Checkoff::Internal::ConfigLoader.load(:asana),
                   client: Checkoff::Clients.new(config: config).client,
                   asana_workspace: Asana::Resources::Workspace)
      @config = config
      @client = client
      @asana_workspace = asana_workspace
    end

    # Pulls an Asana workspace object
    # @param [String] workspace_name
    # @return [Asana::Resources::Workspace, nil]
    def workspace(workspace_name)
      client.workspaces.find_all.find do |workspace|
        workspace.name == workspace_name
      end
    end

    # @return [Asana::Resources::Workspace]
    def default_workspace
      @asana_workspace.find_by_id(client, default_workspace_gid)
    end

    # @param [String] workspace_name
    # @return [Asana::Resources::Workspace]
    def workspace_or_raise(workspace_name)
      w = workspace(workspace_name)
      raise "Could not find workspace #{workspace_name}" if w.nil?

      w
    end

    # @sg-ignore
    # @return [String]
    def default_workspace_gid
      @config.fetch(:default_workspace_gid)
    end

    private

    attr_reader :client
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
checkoff-0.44.0 lib/checkoff/workspaces.rb
checkoff-0.43.0 lib/checkoff/workspaces.rb
checkoff-0.42.0 lib/checkoff/workspaces.rb
checkoff-0.41.0 lib/checkoff/workspaces.rb
checkoff-0.40.0 lib/checkoff/workspaces.rb
checkoff-0.39.4 lib/checkoff/workspaces.rb
checkoff-0.39.3 lib/checkoff/workspaces.rb
checkoff-0.39.2 lib/checkoff/workspaces.rb
checkoff-0.39.1 lib/checkoff/workspaces.rb
checkoff-0.39.0 lib/checkoff/workspaces.rb
checkoff-0.38.0 lib/checkoff/workspaces.rb