class GitLabHttp

Public Instance Methods

checkUserInfo() click to toggle source
# 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
createUserInfo() click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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
resetInfo() click to toggle source
# File lib/cocoapods-lzsource/command/gitlab.rb, line 59
def resetInfo()
        if File.exist?(UserPathFile)
                File.delete(UserPathFile)
        end
    puts 'Reset successful!'
end
startLoading() click to toggle source
# 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