Class: Shenzhen::Plugins::Fir::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/shenzhen/plugins/fir.rb

Constant Summary collapse

HOSTNAME =
'fir.im'
VERSION =
'v2'

Instance Method Summary collapse

Constructor Details

#initialize(user_token) ⇒ Client

Returns a new instance of Client.


12
13
14
15
16
17
18
19
20
21
# 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

Instance Method Details

#get_app_info(app_id) ⇒ Object


23
24
25
26
27
28
29
30
31
32
33
34
# 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) ⇒ Object


36
37
38
39
40
41
42
# 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) ⇒ Object


44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# 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