Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
fudiwei committed Aug 8, 2024
1 parent 7de3ee5 commit dff6b67
Show file tree
Hide file tree
Showing 56 changed files with 502 additions and 1,071 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,19 +61,11 @@ public static class WechatAdsClientExecuteAdCreativesExtensions

IFlurlRequest flurlReq = client
.CreateFlurlRequest(request, HttpMethod.Get, "adcreatives", "get")
.SetQueryParam("access_token", request.AccessToken);

if (request.AdCreativeId is not null)
flurlReq.SetQueryParam("adcreative_id", request.AdCreativeId.Value);

if (request.Filters is not null)
flurlReq.SetQueryParam("filtering", client.JsonSerializer.Serialize(request.Filters));

if (request.PageSize is not null)
flurlReq.SetQueryParam("page_size", request.PageSize.Value);

if (request.Page is not null)
flurlReq.SetQueryParam("page", request.Page.Value);
.SetQueryParam("access_token", request.AccessToken)
.SetQueryParam("adcreative_id", request.AdCreativeId)
.SetQueryParam("filtering", request.Filters is null ? null : client.JsonSerializer.Serialize(request.Filters))
.SetQueryParam("page_size", request.PageSize)
.SetQueryParam("page", request.Page);

return await client.SendFlurlRequestAsJsonAsync<Models.AdCreativesGetResponse>(flurlReq, data: request, cancellationToken: cancellationToken).ConfigureAwait(false);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
Expand Down Expand Up @@ -61,19 +61,11 @@ public static class WechatAdsClientExecuteAdGroupsExtensions

IFlurlRequest flurlReq = client
.CreateFlurlRequest(request, HttpMethod.Get, "adgroups", "get")
.SetQueryParam("access_token", request.AccessToken);

if (request.AdGroupId is not null)
flurlReq.SetQueryParam("adgroup_id", request.AdGroupId.Value);

if (request.Filters is not null)
flurlReq.SetQueryParam("filtering", client.JsonSerializer.Serialize(request.Filters));

if (request.PageSize is not null)
flurlReq.SetQueryParam("page_size", request.PageSize.Value);

if (request.Page is not null)
flurlReq.SetQueryParam("page", request.Page.Value);
.SetQueryParam("access_token", request.AccessToken)
.SetQueryParam("adgroup_id", request.AdGroupId)
.SetQueryParam("filtering", request.Filters is null ? null : client.JsonSerializer.Serialize(request.Filters))
.SetQueryParam("page_size", request.PageSize)
.SetQueryParam("page", request.Page);

return await client.SendFlurlRequestAsJsonAsync<Models.AdGroupsGetResponse>(flurlReq, data: request, cancellationToken: cancellationToken).ConfigureAwait(false);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
Expand Down Expand Up @@ -61,19 +61,11 @@ public static class WechatAdsClientExecuteAdsExtensions

IFlurlRequest flurlReq = client
.CreateFlurlRequest(request, HttpMethod.Get, "ads", "get")
.SetQueryParam("access_token", request.AccessToken);

if (request.AdId is not null)
flurlReq.SetQueryParam("ad_id", request.AdId.Value);

if (request.Filters is not null)
flurlReq.SetQueryParam("filtering", client.JsonSerializer.Serialize(request.Filters));

if (request.PageSize is not null)
flurlReq.SetQueryParam("page_size", request.PageSize.Value);

if (request.Page is not null)
flurlReq.SetQueryParam("page", request.Page.Value);
.SetQueryParam("access_token", request.AccessToken)
.SetQueryParam("ad_id", request.AdId)
.SetQueryParam("filtering", request.Filters is null ? null : client.JsonSerializer.Serialize(request.Filters))
.SetQueryParam("page_size", request.PageSize)
.SetQueryParam("page", request.Page);

return await client.SendFlurlRequestAsJsonAsync<Models.AdsGetResponse>(flurlReq, data: request, cancellationToken: cancellationToken).ConfigureAwait(false);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Linq;
using System.Net.Http;
using System.Threading;
Expand Down Expand Up @@ -43,16 +43,10 @@ public static class WechatAdsClientExecuteAsyncTasksExtensions

IFlurlRequest flurlReq = client
.CreateFlurlRequest(request, HttpMethod.Get, "async_tasks", "get")
.SetQueryParam("access_token", request.AccessToken);

if (request.Filters is not null && request.Filters.Any())
flurlReq.SetQueryParam("filtering", client.JsonSerializer.Serialize(request.Filters));

if (request.PageSize is not null)
flurlReq.SetQueryParam("page_size", request.PageSize.Value);

if (request.Page is not null)
flurlReq.SetQueryParam("page", request.Page.Value);
.SetQueryParam("access_token", request.AccessToken)
.SetQueryParam("filtering", request.Filters is null ? null : client.JsonSerializer.Serialize(request.Filters))
.SetQueryParam("page_size", request.PageSize)
.SetQueryParam("page", request.Page);

return await client.SendFlurlRequestAsJsonAsync<Models.AsyncTasksGetResponse>(flurlReq, data: request, cancellationToken: cancellationToken).ConfigureAwait(false);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
Expand Down Expand Up @@ -61,19 +61,11 @@ public static class WechatAdsClientExecuteCampaignsExtensions

IFlurlRequest flurlReq = client
.CreateFlurlRequest(request, HttpMethod.Get, "campaigns", "get")
.SetQueryParam("access_token", request.AccessToken);

if (request.CampaignId is not null)
flurlReq.SetQueryParam("campaign_id", request.CampaignId.Value);

if (request.Filters is not null)
flurlReq.SetQueryParam("filtering", client.JsonSerializer.Serialize(request.Filters));

if (request.PageSize is not null)
flurlReq.SetQueryParam("page_size", request.PageSize.Value);

if (request.Page is not null)
flurlReq.SetQueryParam("page", request.Page.Value);
.SetQueryParam("access_token", request.AccessToken)
.SetQueryParam("campaign_id", request.CampaignId)
.SetQueryParam("filtering", request.Filters is null ? null : client.JsonSerializer.Serialize(request.Filters))
.SetQueryParam("page_size", request.PageSize)
.SetQueryParam("page", request.Page);

return await client.SendFlurlRequestAsJsonAsync<Models.CampaignsGetResponse>(flurlReq, data: request, cancellationToken: cancellationToken).ConfigureAwait(false);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
Expand All @@ -25,13 +25,9 @@ public static class WechatAdsClientExecuteCreditBillsExtensions
.CreateFlurlRequest(request, HttpMethod.Get, "credit_bills", "get")
.SetQueryParam("access_token", request.AccessToken)
.SetQueryParam("bill_year", request.BillYear)
.SetQueryParam("bill_month", request.BillMonth);

if (request.PageSize is not null)
flurlReq.SetQueryParam("page_size", request.PageSize.Value);

if (request.Page is not null)
flurlReq.SetQueryParam("page", request.Page.Value);
.SetQueryParam("bill_month", request.BillMonth)
.SetQueryParam("page_size", request.PageSize)
.SetQueryParam("page", request.Page);

return await client.SendFlurlRequestAsJsonAsync<Models.CreditBillsGetResponse>(flurlReq, data: request, cancellationToken: cancellationToken).ConfigureAwait(false);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading;
Expand Down Expand Up @@ -62,16 +62,10 @@ public static class WechatAdsClientExecuteCustomAudiencesExtensions

IFlurlRequest flurlReq = client
.CreateFlurlRequest(request, HttpMethod.Get, "custom_audiences", "get")
.SetQueryParam("access_token", request.AccessToken);

if (request.CustomAudienceId is not null)
flurlReq.SetQueryParam("audience_id", request.CustomAudienceId.Value);

if (request.PageSize is not null)
flurlReq.SetQueryParam("page_size", request.PageSize.Value);

if (request.Page is not null)
flurlReq.SetQueryParam("page", request.Page.Value);
.SetQueryParam("access_token", request.AccessToken)
.SetQueryParam("audience_id", request.CustomAudienceId)
.SetQueryParam("page_size", request.PageSize)
.SetQueryParam("page", request.Page);

return await client.SendFlurlRequestAsJsonAsync<Models.CustomAudiencesGetResponse>(flurlReq, data: request, cancellationToken: cancellationToken).ConfigureAwait(false);
}
Expand Down Expand Up @@ -121,19 +115,11 @@ public static class WechatAdsClientExecuteCustomAudiencesExtensions

IFlurlRequest flurlReq = client
.CreateFlurlRequest(request, HttpMethod.Get, "custom_audience_files", "get")
.SetQueryParam("access_token", request.AccessToken);

if (request.CustomAudienceId is not null)
flurlReq.SetQueryParam("audience_id", request.CustomAudienceId.Value);

if (request.CustomAudienceFileId is not null)
flurlReq.SetQueryParam("custom_audience_file_id", request.CustomAudienceFileId.Value);

if (request.PageSize is not null)
flurlReq.SetQueryParam("page_size", request.PageSize.Value);

if (request.Page is not null)
flurlReq.SetQueryParam("page", request.Page.Value);
.SetQueryParam("access_token", request.AccessToken)
.SetQueryParam("audience_id", request.CustomAudienceId)
.SetQueryParam("custom_audience_file_id", request.CustomAudienceFileId)
.SetQueryParam("page_size", request.PageSize)
.SetQueryParam("page", request.Page);

return await client.SendFlurlRequestAsJsonAsync<Models.CustomAudienceFilesGetResponse>(flurlReq, data: request, cancellationToken: cancellationToken).ConfigureAwait(false);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
Expand Down Expand Up @@ -61,19 +61,11 @@ public static class WechatAdsClientExecuteFundsExtensions

IFlurlRequest flurlReq = client
.CreateFlurlRequest(request, HttpMethod.Get, "fund_statements_detailed", "get")
.SetQueryParam("access_token", request.AccessToken);

if (request.DateRange is not null)
flurlReq.SetQueryParam("date_range", client.JsonSerializer.Serialize(request.DateRange));

if (request.TradeType is not null)
flurlReq.SetQueryParam("trade_type", request.TradeType);

if (request.PageSize is not null)
flurlReq.SetQueryParam("page_size", request.PageSize.Value);

if (request.Page is not null)
flurlReq.SetQueryParam("page", request.Page.Value);
.SetQueryParam("access_token", request.AccessToken)
.SetQueryParam("date_range", request.DateRange is null ? null : client.JsonSerializer.Serialize(request.DateRange))
.SetQueryParam("trade_type", request.TradeType)
.SetQueryParam("page_size", request.PageSize)
.SetQueryParam("page", request.Page);

return await client.SendFlurlRequestAsJsonAsync<Models.FundStatementsDetailedGetResponse>(flurlReq, data: request, cancellationToken: cancellationToken).ConfigureAwait(false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,11 @@ public static class WechatAdsClientExecuteImagesExtensions

IFlurlRequest flurlReq = client
.CreateFlurlRequest(request, HttpMethod.Get, "images", "get")
.SetQueryParam("access_token", request.AccessToken);

if (request.ImageId is not null)
flurlReq.SetQueryParam("image_id", request.ImageId);

if (request.Filters is not null)
flurlReq.SetQueryParam("filtering", client.JsonSerializer.Serialize(request.Filters));

if (request.PageSize is not null)
flurlReq.SetQueryParam("page_size", request.PageSize.Value);

if (request.Page is not null)
flurlReq.SetQueryParam("page", request.Page.Value);
.SetQueryParam("access_token", request.AccessToken)
.SetQueryParam("image_id", request.ImageId)
.SetQueryParam("filtering", request.Filters is null ? null : client.JsonSerializer.Serialize(request.Filters))
.SetQueryParam("page_size", request.PageSize)
.SetQueryParam("page", request.Page);

return await client.SendFlurlRequestAsJsonAsync<Models.ImagesGetResponse>(flurlReq, data: request, cancellationToken: cancellationToken).ConfigureAwait(false);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Linq;
using System.Net.Http;
using System.Threading;
Expand All @@ -24,22 +24,12 @@ public static class WechatAdsClientExecuteReportsExtensions

IFlurlRequest flurlReq = client
.CreateFlurlRequest(request, HttpMethod.Get, "daily_reports", "get")
.SetQueryParam("access_token", request.AccessToken);

if (request.DateRange is not null)
flurlReq.SetQueryParam("date_range", client.JsonSerializer.Serialize(request.DateRange));

if (request.ReportType is not null)
flurlReq.SetQueryParam("report_type", request.ReportType);

if (request.ReportLevel is not null)
flurlReq.SetQueryParam("level", request.ReportLevel);

if (request.PageSize is not null)
flurlReq.SetQueryParam("page_size", request.PageSize.Value);

if (request.Page is not null)
flurlReq.SetQueryParam("page", request.Page.Value);
.SetQueryParam("access_token", request.AccessToken)
.SetQueryParam("date_range", request.DateRange is null ? null : client.JsonSerializer.Serialize(request.DateRange))
.SetQueryParam("report_type", request.ReportType)
.SetQueryParam("level", request.ReportLevel)
.SetQueryParam("page_size", request.PageSize)
.SetQueryParam("page", request.Page);

return await client.SendFlurlRequestAsJsonAsync<Models.DailyReportsGetResponse>(flurlReq, data: request, cancellationToken: cancellationToken).ConfigureAwait(false);
}
Expand All @@ -60,10 +50,8 @@ public static class WechatAdsClientExecuteReportsExtensions
.CreateFlurlRequest(request, HttpMethod.Get, "realtime_cost", "get")
.SetQueryParam("access_token", request.AccessToken)
.SetQueryParam("date", request.DateString)
.SetQueryParam("level", request.Level);

if (request.Filters is not null && request.Filters.Any())
flurlReq.SetQueryParam("filtering", client.JsonSerializer.Serialize(request.Filters));
.SetQueryParam("level", request.Level)
.SetQueryParam("filtering", request.Filters is null ? null : client.JsonSerializer.Serialize(request.Filters));

return await client.SendFlurlRequestAsJsonAsync<Models.RealtimeCostGetResponse>(flurlReq, data: request, cancellationToken: cancellationToken).ConfigureAwait(false);
}
Expand Down
Loading

0 comments on commit dff6b67

Please sign in to comment.