class Shenzhen::Plugins::Fir::Client

Constants

HOSTNAME
VERSION

Public Class Methods

new(user_token) click to toggle source
# File lib/shenzhen/plugins/fir.rb, line 13
def initialize(user_token)
  @user_token = user_token

  @connection = Faraday.new(:url => "http://#{HOSTNAME}") do |builder|
    builder.request :url_encoded
    builder.response :json
    builder.use FaradayMiddleware::FollowRedirects
    builder.adapter :net_http
  end
end

Public Instance Methods

get_upload_ticket(bundle_id) { |env, env| ... } click to toggle source

get upload ticket

# File lib/shenzhen/plugins/fir.rb, line 28
def get_upload_ticket bundle_id
  options = {
    :type => 'ios',
    :bundle_id => bundle_id,
    :api_token => @user_token
  }

  response = @connection.post('/apps', options) do |env|
    yield env[:status], env[:body] if block_given?
  end

rescue Faraday::Error::TimeoutError
  say_error "Timed out while geting upload ticket." and abort 
end
upload_file_and_update_app_info(ipa, options) { |env, env| ... } click to toggle source

upload file

# File lib/shenzhen/plugins/fir.rb, line 46
def upload_file_and_update_app_info ipa, options
  connection = Faraday.new(:url => options['upload_url'], :request => { :timeout => 360 }) do |builder|
    builder.request :multipart
    builder.response :json
    builder.use FaradayMiddleware::FollowRedirects
    builder.adapter :net_http
  end

  form_options = {
    :key => options['key'],
    :token => options['token'],
    :file => Faraday::UploadIO.new(ipa, 'application/octet-stream'),
    "x:name" => options[:name],
    "x:version" => options[:version],
    "x:build" => options[:build],
    "x:release_type" => options[:release_type],
    "x:changelog" => options[:changelog]
  }
  p "=================uploading====================="
  connection.post('/', form_options).on_complete do |env|
    yield env[:status], env[:body] if block_given?
  end
rescue Errno::EPIPE
  say_error "Upload failed. Check internet connection is ok." and abort
rescue Faraday::Error::TimeoutError
  say_error "Timed out while uploading build. Check https://fir.im// to see if the upload was completed." and abort
end