Sha256: 682cf8f3702d62ab70a24e05f46400656b985b46b6da2f5d9ff74eb8d506d5f4

Contents?: true

Size: 1.13 KB

Versions: 3

Compression:

Stored size: 1.13 KB

Contents

require 'yaml'
require 'rally_rest_api'
require 'logger'

module Rallycat
  class InvalidConfigError < StandardError; end
  class InvalidCredentialsError < StandardError; end

  class Connection
    attr_reader :api

    def initialize(username=nil, password=nil)
      @username = username
      @password = password

      config = parse_config

      begin
        @api = RallyRestAPI.new \
         base_url: 'https://rally1.rallydev.com/slm',
         username: config.fetch('username'),
         password: config.fetch('password'),
         logger: Logger.new(nil)

      rescue Rally::NotAuthenticatedError
        raise InvalidCredentialsError.new('Your Rally credentials are invalid.')
      end
    end

    private

    def parse_config
      rc_file_path = File.expand_path '~/.rallycatrc'

      if @username || @password
        { 'username' => @username, 'password' => @password }
      else
        begin
          YAML.load_file(rc_file_path)
        rescue StandardError
          message = "Your rallycat config file is missing or invalid. Please RTFM."
          raise InvalidConfigError.new message
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rallycat-0.3.1 lib/rallycat/connection.rb
rallycat-0.3.0 lib/rallycat/connection.rb
rallycat-0.2.0 lib/rallycat/connection.rb