Class: DeployGate::API::V1::Push

Inherits:
Object
  • Object
show all
Defined in:
lib/deploygate/api/v1/push.rb

Constant Summary collapse

ENDPOINT =
"/users/%s/apps"

Class Method Summary collapse

Class Method Details

.upload(command, file_path, target_user, token, message, distribution_key, disable_notify = false) { ... } ⇒ Hash

Parameters:

  • command (String)
  • file_path (String)
  • target_user (String)
  • token (String)
  • message (String)
  • distribution_key (String)
  • disable_notify (Boolean) (defaults to: false)

Yields:

  • Upload process block

Returns:

  • (Hash)


18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/deploygate/api/v1/push.rb', line 18

def upload(command, file_path, target_user, token, message, distribution_key, disable_notify = false, &process_block)
  res = nil
  env_ci = ENV['CI']
  open(file_path) do |file|
    res = Base.new(token).post(
      sprintf(ENDPOINT, target_user),
      { :file => file ,
        :message => message,
        :distribution_key => distribution_key,
        :disable_notify => disable_notify ? 'yes' : 'no',
        :dg_command => command || '',
        :env_ci => env_ci
      }) { process_block.call unless process_block.nil? }
  end

  upload_results = {
      :error => res['error'],
      :message => res['because']
  }

  results = res['results']
  unless results.nil?
    upload_results.merge!({
        :application_name => results['name'],
        :owner_name => results['user']['name'],
        :package_name => results['package_name'],
        :revision => results['revision'],
        :web_url => Base::BASE_URL + results['path']
    })
  end

  upload_results
end