Sha256: 721460677226319430dfc5ab54d9fdc767a9306639b68aa0fca423a758d8b9dc

Contents?: true

Size: 1.3 KB

Versions: 3

Compression:

Stored size: 1.3 KB

Contents

#!/usr/bin/env ruby

# frozen_string_literal: true

require 'forwardable'
require_relative 'config_loader'
require 'asana'

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

module Checkoff
  # Pulls a configured Asana client object which can be used to access the API
  class Clients
    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),
                   asana_client_class: Asana::Client)
      @config = config
      @asana_client_class = asana_client_class
    end

    def client
      @client ||= @asana_client_class.new do |c|
        c.authentication :access_token, @config.fetch(:personal_access_token)
        c.default_headers 'asana-enable' => 'string_ids,new_sections'
        c.default_headers 'asana-disable' => 'new_user_task_lists'
      end
    end

    private

    attr_reader :workspaces

    # bundle exec ./clients.rb
    # :nocov:
    class << self
      def run
        clients = Checkoff::Clients.new
        client = clients.client
        puts "Results: #{client}"
      end
    end
    # :nocov:
  end
end

# :nocov:
abs_program_name = File.expand_path($PROGRAM_NAME)
Checkoff::Clients.run if abs_program_name == __FILE__
# :nocov:

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
checkoff-0.15.2 lib/checkoff/clients.rb
checkoff-0.15.1 lib/checkoff/clients.rb
checkoff-0.15.0 lib/checkoff/clients.rb