Skip to content

Commit

Permalink
Contrast 18474 update json serializer (#3)
Browse files Browse the repository at this point in the history
* CONTRAST-18474

* Updated JsonSerializer. Now it uses NewtonSoft.JSON
* Updated Chapter properties field.
* Updated Chapet type field so it uses a enum type.

* CONTRAST-18474

* Updated README with new dependency.
* Updated TeamServerClient tests.

* CONTRAST-18474

* Updated DateTimeConverter.
* Removed OnDeserialized methods. Using JsonConverter instead.
* Added new converter for Unix time dates.
  • Loading branch information
rduran0 committed Nov 10, 2017
1 parent dbe0692 commit b2ba94d
Show file tree
Hide file tree
Showing 30 changed files with 604 additions and 446 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ This library is also provided as a nuget package: https://www.nuget.org/packages

Please see http://www.contrastsecurity.com for more information about how Contrast can help secure your applications.

## Dependencies
* Newtonsoft.Json


## Contrast TeamServer API Credentials
To access the TeamServer API, you'll first need access to TeamServer - either SAAS (https://app.contrastsecurity.com/Contrast/login.html) or an on-premises installation of TeamServer.
Expand Down
4 changes: 2 additions & 2 deletions contrast-rest-dotnet/Http/ServerFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,10 @@ public override string ToString()
filters.Add("expand=" + String.Join(",", Expand));

if (StartDate != null)
filters.Add("startDate=" + DateTimeConverter.ConvertToUnixTime(StartDate));
filters.Add("startDate=" + DateTimeConverter.ConvertToEpochTime(StartDate.Value));

if (EndDate != null)
filters.Add("endDate=" + DateTimeConverter.ConvertToUnixTime(EndDate));
filters.Add("endDate=" + DateTimeConverter.ConvertToEpochTime(EndDate.Value));

if (Severities != null && Severities.Count > 0)
filters.Add("severities=" + String.Join(",", Severities));
Expand Down
4 changes: 2 additions & 2 deletions contrast-rest-dotnet/Http/TraceFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@ public override string ToString()
filters.Add("expand=" + String.Join(",", Expand));

if (StartDate != null)
filters.Add("startDate=" + DateTimeConverter.ConvertToUnixTime(StartDate));
filters.Add("startDate=" + DateTimeConverter.ConvertToEpochTime(StartDate.Value));

if(EndDate != null)
filters.Add("endDate=" + DateTimeConverter.ConvertToUnixTime(EndDate));
filters.Add("endDate=" + DateTimeConverter.ConvertToEpochTime(EndDate.Value));

if (FilterTags != null && FilterTags.Count > 0)
filters.Add("filterTags=" + String.Join(",", FilterTags));
Expand Down
17 changes: 8 additions & 9 deletions contrast-rest-dotnet/Model/Card.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,48 +28,47 @@
*/

using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using Newtonsoft.Json;

namespace contrast_rest_dotnet.Model
{
[DataContract]
[JsonObject]
public class Card
{
/// <summary>
/// Returns the body snippet as a Dictionary
/// </summary>
[DataMember(Name = "body")]
[JsonProperty(PropertyName = "body")]
public object Body { get; set; }

/// <summary>
/// Returns the header snippet as a Dictionary
/// </summary>
[DataMember(Name = "header")]
[JsonProperty(PropertyName = "header")]
public object Header { get; set; }

/// <summary>
/// Hidden status of Card.
/// </summary>
[DataMember(Name = "is_hidden")]
[JsonProperty(PropertyName = "is_hidden")]
public bool IsHidden { get; set; }

/// <summary>
/// Severity level of card.
/// </summary>
[DataMember(Name = "severity")]
[JsonProperty(PropertyName = "severity")]
public string Severity { get; set; }

/// <summary>
/// Card title.
/// </summary>
[DataMember(Name = "title")]
[JsonProperty(PropertyName = "title")]
public string Title { get; set; }

/// <summary>
/// Trace id the card belongs to.
/// </summary>
[DataMember(Name = "traceId")]
[JsonProperty(PropertyName = "traceId")]
public string TraceId { get; set; }
}
}
20 changes: 10 additions & 10 deletions contrast-rest-dotnet/Model/CodeView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,55 +28,55 @@
*/

using System.Collections.Generic;
using System.Runtime.Serialization;
using Newtonsoft.Json;

namespace contrast_rest_dotnet.Model
{
[DataContract]
[JsonObject]
public class CodeView
{
/// <summary>
/// List of code lines.
/// </summary>
[DataMember(Name = "lines")]
[JsonProperty(PropertyName = "lines")]
public List<CodeLine> Lines { get; set; }

/// <summary>
/// If the code view is nested.
/// </summary>
[DataMember(Name = "nested")]
[JsonProperty(PropertyName = "nested")]
public bool Nested { get; set; }
}

[DataContract]
[JsonObject]
public class CodeLine
{
/// <summary>
/// Formatted fragments of code.
/// </summary>
[DataMember(Name = "fragments")]
[JsonProperty(PropertyName = "fragments")]
public List<LineFragment> Fragments { get; set; }

/// <summary>
/// Full line of code.
/// </summary>
[DataMember(Name = "text")]
[JsonProperty(PropertyName = "text")]
public string Text { get; set; }
}

[DataContract]
[JsonObject]
public class LineFragment
{
/// <summary>
/// Type of fragment.
/// </summary>
[DataMember(Name = "type")]
[JsonProperty(PropertyName = "type")]
public string Type { get; set; }

/// <summary>
/// Fragment content.
/// </summary>
[DataMember(Name = "value")]
[JsonProperty(PropertyName = "value")]
public string value { get; set; }
}
}
Loading

0 comments on commit b2ba94d

Please sign in to comment.