Class: Checkoff::Attachments

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/checkoff/attachments.rb

Overview

Manage attachments in Asana

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Logging

#debug, #error, #finer, #info, #logger, #warn

Constructor Details

#initialize(config: Checkoff::Internal::ConfigLoader.load(:asana), workspaces: Checkoff::Workspaces.new(config: config), clients: Checkoff::Clients.new(config: config), client: clients.client) ⇒ Attachments

Returns a new instance of Attachments.

Parameters:

  • config (Hash) (defaults to: Checkoff::Internal::ConfigLoader.load(:asana))
  • workspaces (Checkoff::Workspaces) (defaults to: Checkoff::Workspaces.new(config: config))
  • clients (Checkoff::Clients) (defaults to: Checkoff::Clients.new(config: config))
  • client (Asana::Client) (defaults to: clients.client)


46
47
48
49
50
51
52
# File 'lib/checkoff/attachments.rb', line 46

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

Class Method Details

.runvoid

This method returns an undefined value.



182
183
184
185
186
187
188
189
190
191
192
193
194
195
# File 'lib/checkoff/attachments.rb', line 182

def run
  # @sg-ignore
  # @type [String]
  gid = ARGV[0] || raise('Please pass task gid as first argument')
  # @sg-ignore
  # @type [String]
  url = ARGV[1] || raise('Please pass attachment URL as second argument')

  tasks = Checkoff::Tasks.new
  attachments = Checkoff::Attachments.new
  task = tasks.task_by_gid(gid)
  attachment = attachments.create_attachment_from_url!(url, task)
  puts "Results: #{attachment.inspect}"
end

Instance Method Details

#create_attachment_from_url!(url, resource, attachment_name: nil, just_the_url: false) ⇒ Asana::Resources::Attachment

Parameters:

  • url (String)
  • resource (Asana::Resources::Resource)
  • attachment_name (String, nil) (defaults to: nil)
  • just_the_url (Boolean) (defaults to: false)

Returns:

  • (Asana::Resources::Attachment)


60
61
62
63
64
65
66
67
68
69
# File 'lib/checkoff/attachments.rb', line 60

def create_attachment_from_url!(url,
                                resource,
                                attachment_name: nil,
                                just_the_url: false)
  if just_the_url
    create_attachment_from_url_alone!(url, resource, attachment_name: attachment_name)
  else
    create_attachment_from_downloaded_url!(url, resource, attachment_name: attachment_name)
  end
end