Class: AutomateSoup::API
- Inherits:
-
Object
- Object
- AutomateSoup::API
- Defined in:
- lib/automate_soup/api.rb
Overview
API class to interact with chef automate
Instance Method Summary collapse
-
#initialize(soup) ⇒ API
constructor
A new instance of API.
-
#orgs(enterprise = 'default') ⇒ Object
Get the organizations given the enterprise.
-
#pipeline(enterprise: 'default', organization: nil, project: nil, pipeline: nil) ⇒ Object
Fetch a projects pipeline under an enterprise, organization pair.
-
#pipelines(enterprise: 'default', organization: nil, project: nil) ⇒ Object
Fetch all project pipelines under an enterprise, organization pair.
-
#project(enterprise: 'default', organization: nil, project: nil) ⇒ Object
Fetch a project under an enterprise, organization pair.
-
#projects(enterprise: 'default', organization: nil) ⇒ Object
Get the projects under and organization given the enterprise.
-
#status ⇒ Object
Get the status of the Automate API.
Constructor Details
#initialize(soup) ⇒ API
Returns a new instance of API
5 6 7 |
# File 'lib/automate_soup/api.rb', line 5 def initialize(soup) @soup = soup end |
Instance Method Details
#orgs(enterprise = 'default') ⇒ Object
Get the organizations given the enterprise.
default.
26 27 28 29 30 31 32 33 34 |
# File 'lib/automate_soup/api.rb', line 26 def orgs(enterprise = 'default') @hash = AutomateSoup::Rest.get( url: "#{@soup.url}/api/v0/e/#{enterprise}/orgs", username: @soup.credentials.username, token: @soup.credentials.token ) raise "Failed to fetch orgs under enterprise #{enterprise}" unless @hash['orgs'] @hash['orgs'] end |
#pipeline(enterprise: 'default', organization: nil, project: nil, pipeline: nil) ⇒ Object
Fetch a projects pipeline under an enterprise, organization pair
default.
102 103 104 105 106 107 108 109 110 |
# File 'lib/automate_soup/api.rb', line 102 def pipeline(enterprise: 'default', organization: nil, project: nil, pipeline: nil) @hash = AutomateSoup::Rest.get( url: "#{@soup.url}/api/v0/e/#{enterprise}/orgs/#{organization}/projects/#{project}/changes?pipeline=#{pipeline}&limit=25", username: @soup.credentials.username, token: @soup.credentials.token ) rescue JSON::ParserError raise "Failed to fetch pipelines under organization #{organization} enterprise #{enterprise}" end |
#pipelines(enterprise: 'default', organization: nil, project: nil) ⇒ Object
Fetch all project pipelines under an enterprise, organization pair
default.
81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/automate_soup/api.rb', line 81 def pipelines(enterprise: 'default', organization: nil, project: nil) @hash = AutomateSoup::Rest.get( url: "#{@soup.url}/api/v0/e/#{enterprise}/orgs/#{organization}/projects/#{project}/pipelines", username: @soup.credentials.username, token: @soup.credentials.token ) @hash['pipelines'] rescue JSON::ParserError raise "Failed to fetch pipelines under organization #{organization} enterprise #{enterprise}" end |
#project(enterprise: 'default', organization: nil, project: nil) ⇒ Object
Fetch a project under an enterprise, organization pair
default.
62 63 64 65 66 67 68 69 70 71 |
# File 'lib/automate_soup/api.rb', line 62 def project(enterprise: 'default', organization: nil, project: nil) @hash = AutomateSoup::Rest.get( url: "#{@soup.url}/api/v0/e/#{enterprise}/orgs/#{organization}/projects/#{project}/pipelines", username: @soup.credentials.username, token: @soup.credentials.token ) rescue JSON::ParserError raise "Failed to fetch projects under organization #{organization} enterprise #{enterprise}" end |
#projects(enterprise: 'default', organization: nil) ⇒ Object
Get the projects under and organization given the enterprise.
default.
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/automate_soup/api.rb', line 43 def projects(enterprise: 'default', organization: nil) @hash = AutomateSoup::Rest.get( url: "#{@soup.url}/api/v0/e/#{enterprise}/orgs/#{organization}/projects", username: @soup.credentials.username, token: @soup.credentials.token ) rescue JSON::ParserError raise "Failed to fetch projects under organization #{organization} enterprise #{enterprise}" end |
#status ⇒ Object
Get the status of the Automate API
12 13 14 15 16 17 18 |
# File 'lib/automate_soup/api.rb', line 12 def status AutomateSoup::Rest.get( url: "#{@soup.url}/api/_status", username: @soup.credentials.username, token: @soup.credentials.token ) end |