Class: GitLabHttp

Inherits:
Object
  • Object
show all
Defined in:
lib/cocoapods-lzsource/command/gitlab.rb

Instance Method Summary collapse

Instance Method Details

#checkUserInfoObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/cocoapods-lzsource/command/gitlab.rb', line 13

def checkUserInfo()
  if File.exist?(UserPathFile)
        f = File.open(UserPathFile, 'r')
    a = f.readlines.map! { |line| line.chomp }

    if a[0] && a[1]
      $Private_Token = a[0]
      $GitHTTP_Address = a[1]
    else
      createUserInfo()
    end

    f.close
  else
        createUserInfo()
  end
end

#createUserInfoObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/cocoapods-lzsource/command/gitlab.rb', line 31

def createUserInfo()

  pt = ''

  while pt.length == 0
    print "Please enter a gitlab private token:"
      pt = STDIN.gets.chomp
  end
  $Private_Token = pt

  
  if $GitHTTP_Address.size < 1
    ga = ''
    while !(ga =~ /(^http|^https)[:][\/][\/][a-zA-Z0-9]/)
      print "Please enter a gitlab url:"
       ga = STDIN.gets.chomp
    end
    $GitHTTP_Address = ga
  end

  f=File.new(UserPathFile,"w+")
    f.puts $Private_Token
    f.puts $GitHTTP_Address
    f.close

  puts 'Operation successful!'
end

#getProjectInfo(keyword) ⇒ Object



139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
# File 'lib/cocoapods-lzsource/command/gitlab.rb', line 139

def getProjectInfo(keyword)

  checkUserInfo()

  uri = "#{$GitHTTP_Address}/api/v4/projects?private_token=#{$Private_Token}&search=#{keyword}&per_page=100"

  html_response = nil 

  # open(uri) do |http|  
  #  html_response = http.read
  # end 

  t = Thread.new {
         startLoading()
       }

  begin
      req = open(uri).read
  rescue  StandardError,Timeout::Error, SystemCallError,SocketError, Errno::ECONNREFUSED
    print "\r"
      puts 'URL Access Error!'
      puts uri
      exit
  else
    print "\r"
    html_response = req
  end

  Thread.kill(t)

  data = JSON.parse(html_response)

  info = Array.new

  data.each do |d|
    ssh = d["ssh_url_to_repo"]
    forkfrom = d["forked_from_project"]

    if !ssh.include?("Pods") && forkfrom.nil?
      temp = Array.new
      temp << d["name"]
      temp << d["web_url"]
      temp << ssh
      temp << d["path"]

      info << temp

    end
  end
  return info
end

#getSourceCodeInfo(keyword) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/cocoapods-lzsource/command/gitlab.rb', line 67

def getSourceCodeInfo(keyword)

  checkUserInfo()

  codeInfo = Array.new

  uri = "#{$GitHTTP_Address}/api/v4/projects?private_token=#{$Private_Token}&search=#{keyword}&per_page=100"

  html_response = nil 

  # open(uri) do |http|  
  #  html_response = http.read
  # end 

  t = Thread.new {
         startLoading()
       }

  begin
      req = open(uri).read
  rescue  StandardError,Timeout::Error, SystemCallError,SocketError, Errno::ECONNREFUSED
    print "\r"
      puts 'URL Access Error!'
      puts uri
      exit
  else
    print "\r"
    html_response = req 
  end

  Thread.kill(t)

  data = JSON.parse(html_response)

  info = Array.new

  data.each do |d|
    ssh = d["ssh_url_to_repo"]
    forkfrom = d["forked_from_project"]

    if !ssh.include?("Pods") && forkfrom.nil?
      temp = Array.new
      temp << d["name"]
      temp << d["web_url"]
      temp << ssh
      temp << d["path"]

      info << temp
    end
  end

  if info.count > 0
    print "Search results:\n"
    i = 1
    info.each do |temp|
      puts " #{i}:#{temp[0]} #{temp[2]}\n"
      i += 1
    end

    num = 0

    while num >info.count || num == 0
      print "Please enter the correct number:"
       num = STDIN.gets.chomp.to_i
    end
    codeInfo = info[num-1];
  end

  return codeInfo
end

#resetInfoObject



59
60
61
62
63
64
# File 'lib/cocoapods-lzsource/command/gitlab.rb', line 59

def resetInfo()
  if File.exist?(UserPathFile)
    File.delete(UserPathFile)
  end
    puts 'Reset successful!'
end

#startLoadingObject



191
192
193
194
195
196
197
198
199
200
201
202
# File 'lib/cocoapods-lzsource/command/gitlab.rb', line 191

def startLoading
    spin = ['.   ','..  ','... ','....']
    cunt = 0
    while true
      cunt +=1
      str = spin[cunt%4]
      print "Searching:#{str}"
      sleep 0.15
      print "\r"
      
    end
end