Skip to content
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
76 changes: 76 additions & 0 deletions SquareSpaceSharp/Entities/Profile.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
using System;
using System.Collections.Generic;
using Newtonsoft.Json;

namespace SquareSpaceSharp.Entities
{
public class Profile
{
/// <summary>
/// The profile's system identifier
/// </summary>
[JsonProperty("id")]
public string Id { get; set; }

/// <summary>
/// Profile first name.
/// </summary>
[JsonProperty("firstName")]
public string FirstName { get; set; }

/// <summary>
/// Profile last name.
/// </summary>
[JsonProperty("lastName")]
public string LastName { get; set; }

/// <summary>
/// Profile email address.
/// </summary>
[JsonProperty("email")]
public string Email { get; set; }

/// <summary>
/// Indicates whether the profile has an account with the website.
/// </summary>
[JsonProperty("hasAccount")]
public bool HasAccount { get; set; }

/// <summary>
/// Indicates whether the profile has any commerce orders or donations with the website.
/// </summary>
[JsonProperty("isCustomer")]
public bool CustomerEmail { get; set; }

/// <summary>
/// ISO 8601 UTC date and time string; represents when the profile was created.
/// </summary>
[JsonProperty("createdOn")]
public string CreatedOn { get; set; }

/// <summary>
/// Profile’s address.
/// An approximate address for the user based on existing data;
/// it should not be used for shipping or billing purposes.
/// Field is `null` if an approximate address can't be determined.
/// </summary>
[JsonProperty("address")]
public Address Address { get; set; }

/// <summary>
/// Indicates whether the profile opted to receive marketing.
/// </summary>
[JsonProperty("acceptsMarketing")]
public bool AcceptsMarketing { get; set; }

/// <summary>
/// Summary of profile’s commerce transactions.
/// If a profile has no commerce transactions, the object is still returned with `null` or `0` values.
/// This information is calculated asynchronously; there may be a slight delay between
/// when an order is created, and when it's reflected in the object.
/// </summary>
[JsonProperty("transactionsSummary")]
public TransactionsSummary TransactionSummary { get; set; }

}
}
20 changes: 20 additions & 0 deletions SquareSpaceSharp/Entities/ProfileCollection.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System.Collections.Generic;
using Newtonsoft.Json;

namespace SquareSpaceSharp.Entities
{
public class ProfileCollection
{
/// <summary>
/// An array of order resource objects, which will be empty if the store doesn't have any orders yet.
/// </summary>
[JsonProperty("Profiles")]
public IEnumerable<Profile> Profiles { get; set; }

/// <summary>
/// An object containing the following fields:
/// </summary>
[JsonProperty("pagination")]
public Pagination Pagination { get; set; }
}
}
49 changes: 49 additions & 0 deletions SquareSpaceSharp/Entities/ProfileQueryParameters.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using SquareSpaceSharp.Infrastructure;
using System.Net;
using System.Text;
using static System.Runtime.InteropServices.JavaScript.JSType;

namespace SquareSpaceSharp.Entities
{
public class ProfileQueryParameters : Parameterizable
{
/// <summary>
/// Type: A string token, returned from the pagination.nextPageCursor of a previous response.Identifies where the next page of results should begin.If this parameter is not present or empty, the first page of order data will be returned.
/// </summary>
[JsonProperty("cursor")]
public string Cursor { get; set; }

/// <summary>
/// optional, values include "isCustomer" and/or "hasAccount", or "Email".
/// The "email" filter cannot be used with "isCUstomer" or "hasAccount"
/// Semicolon separated list used to filter profile results:
/// isCustomer: Value must be true; false currently not supported
/// hasAccount: Value must be true; false currently not supported
/// email: Valid email address with URL-encoded characters; case insensitive
/// filter=isCustomer,true;hasAccount,true
/// </summary>
[JsonProperty("filter")]
public string Filter { get; set; }

/// <summary>
/// optional, values include: asc or dsc
/// Identifies the sort direction of the result list; asc for ascending or dsc for descending.
/// If parameter is not specified, the returned list is in descending order by sortField or by profile id if sortField is not specified.
/// </summary>
[JsonProperty("sortDirection")]
public string SortDirection { get; set; }

/// <summary>
/// optional; values include: createdOn, id, email, or lastName
/// Identifies the sort field of the result list:
/// id: Unique id of a Profile
/// lastName: Last name of a profile
/// createdOn: ISO 8601 UTC date and time when a profile was created
/// email: Email address of a profile
/// </summary>
[JsonProperty("sortField")]
public string FulfillmentStatus { get; set; }
}
}
66 changes: 66 additions & 0 deletions SquareSpaceSharp/Entities/TransactionsSummary.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
using Newtonsoft.Json;

namespace SquareSpaceSharp.Entities
{
public class TransactionsSummary
{
/// <summary>
/// ISO 8601 UTC date and time string; represents when the profile’s first order was submitted.
/// </summary>
[JsonProperty("firstOrderSubmittedOn")]
public string FirstOrderSubmittedOn { get; set; }

/// <summary>
/// ISO 8601 UTC date and time string; represents when the profile’s last order was submitted.
/// </summary>
[JsonProperty("lastOrderSubmittedOn")]
public string LastOrderSubmittedOn { get; set; }


/// <summary>
/// Count of orders submitted.
/// </summary>
[JsonProperty("orderCount")]
public int OrderCount { get; set; }

/// <summary>
/// Monetary amount with 1,000,000 limit and no markers for the dollar amount.
// Conforms to the selected ISO currency's precision.
// (E.g., JPY uses 123, but USD uses 123.00 or 123.)
/// </summary>
[JsonProperty("totalOrderAmount")]
public CurrencyValue TotalOrderAmount { get; set; }

/// <summary>
/// Total of all order refunds.
/// </summary>
[JsonProperty("totalRefundAmount")]
public CurrencyValue TotalRefundAmount { get; set; }


/// <summary>
/// ISO 8601 UTC date and time string; represents when the profile’s first donation was submitted.
/// </summary>
[JsonProperty("firstDonationSubmittedOn")]
public string FirstDonationSubmittedOn { get; set; }

/// <summary>
/// ISO 8601 UTC date and time string; represents when the profile’s latest donation was submitted.
/// </summary>
[JsonProperty("lastDonationSubmittedOn")]
public string LastDonationSubmittedOn { get; set; }


/// <summary>
/// Count of donations submitted.
/// </summary>
[JsonProperty("donationCount")]
public int DonationCount { get; set; }

/// <summary>
/// Total of all order refunds.
/// </summary>
[JsonProperty("totalDonationAmount")]
public CurrencyValue TotalDonationAmount { get; set; }
}
}
47 changes: 47 additions & 0 deletions SquareSpaceSharp/Services/Profile/ProfileService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System.Net.Http;
using System.Threading.Tasks;
using SquareSpaceSharp.Entities;
using SquareSpaceSharp.Extensions;
using SquareSpaceSharp.Infrastructure;

namespace SquareSpaceSharp.Services.Profile
{
public class ProfileService : SquareSpaceService
{
/// <summary>
/// Creates a new instance of <see cref="ProfileService" />.
/// </summary>
/// <param name="secretApiKey">App Secret Api Key</param>
public ProfileService(string secretApiKey) : base(secretApiKey)
{
}

/// <summary>
/// Returns collection of profiles
/// </summary>
/// <param name="queryParameters">Order query parameters</param>
public virtual async Task<ProfileCollection> GetProfilesAsync(OrderQueryParameters queryParameters = null)
{
var req = PrepareRequest("profiles",isCommerce:false);

if (queryParameters != null)
{
req.QueryParams.AddRange(queryParameters.ToParameters());
}

return await ExecuteRequestAsync<ProfileCollection>(req, HttpMethod.Get);
}

/// <summary>
/// Returns a profiles that match ID.
/// </summary>
/// <param name="profileId">Requested profile ID</param>
/// <returns>The <see cref="Profile"/>.</returns>
public virtual async Task<ProfileCollection> GetProfilesByIdAsync(string profileId)
{
var req = PrepareRequest($"profiles/{profileId}",isCommerce:false);

return await ExecuteRequestAsync<ProfileCollection>(req, HttpMethod.Get);
}
}
}
13 changes: 13 additions & 0 deletions SquareSpaceSharp/Services/SquareSpaceService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,19 @@ protected RequestUri PrepareRequest(string apiVersion, string path)
return new RequestUri(new Uri($"https://api.squarespace.com/{apiVersion}/commerce/{path}"));
}

protected RequestUri PrepareRequest(string path,bool isCommerce)
{
if (isCommerce) {
return new RequestUri(new Uri($"https://api.squarespace.com/1.0/commerce/{path}"));

}
else
{
return new RequestUri(new Uri($"https://api.squarespace.com/1.0/{path}"));

}
}

/// <summary>
/// Prepares a request to the path and appends the shop's access token header if applicable.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion SquareSpaceSharp/SquareSpaceSharp.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netcoreapp2.1;</TargetFrameworks>
<TargetFrameworks>net7.0</TargetFrameworks>
<AssemblyName>SquareSpaceSharp</AssemblyName>
<RootNamespace>SquareSpaceSharp</RootNamespace>
<Version>1.0.1</Version>
Expand Down