Class: Github::Auth::KeysClient

Inherits:
Object
  • Object
show all
Defined in:
lib/github/auth/keys_client.rb

Overview

Client for fetching public SSH keys using the Github API

Constant Summary collapse

UsernameRequiredError =
Class.new StandardError
GithubUnavailableError =
Class.new StandardError
GithubUserDoesNotExistError =
Class.new StandardError
DEFAULT_HOSTNAME =
'https://api.github.com'
USER_AGENT =
"github_auth-#{VERSION}"
DEFAULT_OPTIONS =
{
  username: nil,
  hostname: DEFAULT_HOSTNAME
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ KeysClient

Returns a new instance of KeysClient.



20
21
22
23
24
25
26
# File 'lib/github/auth/keys_client.rb', line 20

def initialize(options = {})
  options = DEFAULT_OPTIONS.merge options
  raise UsernameRequiredError unless options.fetch :username

  @username = options.fetch :username
  @hostname = options.fetch :hostname
end

Instance Attribute Details

#hostnameObject (readonly)

Returns the value of attribute hostname.



6
7
8
# File 'lib/github/auth/keys_client.rb', line 6

def hostname
  @hostname
end

#usernameObject (readonly)

Returns the value of attribute username.



6
7
8
# File 'lib/github/auth/keys_client.rb', line 6

def username
  @username
end

Instance Method Details

#keysObject



28
29
30
31
32
# File 'lib/github/auth/keys_client.rb', line 28

def keys
  @keys ||= Array(github_response).map do |entry|
    Github::Auth::Key.new username, entry.fetch('key')
  end
end