Skip to content
This repository has been archived by the owner on Jul 24, 2018. It is now read-only.

Commit

Permalink
rough-out rest of SOAP API
Browse files Browse the repository at this point in the history
I have no tests for most of this, but since most of them are queries or
require very little in the way of manipulating data, it's pretty easy
to think that any issues I'll encounter will be because i misstyped something
or because MantisConnect doesn't work.  A third option is the user fat-fingered
or just didn't know what to put in to a field, which I can't help with, yet.
  • Loading branch information
klauern committed Sep 19, 2011
1 parent 3b04dfe commit b7b1dbf
Show file tree
Hide file tree
Showing 5 changed files with 188 additions and 7 deletions.
124 changes: 124 additions & 0 deletions lib/mantisrb/projects.rb
Expand Up @@ -134,6 +134,130 @@ def custom_fields_for(id_num)
}
end


# Get a list of versions that this project has
# @param [Integer] project_id
# @return [Array<Mantis::XSD::ProjectVersionData>] array of
# {Mantis::XSD::ProjectVersionData} objects for each version
def get_versions(project_id)
@session.response_trimmed :mc_project_get_versions, {
project_id: project_id
}
end

# Update the version of the project
# @param [version_id] ID of the *version* of the project, not the project
# id.
# @param [Mantis::XSD::ProjectVersionData] project version data instance
def update_version(version_id, data)
@session.response_trimmed :mc_project_version_update, {
version_id: version_id,
version: data.to_s
}
end

# Delete a version from a project
# @param [Integer] version_id id of the version instance, not the
# project_id
# @return [Boolean] true or false for success
def delete_version(version_id)
@session.response_trimmed :mc_project_version_delete, {
version_id: version_id
}
end


# Get a list of released versions for this project
# @param [Integer] project_id
# @return [Array<Mantis::XSD::ProjectVersionData>] array of
# {Mantis::XSD::ProjectVersionData}
def get_released_versions(project_id)
versions_ary = @session.response_trimmed :mc_project_get_released_versions, {
project_id: project_id
}
versions_ary.map { |version| Mantis::XSD::ProjectVersionData.new version }
end

# Get the unreleased versions that belong to a project
# @param [Integer] project_id
# @return [Array<Mantis::XSD::ProjectVersionData>] array of
# ProjectVersionData
def get_unreleased_versions(project_id)
versions_ary = @session.response_trimmed :mc_project_get_unreleased_versions, {
project_id: project_id
}
versions_ary.map { |version| Mantis::XSD::ProjectVersionData.new version }
end

# Get all attachments (information) for a given project
# @param [Integer] project_id
# @return [Array<Mantis::XSD::ProjectAttachmentData>] array of project
# attachment data
def get_attachments(project_id)
attachments = @session.response_trimmed :mc_project_get_attachments, {
project_id: project_id
}
attachments.map { |attachment| Mantis::XSD::ProjectAttachmentData.new attachment }
end

# Get the data for an attachment for this project
# @param [Integer] project_attachment_id id of the attachment in the
# project
# @return [Base64] Base64 encoded data of the file
def get_attachment(project_attachment_id)
@session.response_trimmed :mc_project_attachment_get, {
project_attachment_id: project_attachment_id
}
end

# Add an attachment to a project
# @param [Integer] project_id
# @param [String] name filename
# @param [String] title Descriptive Title for the file
# @param [String] description
# @param [String] file_type
# @param [Base64] content Base64 encoded data representation
# @return [Integer] id of the attachment for reference later
def add_attachment(project_id, name, title, description, file_type, content)
@session.response_trimmed :mc_project_attachment_add, {
project_id: project_id,
name: name,
title: title,
description: description,
file_type: file_type,
content: content
}
end

# Delete an attachment for a project
# @param [Integer] project_attachment_id
# @return [Boolean] successful deletion or failure
def delete_attachment(project_attachment_id)
@session.response_trimmed :mc_project_attachment_delete, {
project_attachment_id: project_attachment_id
}
end

# Get all Sub Projects in a project
# @param [Integer] project_id
# @return [Array<String>] list of projects
def get_all_subprojects(project_id)
@session.response_trimmed :mc_project_get_all_subprojects, {
project_id: project_id
}
end

# Get the value for the specified user preference
# @param [Integer] project_id
# @param [String] pref_name name of the preference to get
# @return [String]
def get_user_preference(project_id, pref_name)
@session.response_trimmed :mc_user_pref_get_pref, {
project_id: project_id,
pref_name: pref_name
}
end

private

# The SOAP response from MantisConnect is an array of
Expand Down
4 changes: 3 additions & 1 deletion lib/mantisrb/xsd/doc_builder.rb
Expand Up @@ -15,8 +15,10 @@ module Mantis::XSD::DocBuilder
"tns:IssueHeaderData" => Mantis::XSD::IssueHeaderData,
"tns:IssueNoteData" => Mantis::XSD::IssueNoteData,
"tns:ObjectRef" => Mantis::XSD::ObjectRef,
"tns:ProjectAttachmentData" => Mantis::XSD::ProjectAttachmentData,
"tns:ProjectData" => Mantis::XSD::ProjectData,
"tns:RelationshipData" => Mantis::XSD::RelationshipData
"tns:ProjectVersionData" => Mantis::XSD::ProjectVersionData
"tns:RelationshipData" => Mantis::XSD::RelationshipData,
}
# Create a new instance of the XSD type
Expand Down
29 changes: 29 additions & 0 deletions lib/mantisrb/xsd/project_attachment_data.rb
@@ -0,0 +1,29 @@
module Mantis::XSD

class ProjectAttachmentData

include Mantis::XSD::DocBuilder

attr_accessor :id, :filename, :title, :description, :size,
:content_type, :date_submitted, :download_url, :user_id


# Creates a Nokogiri::XML::Element object out of this class
def to_doc(tag_filename)
builder = Nokogiri::XML::Builder.new { |xml|
xml.send(tag_filename, type: "tns:ProjectAttachmentData") do
xml.id_ @id unless @id == nil
xml.filename @name unless @name == nil
xml.title @project_id unless @project_id == nil
xml.description @description unless @description == nil
xml.size @description unless @description == nil
xml.content_type @description unless @description == nil
xml.date_submitted @description unless @description == nil
xml.download_url @description unless @description == nil
xml.user_id @description unless @description == nil
end
}
builder.doc
end # to_doc
end # ProjectData
end # Mantis::XSD
27 changes: 27 additions & 0 deletions lib/mantisrb/xsd/project_version_data.rb
@@ -0,0 +1,27 @@
module Mantis::XSD

class ProjectVersionData

include Mantis::XSD::DocBuilder

attr_accessor :id, :name, :project_id, :date_order, :description,
:released, :obsolete


# Creates a Nokogiri::XML::Element object out of this class
def to_doc(tag_name)
builder = Nokogiri::XML::Builder.new { |xml|
xml.send(tag_name, type: "tns:ProjectVersionData") do
xml.id_ @id unless @id == nil
xml.name @name unless @name == nil
xml.project_id @project_id unless @project_id == nil
xml.date_order @date_order unless @date_order == nil
xml.description @description unless @description == nil
xml.released @released unless @released == nil
xml.obsolete @obsolete unless @obsolete == nil
end
}
builder.doc
end # to_doc
end # ProjectData
end # Mantis::XSD
11 changes: 5 additions & 6 deletions lib/mantisrb/xsd/relationship_data.rb
Expand Up @@ -11,12 +11,11 @@ class RelationshipData
# Mantis servers. it's not provided out-of-the-box
# for the SOAP API, but unless a new type has been defined,
# this should get you somewhere.
DEFAULT_TYPES = {
2: "parent of",
3: "child of",
0: "duplicate of",
4: "has duplicate",
1: "related to"
DEFAULT_TYPES = { 2 => "parent of",
3 => "child of",
0 => "duplicate of",
4 => "has duplicate",
1 => "related to"
}

def to_doc(tag_name)
Expand Down

0 comments on commit b7b1dbf

Please sign in to comment.