Skip to content

Commit

Permalink
Switched to Json.NET on rest proxy class
Browse files Browse the repository at this point in the history
  • Loading branch information
acenolaza committed Apr 21, 2015
1 parent 3b37d8d commit c6b4dde
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 18 deletions.
32 changes: 17 additions & 15 deletions VersionOne.JiraConnector/Rest/JiraRestProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
using System.Dynamic;
using System.Linq;
using System.Net;
using Newtonsoft.Json.Linq;
using RestSharp;
using System.Web.Helpers;
using VersionOne.JiraConnector.Exceptions;

namespace VersionOne.JiraConnector.Rest
Expand Down Expand Up @@ -66,8 +66,8 @@ public Issue[] GetIssuesFromFilter(string issueFilterId)

if (response.StatusCode.Equals(HttpStatusCode.OK))
{
dynamic data = Json.Decode(response.Content);
return ((IEnumerable<dynamic>)data.issues).Select(i => (Issue)CreateIssue(i)).ToArray();
dynamic data = JObject.Parse(response.Content);
return ((JArray)data.issues).Select(CreateIssue).ToArray();
}
if (response.StatusCode.Equals(HttpStatusCode.Unauthorized))
throw new JiraLoginException();
Expand All @@ -81,7 +81,9 @@ public Issue UpdateIssue(string issueKey, string fieldName, string fieldValue)

if (fieldMeta == null)
throw new JiraException("Field metadata is missing", null);
if (fieldMeta.schema.type == null)

var type = fieldMeta.schema["type"];
if (type == null)
throw new JiraException("Field metadata is missing a type", null);

var request = new RestRequest
Expand All @@ -93,7 +95,7 @@ public Issue UpdateIssue(string issueKey, string fieldName, string fieldValue)
request.AddUrlSegment("issueIdOrKey", issueKey);

dynamic body;
if (fieldMeta.schema.type.Equals("array"))
if (type.ToString().Equals("array"))
{
dynamic operation = new ExpandoObject();
((IDictionary<string, object>)operation).Add(fieldName, new List<dynamic>
Expand Down Expand Up @@ -135,8 +137,8 @@ public IList<Item> GetPriorities()

if (response.StatusCode.Equals(HttpStatusCode.OK))
{
dynamic data = Json.Decode(response.Content);
return ((IEnumerable<dynamic>)data).Select(i => new Item(i.id, i.name)).ToList();
var data = JArray.Parse(response.Content);
return data.Select(i => new Item(i["id"].Value<string>(), i["name"].Value<string>())).ToList();
}
if (response.StatusCode.Equals(HttpStatusCode.Unauthorized))
throw new JiraLoginException();
Expand All @@ -156,8 +158,8 @@ public IList<Item> GetProjects()

if (response.StatusCode.Equals(HttpStatusCode.OK))
{
dynamic data = Json.Decode(response.Content);
return ((IEnumerable<dynamic>)data).Select(i => new Item(i.id, i.name)).ToList();
var data = JArray.Parse(response.Content);
return data.Select(i => new Item(i["id"].Value<string>(), i["name"].Value<string>())).ToList();
}
if (response.StatusCode.Equals(HttpStatusCode.Unauthorized))
throw new JiraLoginException();
Expand Down Expand Up @@ -224,8 +226,8 @@ public IEnumerable<Item> GetAvailableActions(string issueId)

if (response.StatusCode.Equals(HttpStatusCode.OK))
{
dynamic data = Json.Decode(response.Content);
return ((IEnumerable<dynamic>)data.transitions).Select(i => new Item(i.id, i.name)).ToList();
dynamic data = JObject.Parse(response.Content);
return ((JArray)data.transitions).Select(i => new Item(i["id"].Value<string>(), i["name"].Value<string>())).ToList();
}
if (response.StatusCode.Equals(HttpStatusCode.Unauthorized))
throw new JiraLoginException();
Expand All @@ -245,8 +247,8 @@ public IEnumerable<Item> GetCustomFields()

if (response.StatusCode.Equals(HttpStatusCode.OK))
{
dynamic data = Json.Decode(response.Content);
return ((IEnumerable<dynamic>)data).Where(i => i.custom).Select(i => new Item(i.id, i.name)).ToList();
var data = JArray.Parse(response.Content);
return data.Where(i => i["custom"].Value<bool>()).Select(i => new Item(i["id"].Value<string>(), i["name"].Value<string>())).ToList();
}
if (response.StatusCode.Equals(HttpStatusCode.Unauthorized))
throw new JiraLoginException();
Expand All @@ -266,7 +268,7 @@ private dynamic GetEditMetadata(string issueIdOrKey)
var response = client.Execute(request);

if (response.StatusCode.Equals(HttpStatusCode.OK))
return Json.Decode(response.Content);
return JObject.Parse(response.Content);
if (response.StatusCode.Equals(HttpStatusCode.Unauthorized))
throw new JiraLoginException();
throw new JiraException(response.StatusDescription, new Exception(response.Content));
Expand All @@ -286,7 +288,7 @@ private Issue GetIssue(string issueIdOrKey)

if (response.StatusCode.Equals(HttpStatusCode.OK))
{
dynamic data = Json.Decode(response.Content);
dynamic data = JObject.Parse(response.Content);
return CreateIssue(data);
}
if (response.StatusCode.Equals(HttpStatusCode.Unauthorized))
Expand Down
5 changes: 4 additions & 1 deletion VersionOne.JiraConnector/VersionOne.JiraConnector.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@
<Reference Include="Microsoft.CSharp">
<Private>False</Private>
</Reference>
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Newtonsoft.Json.6.0.8\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="RestSharp, Version=105.0.1.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\RestSharp.105.0.1\lib\net4\RestSharp.dll</HintPath>
Expand All @@ -85,7 +89,6 @@
</Reference>
<Reference Include="System.Data" />
<Reference Include="System.EnterpriseServices" />
<Reference Include="System.Web.Helpers, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
<Reference Include="System.Web.Services" />
<Reference Include="System.Xml" />
</ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions VersionOne.JiraConnector/packages.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Newtonsoft.Json" version="6.0.8" targetFramework="net451" />
<package id="RestSharp" version="105.0.1" targetFramework="net451" />
</packages>
4 changes: 2 additions & 2 deletions VersionOne.ServiceHost/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@

<!-- Fields to update to prevent creating multiple workitems in V1 -->
<!-- Not all of these fields are required, consult the documentation on how to set them -->
<CreateFieldId>customfield_10001</CreateFieldId> <!-- ID of JIRA field to update when a V1 workitem is created -->
<CreateFieldId>customfield_10000</CreateFieldId> <!-- ID of JIRA field to update when a V1 workitem is created -->
<CreateFieldValue>Open</CreateFieldValue> <!-- Value to set in CreateFieldId -->
<CloseFieldId>customfield_10001</CloseFieldId> <!-- ID of JIRA field to update when a V1 workitem is closed -->
<CloseFieldId>customfield_10000</CloseFieldId> <!-- ID of JIRA field to update when a V1 workitem is closed -->
<CloseFieldValue>Closed</CloseFieldValue> <!-- Value to set in CloseFieldId -->
<ProgressWorkflow>11</ProgressWorkflow> <!-- ID of JIRA status to set after a V1 workitem is created -->
<ProgressWorkflowClosed>151</ProgressWorkflowClosed><!-- ID of JIRA status to set after a V1 workitem is closed -->
Expand Down
4 changes: 4 additions & 0 deletions VersionOne.ServiceHost/VersionOne.ServiceHost.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Newtonsoft.Json.6.0.8\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="RestSharp">
<HintPath>..\packages\RestSharp.105.0.1\lib\net4\RestSharp.dll</HintPath>
</Reference>
Expand Down
1 change: 1 addition & 0 deletions VersionOne.ServiceHost/packages.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Newtonsoft.Json" version="6.0.8" targetFramework="net451" />
<package id="RestSharp" version="105.0.1" targetFramework="net451" />
</packages>

0 comments on commit c6b4dde

Please sign in to comment.