class XZGit::XZUpVersion
Public Class Methods
new(argv)
click to toggle source
Calls superclass method
XZGit::Command::new
# File lib/mrbin/xzcommand/xzupversion.rb, line 14 def initialize(argv) @version = argv.option('version','') super end
options()
click to toggle source
Calls superclass method
# File lib/mrbin/xzcommand/xzupversion.rb, line 9 def self.options [ ['--version','new version'] ].concat(super) end
Public Instance Methods
run()
click to toggle source
# File lib/mrbin/xzcommand/xzupversion.rb, line 33 def run update_app_version(@version) updateserver(@version) end
validate!()
click to toggle source
Calls superclass method
# File lib/mrbin/xzcommand/xzupversion.rb, line 19 def validate! super if @version.empty? puts "--version is required" exit(1) end root_path = Dir.pwd() dev_path = "#{root_path}/Podfile" if !File.exist?(dev_path) puts "not found podfile,must excute in podfile directory" exit(1) end end
Private Instance Methods
parseurl(urlstr)
click to toggle source
# File lib/mrbin/xzcommand/xzupversion.rb, line 72 def parseurl(urlstr) uri = URI(urlstr) querystr = uri.query queryarr = querystr.split('&') parameters = Hash.new queryarr.each do |para| paraarr = para.split('=') parameters[paraarr[0]] = paraarr[1] end allkeys = parameters.keys.sort() kw = uri.path allkeys.each do |key| kw = kw + '|' + key kw = kw + '|' + parameters[key] end kw += '|2016v001' kcount = URI.encode_www_form_component(kw).length kcount = kcount % 5 + 2 sign = kw while kcount > 0 sign = Digest::MD5.hexdigest(sign) kcount -= 1 end parameters['xzsign'] = 'md5_' + sign new_query = URI.encode_www_form(parameters) uri.query = new_query uri end
startrequest(uri)
click to toggle source
# File lib/mrbin/xzcommand/xzupversion.rb, line 101 def startrequest(uri) https = Net::HTTP.new(uri.host, Net::HTTP.https_default_port) https.use_ssl = true https.ssl_timeout = 2 https.verify_mode = OpenSSL::SSL::VERIFY_PEER libpath = File.expand_path('../../../../lib',__FILE__) https.cert = OpenSSL::X509::Certificate.new(File.read("#{libpath}/filename.crt")) https.key = OpenSSL::PKey::RSA.new(File.read("#{libpath}/newfile.key.pem")) https.start do |http| req = Net::HTTP::Get.new(uri) res = https.request(req) if res.code == '200' jsres = JSON.parse(res.body) if jsres['status'] == 200 File.open('XZServerContents.json','w') do |resf| JSON.dump(jsres,resf) end `plutil -convert xml1 XZServerContents.json -o XZServerContents.plist` `rm XZServerContents.json` `mv XZServerContents.plist XZTenant/XZServerContents.plist` end end end end
update_app_version(version)
click to toggle source
# File lib/mrbin/xzcommand/xzupversion.rb, line 40 def update_app_version(version) Find.find(Dir.pwd()) do |file| filename = File.basename(file) if !file.include?('DevPods') if filename == 'XZAppDelegate.m' content = File.read(file) content = content.gsub(/setGlobalAPIVersion\(@"(.)+?"\);/,"setGlobalAPIVersion(@\"#{version}\");") File.open(file,'w') do |wf| wf.write(content) end elsif filename == 'XZTenant-Info.plist' `plutil -replace CFBundleShortVersionString -string #{version} #{file}` elsif filename == 'Info.plist' && file.include?('SiriShortcuts') `plutil -replace CFBundleShortVersionString -string #{version} #{file}` end end end end
updateserver(version)
click to toggle source
# File lib/mrbin/xzcommand/xzupversion.rb, line 60 def updateserver(version) timestamp = Time.now.to_i urlpath = "https://securewireless.xiaozhu.com/app/xzfk/ios/#{version}/global/preInformation?" idfap = "uniqueId=8D6CCD72-D9C3-4949-A719-959F8EDFA396&" bundletype = "bundleType=xiaozhu&" timestap = "_={#{timestamp}}&" typestr = "type=serverSideContents" url = urlpath+idfap+bundletype+timestap+typestr uri = parseurl(url) startrequest(uri) end