Module: Github

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

Defined Under Namespace

Classes: Cipher, Login, 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
23
24
# File 'lib/hubmaster/base.rb', line 2

def self.connect
  if File.exists? "#{Dir.home}/.hubmaster"
    line1 = File.open("#{Dir.home}/.hubmaster").first.gsub("\n", "")

    if line1 == "basic"
      auth = Github::.authenticate(:basic)
      @user = auth[0]
      @pass = auth[1]
    elsif line1 == "oauth"
      auth = Github::.authenticate(:oauth)
      @user = auth[0]
      @token = auth[1]  
    end
  else
    puts "No login file was detected. To add one, use hub login --new. Unstored basic auth will be used at this point."
    puts ""

    auth = Github::.basic
    @user = auth[0]
    @pass = auth[1]
  end
  return nil
end

.helpObject



105
106
107
# File 'lib/hubmaster/base.rb', line 105

def self.help
  puts "Hubmaster Help: "
end

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



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/hubmaster/base.rb', line 68

def self.makeDeleteRequest(path, username = @user, password = @pass, token = @token, server = "api.github.com")
  if password.nil?
    http = Net::HTTP.new(server,443)
    req = Net::HTTP::Delete.new("#{path}?access_token=#{token}") if path.include?("?") == false
    req = Net::HTTP::Delete.new("#{path}&&access_token=#{token}") if path.include?("?") == true
    http.use_ssl = true
    response = http.request(req)
    return response.body
  else
    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
end

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



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/hubmaster/base.rb', line 86

def self.makeEditRequest(path, body, username = @user, password = @pass, token = @token, server = "api.github.com")
  if password.nil?
    http = Net::HTTP.new(server,443)
    req = Net::HTTP::Post.new("#{path}?access_token=#{token}") if path.include?("?") == false
    req = Net::HTTP::Post.new("#{path}&&access_token=#{token}") if path.include?("?") == true
    http.use_ssl = true
    req.body = body
    response = http.request(req)
    return response.body
  else
    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
end

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



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/hubmaster/base.rb', line 30

def self.makeGetRequest(path, username = @user, password = @pass, token = @token, server = "api.github.com")
  if password.nil?
    http = Net::HTTP.new(server, 443)
    req = Net::HTTP::Get.new("#{path}?access_token=#{token}") if path.include?("?") == false
    req = Net::HTTP::Get.new("#{path}&&access_token=#{token}") if path.include?("?") == true
    http.use_ssl = true
    response = http.request(req)
    return response.body
  else 
    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
end

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



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/hubmaster/base.rb', line 48

def self.makePostRequest(path, body, username = @user, password = @pass, token = @token, server = "api.github.com")
  if password.nil?
    http = Net::HTTP.new(server,443)
    req = Net::HTTP::Post.new("#{path}?access_token=#{token}") if path.include?("?") == false
    req = Net::HTTP::Post.new("#{path}&&access_token=#{token}") if path.include?("?") == true
    http.use_ssl = true
    req.body = body
    response = http.request(req)
    return response.body
  else
    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
end

.userObject



26
27
28
# File 'lib/hubmaster/base.rb', line 26

def self.user
  return @user
end