Skip to content

Commit

Permalink
Merge pull request #93 from hubspot-net/psypher9/92-remove-flurl
Browse files Browse the repository at this point in the history
Removes Flurl dependency
  • Loading branch information
Psypher9 authored Oct 9, 2020
2 parents bbf9808 + ad3d02e commit 5a4f646
Show file tree
Hide file tree
Showing 10 changed files with 110 additions and 119 deletions.
13 changes: 7 additions & 6 deletions HubSpot.NET/Api/Company/HubSpotCompanyApi.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
namespace HubSpot.NET.Api.Company
{
using Flurl;
using HubSpot.NET.Api.Company.Dto;
using HubSpot.NET.Core;
using HubSpot.NET.Core.Abstracts;
using HubSpot.NET.Core.Interfaces;
using RestSharp;
using System;
using System.Linq;
using System.Net;
using System.Net;

public class HubSpotCompanyApi : ApiRoutable, IHubSpotCompanyApi
public class HubSpotCompanyApi : ApiRoutable, IHubSpotCompanyApi
{
private readonly IHubSpotClient _client;
public override string MidRoute => "/companies/v2";
Expand Down Expand Up @@ -79,13 +78,15 @@ public CompanyListHubSpotModel<CompanyHubSpotModel> List(ListRequestOptions opts
{
opts = opts ?? new ListRequestOptions();

var path = GetRoute<CompanyHubSpotModel>("companies", "paged").SetQueryParam(QueryParams.COUNT, opts.Limit);
string path = GetRoute<CompanyHubSpotModel>("companies", "paged");

path += $"{QueryParams.COUNT}={opts.Limit}";

if (opts.PropertiesToInclude.Any())
path.SetQueryParam(QueryParams.PROPERTIES, opts.PropertiesToInclude);
path += $"{QueryParams.PROPERTIES}={opts.PropertiesToInclude}";

This comment has been minimized.

Copy link
@radek-petrik-se

radek-petrik-se Nov 25, 2020

There should be: path += $"&{QueryParams.PROPERTIES}={opts.PropertiesToInclude}"


if (opts.Offset.HasValue)
path = path.SetQueryParam(QueryParams.OFFSET, opts.Offset);
path += $"{QueryParams.OFFSET}={opts.Offset}";

return _client.Execute<CompanyListHubSpotModel<CompanyHubSpotModel>, ListRequestOptions>(path, opts);
}
Expand Down
65 changes: 34 additions & 31 deletions HubSpot.NET/Api/Contact/HubSpotContactApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using Flurl;
using System.Net;
using HubSpot.NET.Api.Contact.Dto;
using HubSpot.NET.Core;
using HubSpot.NET.Core.Abstracts;
Expand Down Expand Up @@ -156,16 +155,17 @@ public ContactHubSpotModel GetByUserToken(string userToken, bool IncludeHistory
/// <returns>A list of contacts</returns>
public ContactListHubSpotModel<ContactHubSpotModel> List(ListRequestOptions opts = null)
{
opts = opts ?? new ListRequestOptions();
opts = opts ?? new ListRequestOptions();

var path = GetRoute<ContactHubSpotModel>("lists", "all", "contacts","all")
.SetQueryParam(QueryParams.COUNT, opts.Limit);
string path = GetRoute<ContactHubSpotModel>("lists", "all", "contacts", "all");

path += $"{QueryParams.COUNT}={opts.Limit}";

if (opts.PropertiesToInclude.Any())
path.SetQueryParam(QueryParams.PROPERTY, opts.PropertiesToInclude);
path += $"{QueryParams.PROPERTY}={opts.PropertiesToInclude}";

if (opts.Offset.HasValue)
path = path.SetQueryParam(QueryParams.VID_OFFSET, opts.Offset);
path = path += $"{QueryParams.VID_OFFSET}={opts.Offset}";

return _client.Execute<ContactListHubSpotModel<ContactHubSpotModel>, ListRequestOptions>(path, opts);
}
Expand Down Expand Up @@ -209,21 +209,22 @@ public ContactListHubSpotModel<ContactHubSpotModel> RecentlyUpdated(ListRecentRe
{
opts = opts ?? new ListRecentRequestOptions();

Url path = GetRoute<ContactHubSpotModel>("lists", "recently_updated","contacts","recent")
.SetQueryParam("count", opts.Limit);
string path = GetRoute<ContactHubSpotModel>("lists", "recently_updated", "contacts", "recent");

path += $"?{QueryParams.COUNT}={opts.Limit}";

if (opts.PropertiesToInclude.Any())
path.SetQueryParam(QueryParams.PROPERTY, opts.PropertiesToInclude);
path += $"{QueryParams.PROPERTY}={opts.PropertiesToInclude}";

if (opts.Offset.HasValue)
path = path.SetQueryParam(QueryParams.VID_OFFSET, opts.Offset);
path += $"{QueryParams.VID_OFFSET}={opts.Offset}";

if (!string.IsNullOrEmpty(opts.TimeOffset))
path = path.SetQueryParam(QueryParams.TIME_OFFSET, opts.TimeOffset);
path += $"{QueryParams.TIME_OFFSET}={opts.TimeOffset}";

path = path.SetQueryParam(QueryParams.PROPERTY_MODE, opts.PropertyMode)
.SetQueryParam(QueryParams.FORM_SUBMISSION_MODE, opts.FormSubmissionMode)
.SetQueryParam(QueryParams.SHOW_LIST_MEMBERSHIPS, opts.ShowListMemberships);
path += $"{QueryParams.PROPERTY_MODE}={opts.PropertyMode}" +
$"&{QueryParams.FORM_SUBMISSION_MODE}={opts.FormSubmissionMode}" +
$"&{QueryParams.SHOW_LIST_MEMBERSHIPS}={opts.ShowListMemberships}";

return _client.Execute<ContactListHubSpotModel<ContactHubSpotModel>, ListRecentRequestOptions>(path, opts);
}
Expand All @@ -232,16 +233,16 @@ public ContactSearchHubSpotModel<ContactHubSpotModel> Search(ContactSearchReques
{
opts = opts ?? new ContactSearchRequestOptions();

Url path = GetRoute<ContactHubSpotModel>("search","query")
.SetQueryParam("q", opts.Query)
.SetQueryParam(QueryParams.COUNT, opts.Limit);
string path = GetRoute<ContactHubSpotModel>("search", "query");

path += $"q={opts.Query}&{QueryParams.COUNT}={opts.Limit}";

if (opts.PropertiesToInclude.Any())
path.SetQueryParam(QueryParams.PROPERTY, opts.PropertiesToInclude);
path += $"{QueryParams.PROPERTY}={opts.PropertiesToInclude}";


if (opts.Offset.HasValue)
path = path.SetQueryParam(QueryParams.OFFSET, opts.Offset);
path = path += $"{QueryParams.OFFSET}={opts.Offset}";

return _client.Execute<ContactSearchHubSpotModel<ContactHubSpotModel>, ContactSearchRequestOptions>(path, opts);
}
Expand All @@ -256,21 +257,22 @@ public ContactListHubSpotModel<ContactHubSpotModel> RecentlyCreated(ListRecentRe
{
opts = opts ?? new ListRecentRequestOptions();

Url path = GetRoute<ContactHubSpotModel>("lists","all","contacts","recent")
.SetQueryParam("count", opts.Limit);
string path = GetRoute<ContactHubSpotModel>("lists", "all", "contacts", "recent");

path += $"{QueryParams.COUNT}={opts.Limit}";

if (opts.PropertiesToInclude.Any())
path.SetQueryParam("property", opts.PropertiesToInclude);
path += $"{QueryParams.PROPERTY}={opts.PropertiesToInclude}";

if (opts.Offset.HasValue)
path = path.SetQueryParam("vidOffset", opts.Offset);
path = path += $"{QueryParams.VID_OFFSET}={opts.Offset}";

if (!string.IsNullOrEmpty(opts.TimeOffset))
path = path.SetQueryParam("timeOffset", opts.TimeOffset);
path = path += $"{QueryParams.TIME_OFFSET}={opts.TimeOffset}";

path = path.SetQueryParam("propertyMode", opts.PropertyMode)
.SetQueryParam("formSubmissionMode", opts.FormSubmissionMode)
.SetQueryParam("showListMemberships", opts.ShowListMemberships);
path += $"{QueryParams.PROPERTY_MODE}={opts.PropertyMode}"
+ $"{QueryParams.FORM_SUBMISSION_MODE}={opts.FormSubmissionMode}"
+ $"{QueryParams.SHOW_LIST_MEMBERSHIPS}={opts.ShowListMemberships}";

return _client.Execute<ContactListHubSpotModel<ContactHubSpotModel>, ListRecentRequestOptions>(path, opts);
}
Expand All @@ -289,17 +291,18 @@ public ContactListHubSpotModel<ContactHubSpotModel> GetList(long listId, ListReq
opts = new ListRequestOptions();
}

var path = GetRoute<ContactHubSpotModel>("lists", $"{listId}", "contacts", "all").SetQueryParam(QueryParams.COUNT, opts.Limit);
string path = GetRoute<ContactHubSpotModel>("lists", $"{listId}", "contacts", "all");
path += $"{QueryParams.COUNT}={opts.Limit}";


if (opts.PropertiesToInclude.Any())
{
path.SetQueryParam(QueryParams.PROPERTY, opts.PropertiesToInclude);
path += $"{QueryParams.PROPERTY}={opts.PropertiesToInclude}";
}

if (opts.Offset.HasValue)
{
path = path.SetQueryParam(QueryParams.VID_OFFSET, opts.Offset);
path = path += $"{QueryParams.VID_OFFSET}={opts.Offset}";
}

var data = _client.Execute<ContactListHubSpotModel<ContactHubSpotModel>>(path);
Expand Down
87 changes: 45 additions & 42 deletions HubSpot.NET/Api/Deal/HubSpotDealApi.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
namespace HubSpot.NET.Api.Deal
{
using System;
using System.Linq;
using System.Net;
using Flurl;
using HubSpot.NET.Api.Deal.Dto;
using HubSpot.NET.Api.Shared;
using HubSpot.NET.Core;
using HubSpot.NET.Core.Abstracts;
using HubSpot.NET.Core.Interfaces;
using RestSharp;
using System;
using System.Linq;
using System.Net;

public class HubSpotDealApi : ApiRoutable, IHubSpotDealApi
{
Expand All @@ -32,7 +31,7 @@ public DealHubSpotModel Create(DealHubSpotModel entity)
NameTransportModel<DealHubSpotModel> model = new NameTransportModel<DealHubSpotModel>();
model.ToPropertyTransportModel(entity);

return _client.Execute<DealHubSpotModel,NameTransportModel<DealHubSpotModel>>(GetRoute<DealHubSpotModel>(), model, Method.POST);
return _client.Execute<DealHubSpotModel, NameTransportModel<DealHubSpotModel>>(GetRoute<DealHubSpotModel>(), model, Method.POST);
}

/// <summary>
Expand Down Expand Up @@ -63,10 +62,10 @@ public DealHubSpotModel GetById(long dealId)
/// <returns>The updated deal entity</returns>
public DealHubSpotModel Update(DealHubSpotModel entity)
{
if (entity.Id < 1)
if (entity.Id < 1)
throw new ArgumentException("Deal entity must have an id set!");

return _client.Execute<DealHubSpotModel, DealHubSpotModel>(GetRoute<DealHubSpotModel>(entity.Id.ToString()), entity, method: Method.PUT);
return _client.Execute<DealHubSpotModel, DealHubSpotModel>(GetRoute<DealHubSpotModel>(entity.Id.ToString()), entity, method: Method.PUT);
}

/// <summary>
Expand All @@ -79,16 +78,18 @@ public DealListHubSpotModel<DealHubSpotModel> List(bool includeAssociations, Lis
{
opts = opts ?? new ListRequestOptions(250);

Url path = GetRoute<DealListHubSpotModel<DealHubSpotModel>>("deal", "paged").SetQueryParam("limit", opts.Limit);
string path = GetRoute<DealListHubSpotModel<DealHubSpotModel>>("deal", "paged");

if (opts.Offset.HasValue)
path = path.SetQueryParam(QueryParams.OFFSET, opts.Offset);
path += $"{QueryParams.LIMIT}={opts.Limit}";

if (includeAssociations)
path = path.SetQueryParam(QueryParams.INCLUDE_ASSOCIATIONS, "true");
if (opts.Offset.HasValue)
path += $"{QueryParams.OFFSET}={opts.Offset}";

if (opts.PropertiesToInclude.Any())
path = path.SetQueryParam(QueryParams.PROPERTIES, opts.PropertiesToInclude);
if (includeAssociations)
path += $"{QueryParams.INCLUDE_ASSOCIATIONS}=true";

if (opts.PropertiesToInclude.Any())
path += $"{QueryParams.PROPERTIES}={opts.PropertiesToInclude}";

return _client.Execute<DealListHubSpotModel<DealHubSpotModel>, ListRequestOptions>(path, opts);
}
Expand All @@ -104,19 +105,20 @@ public DealListHubSpotModel<DealHubSpotModel> List(bool includeAssociations, Lis
/// <returns>List of deals</returns>
public DealListHubSpotModel<DealHubSpotModel> ListAssociated(bool includeAssociations, long hubId, ListRequestOptions opts = null, string objectName = "contact")
{
opts = opts ?? new ListRequestOptions();
opts = opts ?? new ListRequestOptions();

string path = GetRoute<DealListHubSpotModel<DealHubSpotModel>>("deal", "associated", $"{objectName}", $"{hubId}", "paged");

Url path = GetRoute<DealListHubSpotModel<DealHubSpotModel>>("deal","associated",$"{objectName}",$"{hubId}","paged")
.SetQueryParam(QueryParams.LIMIT, opts.Limit);
path += $"{QueryParams.LIMIT}={opts.Limit}";

if (opts.Offset.HasValue)
path = path.SetQueryParam(QueryParams.OFFSET, opts.Offset);
if (opts.Offset.HasValue)
path += $"{QueryParams.OFFSET}={opts.Offset}";

if (includeAssociations)
path = path.SetQueryParam(QueryParams.INCLUDE_ASSOCIATIONS, "true");
if (includeAssociations)
path += $"{QueryParams.INCLUDE_ASSOCIATIONS}=true";

if (opts.PropertiesToInclude.Any())
path = path.SetQueryParam(QueryParams.PROPERTIES, opts.PropertiesToInclude);
if (opts.PropertiesToInclude.Any())
path += $"{QueryParams.PROPERTIES}={opts.PropertiesToInclude}";

return _client.Execute<DealListHubSpotModel<DealHubSpotModel>, ListRequestOptions>(path, opts);
}
Expand All @@ -125,7 +127,7 @@ public DealListHubSpotModel<DealHubSpotModel> ListAssociated(bool includeAssocia
/// Deletes a given deal (by ID)
/// </summary>
/// <param name="dealId">ID of the deal</param>
public void Delete(long dealId)
public void Delete(long dealId)
=> _client.ExecuteOnly(GetRoute<DealHubSpotModel>(dealId.ToString()), method: Method.DELETE);

/// <summary>
Expand All @@ -136,22 +138,23 @@ public void Delete(long dealId)
/// <returns>List of deals</returns>
public DealRecentListHubSpotModel<DealHubSpotModel> RecentlyCreated(DealRecentRequestOptions opts = null)
{
opts = opts ?? new DealRecentRequestOptions();
opts = opts ?? new DealRecentRequestOptions();

string path = $"{GetRoute<DealRecentListHubSpotModel<DealHubSpotModel>>()}/deal/recent/created";

Url path = $"{GetRoute<DealRecentListHubSpotModel<DealHubSpotModel>>()}/deal/recent/created"
.SetQueryParam(QueryParams.LIMIT, opts.Limit);
path += $"{QueryParams.LIMIT}={opts.Limit}";

if (opts.Offset.HasValue)
path = path.SetQueryParam(QueryParams.OFFSET, opts.Offset);
if (opts.Offset.HasValue)
path += $"{QueryParams.OFFSET}={opts.Offset}";

if (opts.IncludePropertyVersion)
path = path.SetQueryParam(QueryParams.INCLUDE_PROPERTY_VERSIONS, "true");
if (opts.IncludePropertyVersion)
path += $"{QueryParams.INCLUDE_PROPERTY_VERSIONS}=true";


if (!string.IsNullOrEmpty(opts.Since))
path = path.SetQueryParam(QueryParams.SINCE, opts.Since);
if (!string.IsNullOrEmpty(opts.Since))
path += $"{QueryParams.SINCE}={opts.Since}";

return _client.Execute<DealRecentListHubSpotModel<DealHubSpotModel>, DealRecentRequestOptions>(path, opts);
return _client.Execute<DealRecentListHubSpotModel<DealHubSpotModel>, DealRecentRequestOptions>(path, opts);
}

/// <summary>
Expand All @@ -162,19 +165,19 @@ public DealRecentListHubSpotModel<DealHubSpotModel> RecentlyCreated(DealRecentRe
/// <returns>List of deals</returns>
public DealRecentListHubSpotModel<DealHubSpotModel> RecentlyUpdated(DealRecentRequestOptions opts = null)
{
opts = opts ?? new DealRecentRequestOptions();
opts = opts ?? new DealRecentRequestOptions();

var path = GetRoute<DealRecentListHubSpotModel<DealHubSpotModel>>("deal","recent","modified").SetQueryParam(QueryParams.LIMIT, opts.Limit);
string path = GetRoute<DealRecentListHubSpotModel<DealHubSpotModel>>("deal", "recent", "modified");
path += $"{QueryParams.LIMIT}={opts.Limit}";

if (opts.Offset.HasValue)
path = path.SetQueryParam(QueryParams.OFFSET, opts.Offset);
if (opts.Offset.HasValue)
path += $"{QueryParams.OFFSET}={opts.Offset}";

if (opts.IncludePropertyVersion)
path = path.SetQueryParam(QueryParams.INCLUDE_PROPERTY_VERSIONS, "true");

if (!string.IsNullOrEmpty(opts.Since))
path = path.SetQueryParam(QueryParams.SINCE, opts.Since);
path += $"{QueryParams.INCLUDE_PROPERTY_VERSIONS}=true";

if (!string.IsNullOrEmpty(opts.Since))
path += $"{QueryParams.SINCE}={opts.Since}";

return _client.Execute<DealRecentListHubSpotModel<DealHubSpotModel>, DealRecentRequestOptions>(path, opts);
}
Expand Down
Loading

1 comment on commit 5a4f646

@radek-petrik-se
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest rollback for this commit. For removing the Flurl dependency just replace the SetQueryParam extension with own implementation of the same functionality. It will be easier to maintain and also fix errors like missing escaping, missing ampersands, etc. . I have marked just one example of missing ampersand, but there are many more.

Please sign in to comment.