Sha256: 2f82df04d21f69a0f29deac87321e31aa64102a421aad6fc577f5e027d61efae

Contents?: true

Size: 1.01 KB

Versions: 4

Compression:

Stored size: 1.01 KB

Contents

module Gitrob
  module Github
    class ClientManager
      USER_AGENT = "Gitrob v#{Gitrob::VERSION}"

      attr_reader :clients

      class NoClientsError < StandardError; end

      def initialize(config)
        @config  = config
        @mutex   = Mutex.new
        @clients = []
        config[:access_tokens].each do |token|
          clients << create_client(token)
        end
      end

      def sample
        @mutex.synchronize do
          fail NoClientsError if clients.count.zero?
          clients.sample
        end
      end

      def remove(client)
        @mutex.synchronize do
          clients.delete(client)
        end
      end

      private

      def create_client(access_token)
        ::Github.new(
          :oauth_token     => access_token,
          :endpoint        => @config[:endpoint],
          :site            => @config[:site],
          :ssl             => @config[:ssl],
          :user_agent      => USER_AGENT,
          :auto_pagination => true
        )
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
gitrob-1.1.2 lib/gitrob/github/client_manager.rb
gitrob-1.1.1 lib/gitrob/github/client_manager.rb
gitrob-1.1.0 lib/gitrob/github/client_manager.rb
gitrob-1.0.1 lib/gitrob/github/client_manager.rb