Class: Threadfix::Client::Applications::GetId

Inherits:
Object
  • Object
show all
Defined in:
lib/threadfix/client/applications/get_id.rb

Constant Summary collapse

API_VERSION =
'v2.7.5'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ GetId

Returns a new instance of GetId.



10
11
12
# File 'lib/threadfix/client/applications/get_id.rb', line 10

def initialize(options={})
  @app_name = options[:app_name]
end

Instance Attribute Details

#app_nameObject (readonly)

Returns the value of attribute app_name.



8
9
10
# File 'lib/threadfix/client/applications/get_id.rb', line 8

def app_name
  @app_name
end

Instance Method Details

#perform!Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/threadfix/client/applications/get_id.rb', line 14

def perform!
  begin
    puts "GET #{endpoint.to_s}" if ENV['DEBUG']
    r = RestClient.get(
      endpoint.to_s,
      { :accept => "application/json", :Authorization => "APIKEY #{apiKey}" }
    )
    body = JSON.parse(r.body)

    begin
      body.fetch('object')
        .find{ |a| a.fetch('name').downcase == app_name.downcase}.fetch('id')
    rescue => e
      puts "App '#{app_name}' was not found."
      nil # return nil if data not found
    end
  rescue RestClient::NotFound => e
    puts "Endpoint not found (using API version: #{API_VERSION})"
    puts e.message if ENG['DEBUG']
    raise e
  rescue RestClient::ExceptionWithResponse => e
    puts e.message if ENG['DEBUG']
    raise e
  end
end