Module: Github

Defined in:
lib/hubmaster/base.rb,
lib/hubmaster/repo.rb,
lib/hubmaster/cipher.rb

Defined Under Namespace

Classes: Cipher, Repos

Class Method Summary collapse

Class Method Details

.connectObject



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/hubmaster/base.rb', line 2

def self.connect
  run_pager
  if File.exists? "#{Dir.home}/.hubmaster"
    content = []
    File.open("#{Dir.home}/.hubmaster", "rb") do |fileC|
      while (line = fileC.gets)
        content << line.gsub("\n", "")
      end
    end

    @user = content[0]
    @pass = Github::Cipher.new.decrypt(content[1])
  else
    print "Username: "
    @user = STDIN.gets.chomp
    @pass = ask("Password: ") {|q| q.echo = "*"}
    File.open("#{Dir.home}/.hubmaster", "w") {|f| f.write("#{@user}\n#{@pass = Github::Cipher.new.encrypt(@pass)}")}
  end

  return nil
end

.helpObject



74
75
76
# File 'lib/hubmaster/base.rb', line 74

def self.help
  puts "Hubmaster Help: "
end

.makeDeleteRequest(path, username = @user, password = @pass, server = "api.github.com") ⇒ Object



55
56
57
58
59
60
61
62
# File 'lib/hubmaster/base.rb', line 55

def self.makeDeleteRequest(path, username = @user, password = @pass, server = "api.github.com")
    http = Net::HTTP.new(server,443)
    req = Net::HTTP::Delete.new(path)
    http.use_ssl = true
    req.basic_auth username, password
    response = http.request(req)
    return response.body
end

.makeEditRequest(path, body, username = @user, password = @pass, server = "api.github.com") ⇒ Object



64
65
66
67
68
69
70
71
72
# File 'lib/hubmaster/base.rb', line 64

def self.makeEditRequest(path, body, username = @user, password = @pass, server = "api.github.com")
    http = Net::HTTP.new(server,443)
    req = Net::HTTP::Post.new(path)
    http.use_ssl = true
    req.basic_auth username, password
    req.body = body
    response = http.request(req)
    return response.body
end

.makeGetRequest(path, username = @user, password = @pass, server = "api.github.com") ⇒ Object



36
37
38
39
40
41
42
43
# File 'lib/hubmaster/base.rb', line 36

def self.makeGetRequest(path, username = @user, password = @pass, server = "api.github.com")
    http = Net::HTTP.new(server,443)
    req = Net::HTTP::Get.new(path)
    http.use_ssl = true
    req.basic_auth username, password
    response = http.request(req)
    return response.body
end

.makePostRequest(path, body, username = @user, password = @pass, server = "api.github.com") ⇒ Object



45
46
47
48
49
50
51
52
53
# File 'lib/hubmaster/base.rb', line 45

def self.makePostRequest(path, body, username = @user, password = @pass, server = "api.github.com")
    http = Net::HTTP.new(server,443)
    req = Net::HTTP::Post.new(path)
    http.use_ssl = true
    req.basic_auth username, password
    req.body = body
    response = http.request(req)
    return response.body
end

.resetLoginObject



24
25
26
27
28
29
30
# File 'lib/hubmaster/base.rb', line 24

def self.resetLogin
  print "Username: "
  @user = STDIN.gets.chomp
  @pass = ask("Password: ") {|q| q.echo = "*"}
  File.open("#{Dir.home}/.hubmaster", "w") {|f| f.write("#{@user}\n#{@pass = Github::Cipher.new.encrypt(@pass)}")}
  return nil
end

.userObject



32
33
34
# File 'lib/hubmaster/base.rb', line 32

def self.user
  return @user
end