class Pod::Command::Jyanalyzer::App

Public Class Methods

new(argv) click to toggle source
Calls superclass method
# File lib/cocoapods-jyanalyzer/command/jyanalyzer/app.rb, line 19
def initialize(argv)
  @pods = argv.arguments!
  super
end

Public Instance Methods

run() click to toggle source
# File lib/cocoapods-jyanalyzer/command/jyanalyzer/app.rb, line 24
def run

  appId = ""
  branch = ""
  packageId = ""
  businessId = ""
  componentId = ""
  api_url = "https://sunflower.hellobike.cn:20000/plugin/setDependLibrary"

  @pods.each do |item|
    map = item.split("=")
    if map[0] == "appId"
      appId = map[1]
    elsif map[0] == "branch"
      branch=map[1]
    elsif map[0] == "packageId"
      packageId = map[1]
    elsif map[0] == "businessId"
      businessId = map[1]
    elsif map[0] == "componentId"
      componentId = map[1]
    elsif map[0] == "api_url"
      api_url = map[1]
    else
      
    end
  end
  
  if appId.empty? 
    UI.puts 'appId 不可为空'
    exit 2
  end

  if branch.empty? 
    UI.puts 'branch 不可为空'
    exit 2
  end

  if packageId.empty? 
    UI.puts 'packageId 不可为空'
    exit 2
  end


  verify_podfile_exists!
  installer = installer_for_config
  installer.repo_update = repo_update?(:default => true)
  # installer.clean_install = @clean_install
  UI.puts 'Update all pods'.yellow
  installer.update = true
  installer.prepare
  installer.resolve_dependencies
  pod_targets = installer.pod_targets;

  Pod::UI.puts "获取app所依赖的库和版本, 使用: pod jyanalyzer app"
  names = Array.new
  pod_targets.each do |item|
    map = Hash["name" => item.pod_name,"version" => item.version]
    names.push(map)
  end

  body = Hash["appId" => appId,
  "branch" => branch,
  "packageId" => packageId,
  "businessId" => businessId,
  "componentId" => componentId,
  "appDependLibraryVOList" => names]

  # Pod::UI.puts JSON.pretty_generate(body).yellow

  
  url = URI.parse(api_url)
  http = Net::HTTP.new(url.host, url.port)
  http.use_ssl = true if url.scheme == "https"  # enable SSL/TLS
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE #这个也很重要
  # 设置请求参数
  data = body.to_json
  # 设置请求头
  header = {'content-type':'application/json'}
  response = http.post(url, data, header)
  
  # puts response.body
  # puts response.code
  
  if "#{response.code}" == "200"
    result = JSON.parse(response.body)
    if result["status"] == 0
      puts "请求成功"
    else
      puts "返回结果一异常"
      exit 2
    end

  else
    puts "请求服务器失败"
    exit 2
  end

end