Class: OpenBuildServiceAPI::API::Projects
- Inherits:
-
Object
- Object
- OpenBuildServiceAPI::API::Projects
- Defined in:
- lib/api/projects.rb
Instance Method Summary collapse
- #create(name, meta = nil) ⇒ Object
- #exists?(name) ⇒ Boolean
- #find(name) ⇒ Object
- #find!(name) ⇒ Object
-
#initialize(connection) ⇒ Projects
constructor
A new instance of Projects.
- #list ⇒ Object
Constructor Details
#initialize(connection) ⇒ Projects
Returns a new instance of Projects.
4 5 6 |
# File 'lib/api/projects.rb', line 4 def initialize(connection) @connection = connection end |
Instance Method Details
#create(name, meta = nil) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/api/projects.rb', line 8 def create(name, = nil) raise ProjectAlreadyExistsError.new("Project name '#{name}' has already been taken.") if exists?(name) = ? : (name) begin response = @connection.send_request(:put, "/source/#{CGI.escape(name)}/_meta", request_body: ) rescue RequestError => err raise ProjectCreationPermissionError.new(err.error_summary) if err.error_code == 'create_project_no_permission' raise end return Project.new(projects: self, connection: @connection, name: name) if response.is_a?(Net::HTTPOK) raise ProjectCreationFailedError.new("could not create project. API responded with '#{response.code}': #{response.body}") end |
#exists?(name) ⇒ Boolean
29 30 31 |
# File 'lib/api/projects.rb', line 29 def exists?(name) !!find(name) end |
#find(name) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/api/projects.rb', line 33 def find(name) begin project_data = Nokogiri::XML(@connection.send_request(:get, "/source/#{CGI.escape(name)}").body) packages = project_data.xpath('//entry').map { |package| package.attr('name') } Project.new(projects: self, name: name, packages: packages, connection: @connection) rescue RequestError => err return if err.error_code == 'unknown_project' raise end end |
#find!(name) ⇒ Object
45 46 47 48 49 50 |
# File 'lib/api/projects.rb', line 45 def find!(name) project = find(name) raise ProjectNotFoundError.new("Project '#{name}' does not exist.") unless project project end |