Class: Checkoff::Workspaces

Inherits:
Object
  • Object
show all
Extended by:
CacheMethod::ClassMethods
Defined in:
lib/checkoff/workspaces.rb

Overview

Query different workspaces of Asana projects

Constant Summary collapse

MINUTE =
60
HOUR =
MINUTE * 60
DAY =
24 * HOUR
REALLY_LONG_CACHE_TIME =
HOUR * 1
LONG_CACHE_TIME =
MINUTE * 15
SHORT_CACHE_TIME =
MINUTE

Instance Method Summary collapse

Constructor Details

#initialize(config: Checkoff::Internal::ConfigLoader.load(:asana), client: Checkoff::Clients.new(config: config).client, asana_workspace: Asana::Resources::Workspace) ⇒ Workspaces

Returns a new instance of Workspaces.

Parameters:

  • config (Hash<Symbol, Object>) (defaults to: Checkoff::Internal::ConfigLoader.load(:asana))
  • client (Asana::Client) (defaults to: Checkoff::Clients.new(config: config).client)
  • asana_workspace (Class<Asana::Resources::Workspace>) (defaults to: Asana::Resources::Workspace)


27
28
29
30
31
32
33
# File 'lib/checkoff/workspaces.rb', line 27

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

Instance Method Details

#default_workspaceAsana::Resources::Workspace

Returns:

  • (Asana::Resources::Workspace)


47
48
49
# File 'lib/checkoff/workspaces.rb', line 47

def default_workspace
  @asana_workspace.find_by_id(client, default_workspace_gid)
end

#default_workspace_gidString

@sg-ignore

Returns:

  • (String)


63
64
65
# File 'lib/checkoff/workspaces.rb', line 63

def default_workspace_gid
  @config.fetch(:default_workspace_gid)
end

#workspace(workspace_name) ⇒ Asana::Resources::Workspace?

Pulls an Asana workspace object @sg-ignore

Parameters:

  • workspace_name (String)

Returns:

  • (Asana::Resources::Workspace, nil)


39
40
41
42
43
# File 'lib/checkoff/workspaces.rb', line 39

def workspace(workspace_name)
  client.workspaces.find_all.find do |workspace|
    workspace.name == workspace_name
  end
end

#workspace_or_raise(workspace_name) ⇒ Asana::Resources::Workspace

Parameters:

  • workspace_name (String)

Returns:

  • (Asana::Resources::Workspace)


54
55
56
57
58
59
# File 'lib/checkoff/workspaces.rb', line 54

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

  w
end