|
nvrnight
|
So far the class currently can create Tickets, Milestones, Notebooks, and Messages.
I’m posting here to offer to the public what I have created so far. I hope to get suggestions from you guys of what you would like do be able to do with the API so I can add more features to this class library.
Here’s examples of how to use the class with what features it has so far using a console application(for simplicity) written in VB.Net…
First you would add a reference to the UnFuddleService.dll file, which you can get from the repository posted below.
Imports UnFuddle
Module UnFuddleApp
Sub Main()
Dim ufs As New UnFuddleService(“username”, “password”, “http://.unfuddle.com/api/v1/”, 2)
ufs.CreateTicket(“My Ticket Title”, “My Ticket Description”, TicketPriority.Normal)
ufs.CreateMileStone(“My MileStone”, Now().AddDays(5))
ufs.CreateNotebook(“My Notebook”)
ufs.CreateMessage(“My Message”, “My Message Body”)
End Sub
End Module
If you need to translate this to C#, you can do so here: http://www.developerfusion.com/tools/convert/vb-to-csharp/
I used it first to make sure it was completely accurate so I wouldn’t have to post 2 versions of the same program.
To obtain the current solution to see what code is used or to just grab the .dll(It’s inside the “Compiled” folder)
Subversion URL is http://nvrnight.unfuddle.com/svn/nvrnight_ufs/
Username: guest
Password: guest
I hope what I have made so far is of help to someone, and I hope to gain useful suggestions on stuff to add to it. I am in school and work full time so I can’t guarantee there will be updates daily or anything, but I will do what I can.
Thanks,
James Hastings
nvrnight@gmail.com
|
|
nvrnight
|
If a forum moderator could clean up the way my code looks above I’d be very grateful; I tried editing my post, but it seems to only let me edit the title. I’m not quite sure how to do blocks of codes with these forums, heheh.
Edit: Nvm, found the edit button.
|
|
Joshua Frappier
|
Great work James! Thanks for sharing the code with us all.
|
|
FoxNET78
|
Thanks for this code That work great. But here is a singleton using you code.
Imports System.Text
Imports System.Net
Imports System.IO
Public Class UnfuddleHelper
Private Shared _instance As UnfuddleHelper = New UnfuddleHelper()
Public Enum TicketPriority
Lowest = 1
Low
Normal
High
Highest
End Enum
Public Shared ReadOnly Property Instance() As UnfuddleHelper
Get
Return _instance
End Get
End Property
’Sub Main()
’ Dim ufs As New UnFuddleService( UNFUDDLEUSERNAME, UNFUDDLEPASSWORD, UNFUDDLEURL, 2)
’ ufs.CreateTicket(“My Ticket Title”, “My Ticket Description”, TicketPriority.Normal)
’ ufs.CreateMileStone(“My MileStone”, Now().AddDays(5))
’ ufs.CreateNotebook(“My Notebook”)
’ ufs.CreateMessage(“My Message”, “My Message Body”)
’End Sub
Private _username As String
Private _password As String
Private _URL As String
Public WriteOnly Property ApiUrl() As String
Set(ByVal value As String)
_URL = value
End Set
End Property
Private _projectId As Integer
Public WriteOnly Property ProjectId() As Integer
Set(ByVal value As Integer)
_projectId = value
End Set
End Property
Public Sub Init(ByVal Username As String, ByVal Password As String)
_username = Username
_password = Password
End Sub
Public Sub Init(ByVal Username As String, ByVal Password As String, ByVal Url As String)
Me.Init(Username, Password)
_URL = Url
End Sub
Public Sub Init(ByVal Username As String, ByVal Password As String, ByVal Url As String, ByVal ProjectId As Integer)
Me.Init(Username, Password, Url)
_projectId = ProjectId
End Sub
Public Sub CreateMessage(ByVal Title As String, ByVal Body As String)
Dim xml As String = String.Format(“{0}{1}”, Body, Title)
ExecuteMethod(“/messages.xml”, xml)
End Sub
Public Sub CreateTicket(ByVal Title As String, ByVal Description As String, ByVal Priority As TicketPriority)
Dim xml As String = String.Format(“{0}{1}{2}{3}”, Description, CInt(Priority), _projectId, Title)
ExecuteMethod(“/tickets.xml”, xml)
End Sub
Public Sub CreateNotebook(ByVal Title As String)
Dim xml As String = String.Format(“{0}”, Title)
ExecuteMethod(“/notebooks.xml”, xml)
End Sub
Public Sub CreateMileStone(ByVal Title As String, ByVal DueDate As DateTime)
Dim xml As String = String.Format(“{0}{1}”, DueDate, Title)
ExecuteMethod(“/milestones.xml”, xml)
End Sub
#Region “Private Subs/Functions”
Private Sub ExecuteMethod(ByVal Method As String, ByVal Xml As String)
Dim Url As String = BuildMethod(Method)
Dim result As String = Post(Url, Xml)
If result.Trim.Length 0 Then
Throw New UnFuddleException(result)
End If
End Sub
Private Function Post(ByVal Method As String, ByVal Xml As String) As String
Dim Message As String
Dim basicAuth As String = Convert.ToBase64String(Encoding. ASCII.GetBytes(String.Format(“{0}:{1}”, _username, _password)))
Dim request As WebRequest = WebRequest.Create(Method)
request.Proxy.Credentials = System.Net.CredentialCache.DefaultCredentials
request.Headers.Add(“Authorization”, "Basic " & basicAuth)
request.ContentType = “application/xml”
request.ContentLength = Xml.Length
request.Method = “ POST”
Try
Dim stream As Stream = request.GetRequestStream()
Dim enc As Encoding = Encoding. ASCII
Dim xmlArray() As Byte = enc.GetBytes(Xml)
stream.Write(xmlArray, 0, xmlArray.Length)
Dim response As WebResponse = request.GetResponse()
Dim reader As StreamReader = New StreamReader(response.GetResponseStream())
Message = reader.ReadToEnd().ToString()
Catch ex As Exception
Message = “Unknown Error”
End Try
Return Message
End Function
Private Function BuildMethod(ByVal Method As String) As String
Return String.Format(“{0}projects/{1}{2}”, _URL, _projectId, Method)
End Function
#End Region
End Class
Public Class UnFuddleException
Inherits ApplicationException
Public Sub New(ByVal message As String)
MyBase.New(message)
End Sub
End Class
|
|
FoxNET78
|
Wow. This is ugly! :) put it and vb.net and it should be fine.
|