Class: UrlBuilder
- Inherits:
-
Object
- Object
- UrlBuilder
- Defined in:
- lib/circle/art.rb
Instance Attribute Summary collapse
-
#build ⇒ Object
readonly
Returns the value of attribute build.
-
#repo ⇒ Object
readonly
Returns the value of attribute repo.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
Instance Method Summary collapse
- #download!(parser) ⇒ Object
- #download_cmd ⇒ Object
- #download_json! ⇒ Object
- #download_url ⇒ Object
- #folder_path ⇒ Object
-
#initialize(repo, build, token = nil) ⇒ UrlBuilder
constructor
A new instance of UrlBuilder.
- #json_path ⇒ Object
- #url ⇒ Object
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
#build ⇒ Object (readonly)
Returns the value of attribute build.
6 7 8 |
# File 'lib/circle/art.rb', line 6 def build @build end |
#repo ⇒ Object (readonly)
Returns the value of attribute repo.
6 7 8 |
# File 'lib/circle/art.rb', line 6 def repo @repo end |
#token ⇒ Object (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_cmd ⇒ Object
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_url ⇒ Object
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_path ⇒ Object
21 22 23 |
# File 'lib/circle/art.rb', line 21 def folder_path "downloads/#{build}/artifacts" end |
#json_path ⇒ Object
25 26 27 |
# File 'lib/circle/art.rb', line 25 def json_path "downloads/#{build}.json" end |
#url ⇒ Object
40 41 42 |
# File 'lib/circle/art.rb', line 40 def url "https://circleci.com/gh/#{repo}/#{build}#artifacts" end |