Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Removes Flurl dependency" #97

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions HubSpot.NET/Api/Company/HubSpotCompanyApi.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
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 @@ -78,15 +79,13 @@ public CompanyListHubSpotModel<CompanyHubSpotModel> List(ListRequestOptions opts
{
opts = opts ?? new ListRequestOptions();

string path = GetRoute<CompanyHubSpotModel>("companies", "paged");

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

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

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

return _client.Execute<CompanyListHubSpotModel<CompanyHubSpotModel>, ListRequestOptions>(path, opts);
}
Expand Down
65 changes: 31 additions & 34 deletions HubSpot.NET/Api/Contact/HubSpotContactApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net;
using Flurl;
using HubSpot.NET.Api.Contact.Dto;
using HubSpot.NET.Core;
using HubSpot.NET.Core.Abstracts;
Expand Down Expand Up @@ -155,17 +156,16 @@ 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();

string path = GetRoute<ContactHubSpotModel>("lists", "all", "contacts", "all");

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

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

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

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

string path = GetRoute<ContactHubSpotModel>("lists", "recently_updated", "contacts", "recent");

path += $"?{QueryParams.COUNT}={opts.Limit}";
Url path = GetRoute<ContactHubSpotModel>("lists", "recently_updated","contacts","recent")
.SetQueryParam("count", opts.Limit);

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

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

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

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

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

string path = GetRoute<ContactHubSpotModel>("search", "query");

path += $"q={opts.Query}&{QueryParams.COUNT}={opts.Limit}";
Url path = GetRoute<ContactHubSpotModel>("search","query")
.SetQueryParam("q", opts.Query)
.SetQueryParam(QueryParams.COUNT, opts.Limit);

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


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

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

string path = GetRoute<ContactHubSpotModel>("lists", "all", "contacts", "recent");

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

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

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

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

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

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

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


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

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

var data = _client.Execute<ContactListHubSpotModel<ContactHubSpotModel>>(path);
Expand Down
87 changes: 42 additions & 45 deletions HubSpot.NET/Api/Deal/HubSpotDealApi.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
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 @@ -31,7 +32,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 @@ -62,10 +63,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 @@ -78,18 +79,16 @@ public DealListHubSpotModel<DealHubSpotModel> List(bool includeAssociations, Lis
{
opts = opts ?? new ListRequestOptions(250);

string path = GetRoute<DealListHubSpotModel<DealHubSpotModel>>("deal", "paged");
Url path = GetRoute<DealListHubSpotModel<DealHubSpotModel>>("deal", "paged").SetQueryParam("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 += $"{QueryParams.PROPERTIES}={opts.PropertiesToInclude}";
if (opts.PropertiesToInclude.Any())
path = path.SetQueryParam(QueryParams.PROPERTIES, opts.PropertiesToInclude);

return _client.Execute<DealListHubSpotModel<DealHubSpotModel>, ListRequestOptions>(path, opts);
}
Expand All @@ -105,20 +104,19 @@ 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();

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

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

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

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

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

return _client.Execute<DealListHubSpotModel<DealHubSpotModel>, ListRequestOptions>(path, opts);
}
Expand All @@ -127,7 +125,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 @@ -138,23 +136,22 @@ public void Delete(long dealId)
/// <returns>List of deals</returns>
public DealRecentListHubSpotModel<DealHubSpotModel> RecentlyCreated(DealRecentRequestOptions opts = null)
{
opts = opts ?? new DealRecentRequestOptions();

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

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

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

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


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

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

/// <summary>
Expand All @@ -165,19 +162,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();

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

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

if (opts.IncludePropertyVersion)
path += $"{QueryParams.INCLUDE_PROPERTY_VERSIONS}=true";
path = path.SetQueryParam(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);
}
Expand Down
Loading