class OrmDev::HTTPUtil

Constants

API_THIRD_PLUGIN_CHECK
API_THIRD_PLUGIN_PUBLISH

Public Class Methods

send_check_plugin_http(username, password, publish_type, podspec_path, zip_path, changelog = '') click to toggle source
# File lib/ormdev/source/util/http_util.rb, line 10
def self.send_check_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
      'pluginName' => @spec.name.gsub(/^CIP/, 'cip'),
      'pluginVersion' => @spec.version.to_s,
      'pluginBaseVersion' => cim_sdk_version, #base版本号
  }

  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 '【发布第三方插件】开始上传 ...'

  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
send_pulish_plugin_http(username, password, publish_type, podspec_path, zip_path, changelog = '') click to toggle source
# File lib/ormdev/source/util/http_util.rb, line 63
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 '【发布第三方插件】开始上传 ...'

  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 Class Methods

plugin_version_from(pod_version) click to toggle source
# File lib/ormdev/source/util/http_util.rb, line 120
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