Class: Pod::Podfile

Inherits:
Object
  • Object
show all
Defined in:
lib/ppdbiu.rb

Instance Method Summary collapse

Instance Method Details

#handleResponse(url, response) ⇒ Object

处理网络请求返回来的内容

{

"result": 0,
"codeMsg": "",
"resultMessage": "响应成功",
"content": [
  {
    "dependencyName": "AFNetworking",
    "componentVersion": "~> 3.2.0"
  }
   ]
}

Parameters:

  • response

    应返回json数据结构,如下:



131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/ppdbiu.rb', line 131

def handleResponse(url, response)
  if response.ok?
    body = JSON.parse(response.body)
    result = body["result"]
    if result == 0
      content = body["content"]
      UI.title content
      content
    else
      resultMessage = body["resultMessage"]
      CoreUI.warn "Request to #{url} has error - #{resultMessage}"
      nil
    end
  else
    CoreUI.warn "Request to #{url} failed - #{response.status_code}"
    nil
  end
end

#makeup_pods(url, params, method, ignores = []) ⇒ Object

从url获取依赖并进行依赖安装

Parameters:

  • url

    获取依赖配置的请求url

  • params

    获取依赖配置的请求参数

  • method

    获取依赖配置的请求方式

  • ignores (defaults to: [])

    依赖安装忽略列表,默认为空



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

def makeup_pods(url, params, method, ignores = [])
  UI.title "makeup pods dependency from #{url}"
  file = "dependency.json"
  dependencies = peform_request(url, params, method)
  if dependencies
    #1.保存json
    File.delete(file) if File.exist?(file)
    File.open(file, "w") { |io|  io.syswrite(JSON.generate(dependencies))}
    #2.安装依赖
    ppd_pod(dependencies, ignores)
  else
    #1.读取本地保存的json
    json = File.read(file) if File.exist?(file)
    dependencies = JSON.parse(json)
    #2.安装依赖
    ppd_pod(dependencies, ignores) if dependencies
  end
end

#peform_request(url, params, method) ⇒ Object

处理获取依赖的网络请求

Parameters:

  • url

    请求的url

  • paras

    请求的参数

  • method

    请求的方式



101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/ppdbiu.rb', line 101

def peform_request(url, params, method)
  require 'rest'
  require 'json'

  headers = {'Accept' => 'application/json, */*', 'Content-Type' => 'application/json; charset=utf-8'}
  if 'GET' == method || 'get' == method
    response = REST.get(url, headers, params)
    handleResponse(url, response)
  elsif 'POST' == method || 'post' == method
    response = REST.post(url, params.to_json, headers)
    handleResponse(url, response)
  end
end

#ppd_pod(dependencies, ignores) ⇒ Object

安装依赖,在安装依赖的过程中判断是否在ignores中, 如果在ignores中则忽略不进行依赖安装, 如果不在ignores,判断是否有componentVersion,优先是用版本进行安装,否则进行url、tag、commit等配置进行安装依赖

Parameters:

  • dependencies

    依赖列表

  • ignores

    忽略列表



54
55
56
57
58
59
60
61
62
63
64
65
66
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
# File 'lib/ppdbiu.rb', line 54

def ppd_pod(dependencies, ignores)
  dependencies.each { |value|
    componentName = value.fetch("dependencyName", nil)
    unless componentName
      return
    end
    # 判断依赖是否在ignores中,如果在则略过
    if ignores
      isIgnore = false;
      ignores.each { |ignore|
        if ignore == componentName
          isIgnore = true
          break
        end
      }
      if isIgnore
        next
      end
    end


    version = value.fetch("componentVersion", nil)
    if version
      pod(componentName, version)
    else
      hash = {}
      value.each{ |rKey, rValue|
        hash[:git] = rValue if rKey == "gitUrl"
        hash[:branch] = rValue if rKey == "componentBranch"
        hash[:tag] = rValue if rKey == "tag"
        hash[:commit] = rValue if rKey == "commit"
        hash[:configuration] = rValue if rKey == "configuration"
        hash[:path] = rValue if rKey == "path"
        hash[:podspec] = rValue if rKey == "podspec"
        hash[:subspecs] = rValue if rKey == "subspecs"
      }
      pod(componentName, hash)
    end
  }
end