Class: Buildbox::Artifact::Uploader

Inherits:
Object
  • Object
show all
Includes:
Celluloid, Celluloid::Logger
Defined in:
lib/buildbox/artifact/uploader.rb

Instance Method Summary collapse

Constructor Details

#initialize(api, access_token, build, artifacts) ⇒ Uploader

Returns a new instance of Uploader.



9
10
11
12
13
14
# File 'lib/buildbox/artifact/uploader.rb', line 9

def initialize(api, access_token, build, artifacts)
  @api          = api
  @access_token = access_token
  @build        = build
  @artifacts    = artifacts
end

Instance Method Details

#prepare_and_uploadObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/buildbox/artifact/uploader.rb', line 16

def prepare_and_upload
  info "Preparing #{@artifacts.count} artifacts for upload"

  responses = @api.create_artifacts(@access_token, @build, @artifacts)
  responses.each do |response|
    artifact = @artifacts.find { |artifact| artifact.id == response['id'] }

    artifact.remote_id           = response['artifact']['id']
    artifact.upload_instructions = response['artifact']['uploader']
  end

  @artifacts.each do |artifact|
    Celluloid::Actor[:artifact_poster_pool].async.post(@api, @access_token, @build, artifact)
  end
end