Class: PuppetHerald::App::ApiImplV1
- Inherits:
-
Object
- Object
- PuppetHerald::App::ApiImplV1
- Defined in:
- lib/puppet-herald/app/api.rb
Overview
An implementation of API v1
Instance Method Summary collapse
-
#get_node(params) ⇒ Array
Gets a node by its ID.
-
#get_report(params) ⇒ Array
Get a report by its ID.
-
#initialize(app) ⇒ ApiImplV1
constructor
Constructor.
-
#nodes ⇒ Array
Gets all nodes.
-
#post_reports(request) ⇒ Array
Creates a new report.
-
#version_json ⇒ Array
Get a app’s artifact information.
Constructor Details
#initialize(app) ⇒ ApiImplV1
Constructor
17 18 19 |
# File 'lib/puppet-herald/app/api.rb', line 17 def initialize(app) @app = app end |
Instance Method Details
#get_node(params) ⇒ Array
Gets a node by its ID
49 50 51 52 53 54 55 56 |
# File 'lib/puppet-herald/app/api.rb', line 49 def get_node(params) id = params[:id] node = PuppetHerald::Models::Node.get_with_reports(id) status = 200 status = 404 if node.nil? body = node.to_json(include: :reports) [status, body] end |
#get_report(params) ⇒ Array
Get a report by its ID
32 33 34 35 36 37 38 39 |
# File 'lib/puppet-herald/app/api.rb', line 32 def get_report(params) id = params[:id] report = PuppetHerald::Models::Report.get_with_log_entries(id) status = 200 status = 404 if report.nil? body = report.to_json(include: :log_entries) [status, body] end |
#nodes ⇒ Array
Gets all nodes
42 43 44 45 |
# File 'lib/puppet-herald/app/api.rb', line 42 def nodes nodes = PuppetHerald::Models::Node.all [200, nodes.to_json] end |
#post_reports(request) ⇒ Array
Creates a new report
23 24 25 26 27 28 |
# File 'lib/puppet-herald/app/api.rb', line 23 def post_reports(request) yaml = request.body.read report = PuppetHerald::Models::Report.create_from_yaml yaml body = { id: report.id }.to_json [201, body] end |
#version_json ⇒ Array
Get a app’s artifact information
59 60 61 62 63 64 65 |
# File 'lib/puppet-herald/app/api.rb', line 59 def version_json ver = {} [:VERSION, :LICENSE, :NAME, :PACKAGE, :SUMMARY, :DESCRIPTION, :HOMEPAGE].each do |const| ver[const.downcase] = PuppetHerald.const_get const end [200, ver.to_json] end |