Class: Shenzhen::Plugins::Pgyer::Client

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

Constant Summary collapse

HOSTNAME =
'www.pgyer.com'

Instance Method Summary collapse

Constructor Details

#initialize(user_key, api_key) ⇒ Client

Returns a new instance of Client.


11
12
13
14
15
16
17
18
19
20
# File 'lib/shenzhen/plugins/pgyer.rb', line 11

def initialize(user_key, api_key)
  @user_key, @api_key = user_key, api_key
  @connection = Faraday.new(:url => "http://#{HOSTNAME}", :request => { :timeout => 120 }) do |builder|
    builder.request :multipart
    builder.request :json
    builder.response :json, :content_type => /\bjson$/
    builder.use FaradayMiddleware::FollowRedirects
    builder.adapter :net_http
  end
end

Instance Method Details

#update_app_info(options) ⇒ Object


37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/shenzhen/plugins/pgyer.rb', line 37

def update_app_info(options)
  connection = Faraday.new(:url => "http://#{HOSTNAME}", :request => { :timeout => 120 }) do |builder|
    builder.request :url_encoded
    builder.request :json
    builder.response :logger
    builder.response :json, :content_type => /\bjson$/
    builder.use FaradayMiddleware::FollowRedirects
    builder.adapter :net_http
  end

  options.update({
    :uKey => @user_key,
    :_api_key => @api_key,
  })

  connection.post("/apiv1/app/update", options) do |env|
    yield env[:status], env[:body] if block_given?
  end

rescue Faraday::Error::TimeoutError
  say_error "Timed out while uploading build. Check http://www.pgyer.com/my to see if the upload was completed." and abort
end

#upload_build(ipa, options) ⇒ Object


22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/shenzhen/plugins/pgyer.rb', line 22

def upload_build(ipa, options)
  options.update({
    :uKey => @user_key,
    :_api_key => @api_key,
    :file => Faraday::UploadIO.new(ipa, 'application/octet-stream')
  })

  @connection.post("/apiv1/app/upload", options).on_complete do |env|
    yield env[:status], env[:body] if block_given?
  end

rescue Faraday::Error::TimeoutError
  say_error "Timed out while uploading build. Check http://www.pgyer.com/my to see if the upload was completed." and abort
end