class Rubygems::API::Client
Attributes
api_key[RW]
client[RW]
Public Class Methods
new(arguments = {})
click to toggle source
# File lib/rubygems_api/client.rb, line 21 def initialize(arguments = {}) @api_key ||= arguments[:api_key] || \ nil @host = 'https://rubygems.org/' @api_endpoint = '/api/v1' @client = Hurley::Client.new 'https://rubygems.org/api/v1/' ssl(arguments) @client.request_options.redirection_limit = 10 @client.header[:Authorization] = @api_key unless @api_key.nil? @client end
Public Instance Methods
set_api_key(username, password, format = 'json', args = {})
click to toggle source
# File lib/rubygems_api/client.rb, line 44 def set_api_key(username, password, format = 'json', args = {}) creds = CGI.escape(username) + ':' + CGI.escape(password) if validate_format(format) response = @client.get("https://#{creds}@rubygems.org/api/v1/api_key.#{format}") do |req| req.header[:Authorization] = req.url.basic_auth.gsub!(/(\n|\r|\t)+/, '') end if response.success? format_body response: response, skip_format: args[:skip_format], format: format api_key(response.body['rubygems_api_key']) end end response end