Class: UrlBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/circle/art.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(repo, build, token = nil) ⇒ UrlBuilder

Returns a new instance of UrlBuilder.



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/circle/art.rb', line 8

def initialize(repo, build, token = nil)
  @repo = repo
  @build = build
  @token = token

  raise "Missing repo" unless @repo
  raise "Missing build" unless @build


  system("mkdir -p downloads/#{build}/artifacts")
  system("mkdir -p downloads/builds")
end

Instance Attribute Details

#buildObject (readonly)

Returns the value of attribute build.



6
7
8
# File 'lib/circle/art.rb', line 6

def build
  @build
end

#repoObject (readonly)

Returns the value of attribute repo.



6
7
8
# File 'lib/circle/art.rb', line 6

def repo
  @repo
end

#tokenObject (readonly)

Returns the value of attribute token.



6
7
8
# File 'lib/circle/art.rb', line 6

def token
  @token
end

Instance Method Details

#download!(parser) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/circle/art.rb', line 48

def download!(parser)
  if Dir[File.join(folder_path, "*")].length > 0
    puts "Already downloaded."
    return
  end

  parser.urls.each_with_index do |url, index|
    cmd = "curl #{url}?circle-token=#{token} --output downloads/#{build}/artifacts/#{parser.filenames[index]}"
    puts "🌐  #{cmd}"
    system(cmd)
  end
end

#download_cmdObject



29
30
31
# File 'lib/circle/art.rb', line 29

def download_cmd
  "curl #{download_url}"
end

#download_json!Object



33
34
35
36
37
38
# File 'lib/circle/art.rb', line 33

def download_json!
  # save json
  unless File.exist?(json_path)
    system(download_cmd + " --output #{json_path}")
  end
end

#download_urlObject



44
45
46
# File 'lib/circle/art.rb', line 44

def download_url
  "https://circleci.com/api/v1.1/project/github/#{repo}/#{build}/artifacts?circle-token=#{token}"
end

#folder_pathObject



21
22
23
# File 'lib/circle/art.rb', line 21

def folder_path
  "downloads/#{build}/artifacts"
end

#json_pathObject



25
26
27
# File 'lib/circle/art.rb', line 25

def json_path
  "downloads/#{build}.json"
end

#urlObject



40
41
42
# File 'lib/circle/art.rb', line 40

def url
  "https://circleci.com/gh/#{repo}/#{build}#artifacts"
end