Skip to content

Commit

Permalink
Internal change
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 296090610
  • Loading branch information
Brothman committed Feb 10, 2023
1 parent e9514ab commit 680a644
Show file tree
Hide file tree
Showing 8 changed files with 143 additions and 121 deletions.
14 changes: 8 additions & 6 deletions dotnet/source/AccountsSample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,10 @@ private AccountUser AddUser(ulong merchantId, ulong accountId, String emailAddre

// First, retrieve list of users.
Account account = service.Accounts.Get(merchantId, accountId).Execute();
AccountUser newAccountUser = new AccountUser();
newAccountUser.EmailAddress = emailAddress;
newAccountUser.Admin = false;
AccountUser newAccountUser = new AccountUser {
EmailAddress = emailAddress,
Admin = false
};

if (account.Users == null)
{
Expand Down Expand Up @@ -130,9 +131,10 @@ private AccountAdsLink LinkGoogleAdsAccount(ulong merchantId, ulong googleAdsAcc

// First, retrieve list of Google Ads accounts.
Account account = service.Accounts.Get(merchantId, merchantId).Execute();
var newAccountLink = new AccountAdsLink();
newAccountLink.AdsId = googleAdsAccountId;
newAccountLink.Status = "active";
var newAccountLink = new AccountAdsLink {
AdsId = googleAdsAccountId,
Status = "active"
};

if (account.AdsLinks == null)
{
Expand Down
17 changes: 9 additions & 8 deletions dotnet/source/AccounttaxSample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,16 @@ private void UpdateAccountTax(ulong merchantId, ulong accountId, AccountTax sett

private AccountTax SampleTaxSettings(ulong accountId)
{
AccountTaxTaxRule taxNY = new AccountTaxTaxRule();
taxNY.Country = "US";
taxNY.LocationId = 21167;
taxNY.UseGlobalRate = true;
AccountTaxTaxRule taxNY = new AccountTaxTaxRule {
Country = "US",
LocationId = 21167,
UseGlobalRate = true
};

AccountTax settings = new AccountTax();
settings.AccountId = accountId;
settings.Rules = new List<AccountTaxTaxRule>();
settings.Rules.Add(taxNY);
AccountTax settings = new AccountTax() {
AccountId = accountId,
Rules = new List<AccountTaxTaxRule> { taxNY }
};
return settings;
}

Expand Down
46 changes: 25 additions & 21 deletions dotnet/source/DatafeedsSample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,27 +149,31 @@ private void DeleteDatafeed(ulong merchantId, ulong datafeedId)
internal Datafeed GenerateDatafeed()
{
String name = String.Format("datafeed{0}", shoppingUtil.GetUniqueId());
Datafeed datafeed = new Datafeed();
datafeed.Name = name;
datafeed.ContentType = "products";
datafeed.AttributeLanguage = "en";
datafeed.FileName = name;
datafeed.FetchSchedule = new DatafeedFetchSchedule();
datafeed.FetchSchedule.Weekday = "monday";
datafeed.FetchSchedule.Hour = 6;
datafeed.FetchSchedule.TimeZone = "America/Los_Angeles";
datafeed.FetchSchedule.FetchUrl = $"http://feeds.my-shop.com/{name}";
datafeed.Format = new DatafeedFormat();
datafeed.Format.FileEncoding = "utf-8";
datafeed.Format.ColumnDelimiter = "tab";
datafeed.Format.QuotingMode = "value quoting";
datafeed.Targets = new List<DatafeedTarget>();
var target = new DatafeedTarget();
target.Country = "US";
target.Language = "EN";
target.IncludedDestinations = new List<String>();
target.IncludedDestinations.Add("Shopping");
datafeed.Targets.Add(target);
Datafeed datafeed = new Datafeed
{
Name = name,
ContentType = "products",
AttributeLanguage = "en",
FileName = name,
FetchSchedule = new DatafeedFetchSchedule {
Weekday = "monday",
Hour = 6,
TimeZone = "America/Los_Angeles",
FetchUrl = $"http://feeds.my-shop.com/{name}"
},
Format = new DatafeedFormat {
FileEncoding = "utf-8",
ColumnDelimiter = "tab",
QuotingMode = "value quoting"
},
Targets = new List<DatafeedTarget> {
new DatafeedTarget {
Country = "US",
Language = "EN",
IncludedDestinations = new List<String> { "Shopping" }
}
}
};

return datafeed;
}
Expand Down
5 changes: 3 additions & 2 deletions dotnet/source/MerchantConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ public static MerchantConfig Load(String configPath)
{
Console.WriteLine($"No configuration file at {contentFile}");
Console.WriteLine("Assuming default configuration for authenticated user.");
config = new MerchantConfig();
config.ConfigDir = contentPath;
config = new MerchantConfig {
ConfigDir = contentPath
};
return config;
}
using (StreamReader reader = File.OpenText(contentFile))
Expand Down
7 changes: 4 additions & 3 deletions dotnet/source/MultiClientAccountSample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,10 @@ private void DeleteAccount(ulong merchantId, ulong accountId)
internal Account GenerateAccount()
{
String name = String.Format("account{0}", shoppingUtil.GetUniqueId());
Account account = new Account();
account.Name = name;
account.WebsiteUrl = String.Format("https://{0}.example.com/", name);
Account account = new Account {
Name = name,
WebsiteUrl = String.Format("https://{0}.example.com/", name)
};
return account;
}
}
Expand Down
73 changes: 40 additions & 33 deletions dotnet/source/OrdersSample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ internal override void runCalls()

string orderId;
{
var req = new OrdersCreateTestOrderRequest();
req.TemplateName = "template1";
var req = new OrdersCreateTestOrderRequest() {
TemplateName = "template1"
};
var resp = sandboxService.Orders.Createtestorder(req, merchantId).Execute();
orderId = resp.OrderId;
}
Expand Down Expand Up @@ -80,12 +81,13 @@ internal override void runCalls()

// Oops, not enough stock for all the Chromecasts ordered, so we cancel one of them.
{
var req = new OrdersCancelLineItemRequest();
req.LineItemId = currentOrder.LineItems[0].Id;
req.Quantity = 1;
req.Reason = "noInventory";
req.ReasonText = "Ran out of inventory while fulfilling request.";
req.OperationId = NewOperationId();
var req = new OrdersCancelLineItemRequest() {
LineItemId = currentOrder.LineItems[0].Id,
Quantity = 1,
Reason = "noInventory",
ReasonText = "Ran out of inventory while fulfilling request.",
OperationId = NewOperationId()
};

CancelLineItem(merchantId, orderId, req);
}
Expand Down Expand Up @@ -243,8 +245,9 @@ private void Acknowledge(ulong merchantId, string orderId)
Console.WriteLine("Acknowledging Order {0}", orderId);
Console.WriteLine("=================================================================");

var req = new OrdersAcknowledgeRequest();
req.OperationId = NewOperationId();
var req = new OrdersAcknowledgeRequest() {
OperationId = NewOperationId()
};
var resp = sandboxService.Orders.Acknowledge(req, merchantId, orderId).Execute();

Console.WriteLine("Finished with status {0}.", resp.ExecutionStatus);
Expand All @@ -257,9 +260,10 @@ private void UpdateMerchantOrderId(ulong merchantId, string orderId, string merc
Console.WriteLine("Updating Merchant Order ID to {0}", merchantOrderId);
Console.WriteLine("=================================================================");

var req = new OrdersUpdateMerchantOrderIdRequest();
req.OperationId = NewOperationId();
req.MerchantOrderId = merchantOrderId;
var req = new OrdersUpdateMerchantOrderIdRequest() {
OperationId = NewOperationId(),
MerchantOrderId = merchantOrderId
};
var resp = sandboxService.Orders
.Updatemerchantorderid(req, merchantId, orderId)
.Execute();
Expand Down Expand Up @@ -288,20 +292,22 @@ private OrdersShipLineItemsRequest ShipAllLineItem(ulong merchantId, string orde
Console.WriteLine("Shipping {0} of item {1}", item.QuantityPending, item.Id);
Console.WriteLine("=================================================================");

var itemShip = new OrderShipmentLineItemShipment();
itemShip.LineItemId = item.Id;
itemShip.Quantity = item.QuantityPending;

var req = new OrdersShipLineItemsRequest();
var shipmentInfo = new OrdersCustomBatchRequestEntryShipLineItemsShipmentInfo();
shipmentInfo.Carrier = item.ShippingDetails.Method.Carrier;
shipmentInfo.ShipmentId = prng.Next().ToString();
shipmentInfo.TrackingId = prng.Next().ToString();
req.ShipmentInfos = new List<OrdersCustomBatchRequestEntryShipLineItemsShipmentInfo>();
req.ShipmentInfos.Add(shipmentInfo);
req.LineItems = new List<OrderShipmentLineItemShipment>();
req.LineItems.Add(itemShip);
req.OperationId = NewOperationId();
var itemShip = new OrderShipmentLineItemShipment() {
LineItemId = item.Id,
Quantity = item.QuantityPending
};

var shipmentInfo = new OrdersCustomBatchRequestEntryShipLineItemsShipmentInfo() {
Carrier = item.ShippingDetails.Method.Carrier,
ShipmentId = prng.Next().ToString(),
TrackingId = prng.Next().ToString(),
};

var req = new OrdersShipLineItemsRequest {
ShipmentInfos = new List<OrdersCustomBatchRequestEntryShipLineItemsShipmentInfo> { shipmentInfo },
LineItems = new List<OrderShipmentLineItemShipment> { itemShip },
OperationId = NewOperationId()
};

var resp = sandboxService.Orders.Shiplineitems(req, merchantId, orderId).Execute();

Expand All @@ -321,12 +327,13 @@ private void LineItemDelivered(ulong merchantId, string orderId,
ship.LineItems[0].LineItemId);
Console.WriteLine("=================================================================");

var req = new OrdersUpdateShipmentRequest();
req.Carrier = ship.ShipmentInfos[0].Carrier;
req.TrackingId = ship.ShipmentInfos[0].TrackingId;
req.ShipmentId = ship.ShipmentInfos[0].ShipmentId;
req.Status = "delivered";
req.OperationId = NewOperationId();
var req = new OrdersUpdateShipmentRequest() {
Carrier = ship.ShipmentInfos[0].Carrier,
TrackingId = ship.ShipmentInfos[0].TrackingId,
ShipmentId = ship.ShipmentInfos[0].ShipmentId,
Status = "delivered",
OperationId = NewOperationId()
};

var resp = sandboxService.Orders.Updateshipment(req, merchantId, orderId).Execute();

Expand Down
61 changes: 32 additions & 29 deletions dotnet/source/ProductsSample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -273,35 +273,38 @@ private void DeleteProductCustombatch(ulong merchantId, List<String> productList

internal Product GenerateProduct(string websiteUrl)
{
Product product = new Product();
product.OfferId = String.Format("product#{0}", shoppingUtil.GetUniqueId());
product.Title = "A Tale of Two Cities";
product.Description = "A classic novel about the French Revolution";
product.Link = $"{websiteUrl}/tale-of-two-cities.html";
product.ImageLink = $"{websiteUrl}/tale-of-two-cities.jpg";
product.ContentLanguage = "EN";
product.TargetCountry = "US";
product.Channel = "online";
product.Availability = "in stock";
product.Condition = "new";
product.GoogleProductCategory = "Media > Books";
product.Gtin = "9780007350896";
product.Price = new Price();
product.Price.Currency = "USD";
product.Price.Value = "2.50";

ProductShipping shipping = new ProductShipping();
shipping.Country = "US";
shipping.Service = "Standard shipping";
product.Shipping = new List<ProductShipping>();
shipping.Price = new Price();
shipping.Price.Currency = "USD";
shipping.Price.Value = "0.99";
product.Shipping.Add(shipping);

product.ShippingWeight = new ProductShippingWeight();
product.ShippingWeight.Unit = "grams";
product.ShippingWeight.Value = 200;
Product product = new Product() {
OfferId = String.Format("product#{0}", shoppingUtil.GetUniqueId()),
Title = "A Tale of Two Cities",
Description = "A classic novel about the French Revolution",
Link = $"{websiteUrl}/tale-of-two-cities.html",
ImageLink = $"{websiteUrl}/tale-of-two-cities.jpg",
ContentLanguage = "EN",
TargetCountry = "US",
Channel = "online",
Availability = "in stock",
Condition = "new",
GoogleProductCategory = "Media > Books",
Gtin = "9780007350896",
Price = new Price() {
Currency = "USD",
Value = "2.50"
},
Shipping = new List<ProductShipping> {
new ProductShipping() {
Country = "US",
Service = "Standard shipping",
Price = new Price() {
Currency = "USD",
Value = "0.99"
}
}
},
ShippingWeight = new ProductShippingWeight() {
Unit = "grams",
Value = 200
}
};

return product;
}
Expand Down
41 changes: 22 additions & 19 deletions dotnet/source/ShippingsettingsSample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ private ShippingSettings GetShippingSettings(ulong merchantId, ulong accountId)
PrintShippingSettings(settings);
Console.WriteLine();

return settings;
return settings;
}

private void UpdateShippingSettings(ulong merchantId, ulong accountId, ShippingSettings settings)
Expand All @@ -71,26 +71,29 @@ private ShippingSettings SampleShippingSettings()
{
RateGroup rateUSPS = new RateGroup();
rateUSPS.ApplicableShippingLabels = new List<string>();
rateUSPS.SingleValue = new Value();
rateUSPS.SingleValue.FlatRate = new Price();
rateUSPS.SingleValue.FlatRate.Value = "5.00";
rateUSPS.SingleValue.FlatRate.Currency = "USD";
rateUSPS.SingleValue = new Value() {
FlatRate = new Price() {
Value = "5.00",
Currency = "USD"
}
};

Service serviceUSPS = new Service();
serviceUSPS.Name = "USPS";
serviceUSPS.Currency = "USD";
serviceUSPS.DeliveryCountry = "US";
serviceUSPS.DeliveryTime = new DeliveryTime();
serviceUSPS.DeliveryTime.MinTransitTimeInDays = 3;
serviceUSPS.DeliveryTime.MaxTransitTimeInDays = 7;
serviceUSPS.RateGroups = new List<RateGroup>();
serviceUSPS.RateGroups.Add(rateUSPS);
serviceUSPS.Active = true;
Service serviceUSPS = new Service() {
Name = "USPS",
Currency = "USD",
DeliveryCountry = "US",
DeliveryTime = new DeliveryTime() {
MinTransitTimeInDays = 3,
MaxTransitTimeInDays = 7,
},
RateGroups = new List<RateGroup> { rateUSPS },
Active = true
};

ShippingSettings settings = new ShippingSettings();
settings.PostalCodeGroups = new List<PostalCodeGroup>();
settings.Services = new List<Service>();
settings.Services.Add(serviceUSPS);
ShippingSettings settings = new ShippingSettings() {
PostalCodeGroups = new List<PostalCodeGroup>(),
Services = new List<Service> { serviceUSPS }
};
return settings;
}

Expand Down

0 comments on commit 680a644

Please sign in to comment.