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:), clients: Checkoff::Clients.new(config:), client: clients.client) ⇒ Attachments

Returns a new instance of Attachments.

Parameters:



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

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

Class Method Details

.runvoid

This method returns an undefined value.



189
190
191
192
193
194
195
196
197
198
199
200
201
202
# File 'lib/checkoff/attachments.rb', line 189

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, verify_mode: OpenSSL::SSL::VERIFY_PEER, 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)
  • verify_mode (Integer) (defaults to: OpenSSL::SSL::VERIFY_PEER)
    • e.g., OpenSSL::SSL::VERIFY_NONE or OpenSSL::SSL::VERIFY_PEER

Returns:

  • (Asana::Resources::Attachment)


63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/checkoff/attachments.rb', line 63

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