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 12
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_app_info(app_id) { |env, env| ... } click to toggle source
# File lib/shenzhen/plugins/fir.rb, line 23
def get_app_info(app_id)
  options = {
    :type => 'ios',
    :token => @user_token,
  }

  @connection.get("/api/#{VERSION}/app/info/#{app_id}", options) do |env|
    yield env[:status], env[:body] if block_given?
  end
rescue Faraday::Error::TimeoutError
  say_error "Timed out while geting app info." and abort
end
update_app_info(app_id, options) { |env, env| ... } click to toggle source
# File lib/shenzhen/plugins/fir.rb, line 36
def update_app_info(app_id, options)
  @connection.put("/api/#{VERSION}/app/#{app_id}?token=#{@user_token}", options) do |env|
    yield env[:status], env[:body] if block_given?
  end
rescue Faraday::Error::TimeoutError
  say_error "Timed out while geting app info." and abort
end
upload_build(ipa, options) { |env, env| ... } click to toggle source
# File lib/shenzhen/plugins/fir.rb, line 44
def upload_build(ipa, options)
  connection = Faraday.new(:url => options['url'], :request => { :timeout => 360 }) do |builder|
    builder.request :multipart
    builder.response :json
    builder.use FaradayMiddleware::FollowRedirects
    builder.adapter :net_http
  end

  options = {
    :key => options['key'],
    :token => options['token'],
    :file => Faraday::UploadIO.new(ipa, 'application/octet-stream')
  }

  connection.post('/', 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