class BlastOff::Services::Qiniu

Public Class Methods

new(ipa_file_path:nil, access_key:'', secret_key:'', bucket:'', custom_domain:'', use_secure_connection:true) click to toggle source
# File lib/blast_off/services/qiniu.rb, line 9
def initialize(ipa_file_path:nil, access_key:'', secret_key:'', bucket:'', custom_domain:'', use_secure_connection:true)
  @ipa_file_path = ipa_file_path
  @ipa_file = ::IpaReader::IpaFile.new(ipa_file_path)
  @bucket = bucket
  @custom_domain = custom_domain || "#{@bucket}.qiniudn.com"
  @use_secure_connection = use_secure_connection

  ::Qiniu::RS.establish_connection!(
    enable_debug: false,
    block_size: File.size(@ipa_file_path) + 100,
    access_key: access_key,
    secret_key: secret_key
  )
end

Public Instance Methods

distribute() click to toggle source
# File lib/blast_off/services/qiniu.rb, line 24
def distribute
  upload_string(
    template.manifest_plist("#{base_url}/#{@ipa_file.name}.ipa"),
    'manifest.plist',
    'application/octet-stream'
  )
  upload_string(
    template.html("#{base_url}/manifest.plist"),
    'index.html',
    'text/html'
  )
  upload_file(
    @ipa_file_path,
    "#{@ipa_file.name}.ipa",
    'application/octet-stream'
  )

  "#{base_url}/index.html"
end

Private Instance Methods

base_path() click to toggle source
# File lib/blast_off/services/qiniu.rb, line 46
def base_path
  "#{@ipa_file.name}/#{@ipa_file.version}"
end
base_url() click to toggle source
# File lib/blast_off/services/qiniu.rb, line 50
def base_url
  "#{protocal}://#{@custom_domain}/#{base_path}"
end
protocal() click to toggle source
# File lib/blast_off/services/qiniu.rb, line 54
def protocal
  @use_secure_connection ? "https" : "http"
end
template() click to toggle source
# File lib/blast_off/services/qiniu.rb, line 84
def template
  @template ||= Template.new(@ipa_file)
end
upload_file(filepath, name, mime_type) click to toggle source
# File lib/blast_off/services/qiniu.rb, line 70
def upload_file(filepath, name, mime_type)
  key = "#{base_path}/#{name}"
  upload_token = ::Qiniu::RS.generate_upload_token(
    scope: "#{@bucket}:#{key}"
  )
  ::Qiniu::RS.upload_file(
    uptoken: upload_token,
    file: filepath,
    mime_type: mime_type,
    bucket: @bucket,
    key: key
  )
end
upload_string(string, name, mime_type) click to toggle source
# File lib/blast_off/services/qiniu.rb, line 58
def upload_string(string, name, mime_type)
  file = Tempfile.new(name)
  begin
    file.write(string)
    file.rewind
    upload_file(file.path, name, mime_type)
  ensure
    file.close
    file.unlink
  end
end