Sha256: 934ab8131a0923d88b039e95f86c9c7b72c56f744a2d4ff5e872d0633ad5e836

Contents?: true

Size: 1.42 KB

Versions: 1

Compression:

Stored size: 1.42 KB

Contents

require "harvested"

module GetToWork
  class Service
    class Harvest < GetToWork::Service
      @yaml_key = "harvest"
      @name = "Harvest"
      @display_name = "Harvest"

      attr_reader :subdomain, :project_id, :task_id
      def initialize(yaml_hash)
        super(yaml_hash)

        @harvest = nil
      end

      def api_client
        @api_client ||= ::Harvest.client(
          subdomain: @subdomain,
          username: keychain.account,
          password: keychain.password
        )
      end

      def authenticate_with_keychain
        if !@subdomain.blank? && keychain
          return api_client
        end
      end

      def authenticate(username:, password:, subdomain:)
        @subdomain = subdomain
        @api_client = ::Harvest.client(
          subdomain: @subdomain,
          username: username,
          password: password
        )

        if @api_client
          @api_token = password
        end
      end

      def clients
        @clients ||= get_clients
      end

      def get_clients
        api_client.clients.all
      end

      def get_time
        api_client.time
      end

      def projects
        api_client.time.trackable_projects
      end

      def project
        projects.find(@project_id)
      end

      def start_timer(opts = {})
        api_client.time.create(opts)
      end

      def stop_timer(timer_id)
        api_client.time.toggle(timer_id)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
get_to_work-0.1.0 lib/get_to_work/service/harvest.rb