Sha256: d78ac842c737726ed07992a0b109f9287311ba3b8e00725d904c0a6d44461dd3

Contents?: true

Size: 833 Bytes

Versions: 2

Compression:

Stored size: 833 Bytes

Contents

require "tmg/version"
require 'yaml'
require 'httparty'
require 'gems'

module Tmg
  def self.write_credentials(username,
                             password,
                             outdir = "#{Dir.home}/.gem",
                             outfile = 'credentials')
    # Write credentials rubygems.org API access key to:
    # /home/username/.gem/credentials
    auth = { username: username, password: password }
    yaml = HTTParty.get('https://rubygems.org/api/v1/api_key.yaml',
                        basic_auth: auth)
    raise 'Access Denied' if yaml.code == 401

    File.open("#{outdir}/#{outfile}", "w") { |file| file.write(yaml) }
    FileUtils.chmod 0600, "#{outdir}/#{outfile}"
    api_key = YAML.load_file("#{outdir}/#{outfile}")
    Gems.configure { |config| config.key = api_key[:rubygems_api_key] }
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
tmg-0.5.5 lib/tmg.rb
tmg-0.5.4 lib/tmg.rb