require 'faraday' require 'faraday_middleware' module OrmDev class HTTPUtil API_THIRD_PLUGIN_PUBLISH = 'http://192.168.2.110:8081/soops/sword/portal?SwordControllerName=uploadPlugin'.freeze #测试地址 def self.send_pulish_plugin_http(username, password, publish_type, podspec_path, zip_path, changelog = '') @spec = Pod::Specification.from_file(podspec_path) cim_sdk_version = '' @spec.dependencies.each do |dep| if 'CIMSDK'.eql? dep.name cim_sdk_version = plugin_version_from(dep.requirement.requirements.flatten.last.to_s) end end # start upload conn_options = { request: { timeout: 1000, open_timeout: 300 } } pgyer_client = Faraday.new(nil, conn_options) do |c| c.request :multipart c.request :url_encoded c.response :json, content_type: /\bjson$/ c.adapter :net_http end params = { 'username' => username || ENV['ORMDEV_CLT_USERNAME'], 'password' => password || ENV['ORMDEV_CLT_PASSWORD'], 'version' => OrmDev::VERSION, 'platform' => 1,# 0:android,1:ios 'type' => 1,# ios:0,1,2 'cipBaseVersion' => cim_sdk_version, #base版本号 'desc' => changelog, } unless podspec_path.nil? then params[File.basename(podspec_path)] = Faraday::UploadIO.new(podspec_path, 'application/octet-stream') if File.exist?(podspec_path) end unless zip_path.nil? then params[File.basename(zip_path)] = Faraday::UploadIO.new(zip_path, 'application/octet-stream') if File.exist?(zip_path) end OrmDev::LogUtil.info '【发布第三方插件】Start upload ...' api = ENV['ORMDEV_CLT_API_THIRD_PLUGIN_PUBLISH'] || API_THIRD_PLUGIN_PUBLISH response = pgyer_client.post api, params info = response.body OrmDev::LogUtil.info "【第三方插件发布】#{api}" OrmDev::LogUtil.info "【第三方插件发布】Upload complate: #{info}" if info && info['status'] && info['status'] == '0000' then OrmDev::LogUtil.info '发布成功' end info end private def self.plugin_version_from(pod_version) if pod_version.nil? then '' else arr = pod_version.split('.') arr.delete_at(arr.size - 1) arr.join('.') end end end end