Module: Tmg

Defined in:
lib/tmg.rb,
lib/tmg/cli.rb,
lib/tmg/version.rb,
lib/tmg/cli/info.rb,
lib/tmg/cli/list.rb,
lib/tmg/cli/user.rb,
lib/tmg/cli/wiki.rb,
lib/tmg/cli/about.rb,
lib/tmg/cli/login.rb,
lib/tmg/cli/version.rb,
lib/tmg/cli/homepage.rb,
lib/tmg/cli/documentation.rb

Defined Under Namespace

Classes: CLI

Constant Summary collapse

VERSION =
"0.5.5"
'''
 ______   __    __     ______    
/\__  _\ /\ "-./  \   /\  ___\   
\/_/\ \/ \ \ \-./\ \  \ \ \__ \  
   \ \_\  \ \_\ \ \_\  \ \_____\ 
    \/_/   \/_/  \/_/   \/_____/ 
'''

Class Method Summary collapse

Class Method Details

.write_credentials(username, password, outdir = "#{Dir.home}/.gem", outfile = 'credentials') ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/tmg.rb', line 7

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