Class: Stickler::Repository::RubygemsAuthenticator

Inherits:
Object
  • Object
show all
Defined in:
lib/stickler/repository/rubygems_authenticator.rb

Overview

When talking to rubygems itself, the rubygems_api key is required. This authenticator is injected automatically if the host you are talking to matches the rubygems host

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.rubygems_uriObject



10
11
12
# File 'lib/stickler/repository/rubygems_authenticator.rb', line 10

def self.rubygems_uri
  @rubygems_uri ||= Addressable::URI.parse( "https://rubygems.org" )
end

Instance Method Details

#add_credentials_to(request) ⇒ Object



28
29
30
# File 'lib/stickler/repository/rubygems_authenticator.rb', line 28

def add_credentials_to(request)
  request.header['Authorization'] = credentials
end

#can_handle?(request) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
25
26
# File 'lib/stickler/repository/rubygems_authenticator.rb', line 22

def can_handle?( request )
  request_uri  = Addressable::URI.parse(request.uri)
  return (request_uri.host   == rubygems_uri.host  ) && 
         (request_uri.scheme == rubygems_uri.scheme)
end

#credentialsObject



14
15
16
# File 'lib/stickler/repository/rubygems_authenticator.rb', line 14

def credentials
  Gem.configuration.rubygems_api_key
end

#rubygems_uriObject



18
19
20
# File 'lib/stickler/repository/rubygems_authenticator.rb', line 18

def rubygems_uri
  self.class.rubygems_uri
end