Sha256: ac3381600f0d55adfd39cd7f89b79072bdbf4b394d7404e7d5a487a33628c52a

Contents?: true

Size: 1.14 KB

Versions: 6

Compression:

Stored size: 1.14 KB

Contents

# frozen_string_literal: true

require 'forwardable'
require 'cache_method'
require_relative 'config_loader'
require_relative 'clients'

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

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

    def initialize(config: Checkoff::ConfigLoader.load(:asana),
                   clients: Checkoff::Clients.new(config: config),
                   client: clients.client)
      @config = config
      @client = client
    end

    # Pulls an Asana workspace object
    def workspace(workspace_name)
      client.workspaces.find_all.find do |workspace|
        workspace.name == workspace_name
      end
    end

    def workspace_or_raise(workspace_name)
      workspace = workspace(workspace_name)
      raise "Could not find workspace #{workspace_name}" if workspace.nil?

      workspace
    end

    private

    attr_reader :client

    def default_workspace_gid
      @config.fetch(:default_workspace_gid)
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
checkoff-0.17.0 lib/checkoff/workspaces.rb
checkoff-0.16.1 lib/checkoff/workspaces.rb
checkoff-0.16.0 lib/checkoff/workspaces.rb
checkoff-0.15.2 lib/checkoff/workspaces.rb
checkoff-0.15.1 lib/checkoff/workspaces.rb
checkoff-0.15.0 lib/checkoff/workspaces.rb