class SnapCI::ArtefactGrabber
Public Class Methods
new(owner, repo, branch, pipeline)
click to toggle source
# File lib/snap-ci-artefact-grabber.rb, line 7 def initialize owner, repo, branch, pipeline @owner = owner @repo = repo @branch = branch @pipeline = pipeline get_latest_pipeline end
Public Instance Methods
get_artefact_url_for_stage(stage, filename)
click to toggle source
# File lib/snap-ci-artefact-grabber.rb, line 16 def get_artefact_url_for_stage stage, filename url = "#{base_url}/branch/#{@branch}/artifacts/#{@pipeline}/#{@pipeline_counter}/#{stage}/1/#{filename}" get_from_snap url end
Private Instance Methods
base_url()
click to toggle source
# File lib/snap-ci-artefact-grabber.rb, line 23 def base_url "https://api.snap-ci.com/project/#{@owner}/#{@repo}" end
credentials_set?()
click to toggle source
# File lib/snap-ci-artefact-grabber.rb, line 34 def credentials_set? !( ENV['SNAP_USER'].nil? or ENV['SNAP_APIKEY'].nil? or ENV['SNAP_USER'] == "" or ENV['SNAP_APIKEY'] == "" ) end
get_from_snap(url)
click to toggle source
# File lib/snap-ci-artefact-grabber.rb, line 41 def get_from_snap url unless credentials_set? raise "SNAP_USER or SNAP_APIKEY is not set as ENV vars" end begin open(url, { http_basic_authentication: [ENV['SNAP_USER'], ENV['SNAP_APIKEY']] }).read rescue raise IOError, "Exception whilst trying to get: #{url}" end end
get_latest_pipeline()
click to toggle source
# File lib/snap-ci-artefact-grabber.rb, line 27 def get_latest_pipeline url = "#{base_url}/branch/#{@branch}/pipelines" pipelines = JSON.parse(get_from_snap(url)) @pipeline_counter = pipelines['_embedded']['pipelines'][0]['counter'] end