Class: Threadfix::Client::Applications::GetId
- Inherits:
-
Object
- Object
- Threadfix::Client::Applications::GetId
- Defined in:
- lib/threadfix/client/applications/get_id.rb
Constant Summary collapse
- API_VERSION =
'2.7.5'
Instance Attribute Summary collapse
-
#app_name ⇒ Object
readonly
Returns the value of attribute app_name.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ GetId
constructor
A new instance of GetId.
- #perform! ⇒ Object
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(={}) @app_name = [:app_name] end |
Instance Attribute Details
#app_name ⇒ Object (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 |
# File 'lib/threadfix/client/applications/get_id.rb', line 14 def perform! begin 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') == app_name}.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})" raise e rescue RestClient::ExceptionWithResponse => e raise e end end |