Class: AppStage::ListFiles

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

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ ListFiles

Returns a new instance of ListFiles.



4
5
6
# File 'lib/list_files.rb', line 4

def initialize(options)
  @options = options
end

Instance Method Details

#executeObject



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

def execute
  begin
    getFileList.each do |rf|
      puts "#{rf['name']}"
    end
    0
  rescue Exception => e
    puts "File listing failed - #{e.message}"
    -1
  end
end

#getFileListObject



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/list_files.rb', line 20

def getFileList
  host = @options[:host] || "https://www.appstage.io"
  raise('Invalid project token') unless @options[:jwt]
  token = @options[:jwt]
  pattern = @options[:list].nil? ? ".*" : @options[:list]

  response = HTTParty.get(host+"/api/live_builds",
      :headers => { 'Content-Type' => 'application/json',
                    'Authorization' => "Bearer #{token}"}
  )
  raise(JSON.parse(response.body)['error']) unless response.code == 200
  files = JSON.parse(response.body)['release_files'].select{|f| f['name'].match(/#{pattern}/)}
end