Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fixed UpdateUserIdentity and UpdateUserIdentityAsync
  • Loading branch information
mozts2005 authored Sep 30, 2017
1 parent 5053911 commit e4dfe33
Show file tree
Hide file tree
Showing 8 changed files with 192 additions and 11 deletions.
12 changes: 12 additions & 0 deletions src/ZendeskApi_v2/Core.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,9 @@ public Core(string zendeskApiUrl, string user, string password, string apiToken,
public T GetByPageUrl<T>(string pageUrl, int perPage = 100)
{
if (string.IsNullOrEmpty(pageUrl))
{
return JsonConvert.DeserializeObject<T>("");
}

var resource = Regex.Split(pageUrl, "api/v2/").Last() + "&per_page=" + perPage;
return RunRequest<T>(resource, RequestMethod.Get);
Expand Down Expand Up @@ -329,13 +331,21 @@ protected bool GenericBoolPut(string resource, object body = null)
protected string GetPasswordOrTokenAuthHeader()
{
if (!ApiToken.IsNullOrWhiteSpace() && !User.IsNullOrWhiteSpace())
{
return GetAuthHeader(User + "/token", ApiToken);
}
else if (!Password.IsNullOrWhiteSpace() && !User.IsNullOrWhiteSpace())
{
return GetAuthHeader(User, Password);
}
else if (!OAuthToken.IsNullOrWhiteSpace())
{
return GetAuthBearerHeader(OAuthToken);
}
else
{
return string.Empty;
}
}

protected string GetAuthBearerHeader(string oAuthToken)
Expand All @@ -353,7 +363,9 @@ protected string GetAuthHeader(string userName, string password)
public async Task<T> GetByPageUrlAsync<T>(string pageUrl, int perPage = 100)
{
if (string.IsNullOrEmpty(pageUrl))
{
return JsonConvert.DeserializeObject<T>("");
}

var resource = Regex.Split(pageUrl, "api/v2/").Last() + "&per_page=" + perPage;
return await RunRequestAsync<T>(resource, RequestMethod.Get);
Expand Down
10 changes: 8 additions & 2 deletions src/ZendeskApi_v2/Extensions/StringExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,17 @@ internal static bool IsNullOrWhiteSpace(this string value)

// this is needed because .net 3.5 and older don't have
// string.IsNullOrWhiteSpace
if (value == null) return true;
if (value == null)
{
return true;
}

for (int i = 0; i < value.Length; i++)
{
if (!char.IsWhiteSpace(value[i])) return false;
if (!char.IsWhiteSpace(value[i]))
{
return false;
}
}

return true;
Expand Down
6 changes: 6 additions & 0 deletions src/ZendeskApi_v2/Models/GroupResponseBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,14 @@ public long TotalPages
private long GetPageFromParameter()
{
if (string.IsNullOrEmpty(PreviousPage))
{
return 1;
}

if (string.IsNullOrEmpty(NextPage))
{
return TotalPages;
}

Dictionary<string, string> dict = NextPage.GetQueryStringDict();
if (dict.ContainsKey("page"))
Expand All @@ -68,7 +72,9 @@ private int GetPageSizeFromParameter()
{
var page = NextPage ?? PreviousPage;
if (page == null)
{
return 100;
}

Dictionary<string, string> dict = page.GetQueryStringDict();
if (dict.ContainsKey("per_page"))
Expand Down
6 changes: 6 additions & 0 deletions src/ZendeskApi_v2/Requests/Attachments.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,19 @@ public Upload UploadAttachments(IEnumerable<ZenFile> files, int? timeout = null)
{
var zenFiles = files as IList<ZenFile> ?? files.ToList();
if (!zenFiles.Any())
{
return null;
}

var res = UploadAttachment(zenFiles.First(), timeout);

if (zenFiles.Count() > 1)
{
var otherFiles = zenFiles.Skip(1);
foreach (var curFile in otherFiles)
{
res = UploadAttachment(curFile, res.Token, timeout);
}
}

return res;
Expand Down Expand Up @@ -102,7 +106,9 @@ public async Task<Upload> UploadAttachmentsAsync(IEnumerable<ZenFile> files, int
{
var zenFiles = files as IList<ZenFile> ?? files.ToList();
if (!zenFiles.Any())
{
return null;
}

var res = UploadAttachmentAsync(zenFiles.First(), timeout);

Expand Down
3 changes: 3 additions & 0 deletions src/ZendeskApi_v2/Requests/HelpCenter/Categories.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ public IndividualCategoryResponse GetCategoryById(long id)
public IndividualCategoryResponse CreateCategory(Category category)
{
if (string.IsNullOrEmpty(category.Locale))
{
category.Locale = Locale;
}

var body = new { category };

return GenericPost<IndividualCategoryResponse>("help_center/categories.json", body);
Expand Down
8 changes: 8 additions & 0 deletions src/ZendeskApi_v2/Requests/Tickets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,10 @@ public JobStatusResponse BulkImportTickets(IEnumerable<TicketImport> tickets)
public IndividualTicketResponse UpdateTicket(Ticket ticket, Comment comment = null)
{
if (comment != null)
{
ticket.Comment = comment;
}

var body = new { ticket };

return GenericPut<IndividualTicketResponse>($"{_tickets}/{ticket.Id}.json", body);
Expand Down Expand Up @@ -745,7 +748,10 @@ public async Task<JobStatusResponse> BulkImportTicketsAsync(IEnumerable<TicketIm
public async Task<IndividualTicketResponse> UpdateTicketAsync(Ticket ticket, Comment comment = null)
{
if (comment != null)
{
ticket.Comment = comment;
}

var body = new { ticket };

return await GenericPutAsync<IndividualTicketResponse>($"{_tickets}/{ticket.Id}.json", body);
Expand Down Expand Up @@ -957,7 +963,9 @@ private string GetResourceStringWithSideLoadOptionsParam(string resource, Ticket
if (sideLoadOptions != TicketSideLoadOptionsEnum.None)
{
if (sideLoadOptions.HasFlag(TicketSideLoadOptionsEnum.None))
{
sideLoadOptions &= ~TicketSideLoadOptionsEnum.None;
}

string sideLoads = sideLoadOptions.ToString().ToLower().Replace(" ", "");
resource += (resource.Contains("?") ? "&" : "?") + "include=" + sideLoads;
Expand Down
Loading

0 comments on commit e4dfe33

Please sign in to comment.