Skip to content

Commit

Permalink
[api] Refactor Backend::Api::Project
Browse files Browse the repository at this point in the history
...to use Backend::Api::Connection calls
  • Loading branch information
Moises Deniz Aleman committed Sep 29, 2017
1 parent 04f1df1 commit 11bc27c
Showing 1 changed file with 15 additions and 17 deletions.
32 changes: 15 additions & 17 deletions src/api/lib/backend/api/sources/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,52 +3,50 @@ module Backend
module Api
module Sources
class Project
extend Backend::ConnectionHelper

# Returns the attributes for the project
def self.attributes(project, revision)
path = "/source/#{CGI.escape(project)}/_project/_attribute?meta=1"
path += "&rev=#{CGI.escape(revision)}" if revision
Backend::Connection.get(path).body
params = { meta: 1 }
params[:rev] = revision if revision
get(["/source/:project/_project/_attribute", project], params: params)
end

# Writes the xml for attributes
def self.write_attributes(project, login, xml, comment)
path = "/source/#{CGI.escape(project)}/_project/_attribute?meta=1&user=#{CGI.escape(login)}"
path += "&comment=#{CGI.escape(comment)}" if comment
Backend::Connection.put(path, xml)
def self.write_attributes(project, user, content, comment)
params = { meta: 1, user: user }
params[:comment] = comment if comment
put(["/source/:project/_project/_attribute", project], data: content, params: params)
end

# Returns the revisions (mrev) list for a project
def self.revisions(project)
Backend::Connection.get("/source/#{CGI.escape(project)}/_project/_history?deleted=1&meta=1").body
get(["/source/:project/_project/_history", project], params: { meta: 1, deleted: 1 })
end

# Returns the meta file from a project
def self.meta(project, options = {})
path = "/source/#{CGI.escape(project)}/_project/_meta"
options.slice!(:revision, :deleted)
options[:rev] = options.delete(:revision)
path += "?#{options.to_query}" unless options.empty?
Backend::Connection.get(path).body.force_encoding('UTF-8')
get(["/source/:project/_project/_meta", project], params: options, accepted: [:revision, :deleted], rename: { revision: :rev })
end

# Writes a Project configuration
def self.write_configuration(project, configuration)
Backend::Connection.put("/source/#{CGI.escape(project)}/_config", configuration)
put(["/source/:project/_config", project], data: configuration)
end

# Returns the KeyInfo file for the project
def self.key_info(project)
Backend::Connection.get("/source/#{CGI.escape(project)}/_keyinfo?withsslcert=1&donotcreatecert=1").body
get(["/source/:project/_keyinfo", project], params: { withsslcert: 1, donotcreatecert: 1 })
end

# Returns the patchinfo for the project
def self.patchinfo(project)
Backend::Connection.get("/source/#{CGI.escape(project)}/_patchinfo").body
get(["/source/:project/_patchinfo", project])
end

# Moves the source project to the target
def self.move(source, target)
Backend::Connection.post("/source/#{CGI.escape(target)}?cmd=move&oproject=#{CGI.escape(source)}")
post(["/source/:project", target], params: { cmd: :move, oproject: source })
end
end
end
Expand Down

0 comments on commit 11bc27c

Please sign in to comment.