Skip to content

Commit

Permalink
Merge pull request #891 from nozzlegear/service-interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
nozzlegear committed Jun 27, 2023
2 parents 2eebbc7 + 825e4c9 commit 940350e
Show file tree
Hide file tree
Showing 125 changed files with 3,997 additions and 2,933 deletions.
4 changes: 1 addition & 3 deletions ShopifySharp.sln
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
ProjectSection(SolutionItems) = preProject
LICENSE = LICENSE
readme.md = readme.md
scripts\build.ps1 = scripts\build.ps1
scripts\test.ps1 = scripts\test.ps1
scripts\deploy.ps1 = scripts\deploy.ps1
docs\contribution-guide.md = docs\contribution-guide.md
EndProjectSection
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "ShopifySharp.Experimental", "ShopifySharp.Experimental\ShopifySharp.Experimental.fsproj", "{DE7BB881-2191-489D-B9AA-F5F910EF55D8}"
Expand Down
5 changes: 5 additions & 0 deletions ShopifySharp.sln.DotSettings
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/CodeEditing/SuppressUninitializedWarningFix/Enabled/@EntryValue">False</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=fulfillments/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=metafield/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=myshopify/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
23 changes: 9 additions & 14 deletions ShopifySharp/Services/AccessScope/AccessScopeService.cs
Original file line number Diff line number Diff line change
@@ -1,31 +1,26 @@
using System.Collections.Generic;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using System.Threading;

namespace ShopifySharp
{
/// <summary>
/// A service for getting the access scopes associated with the access token
/// </summary>
public class AccessScopeService : ShopifyService
public class AccessScopeService : ShopifyService, IAccessScopeService
{
//oauth endpoints don't support versioning
protected override bool SupportsAPIVersioning => false;

/// <summary>
/// Creates a new instance of the service.
/// </summary>
/// <param name="myShopifyUrl">The shop's *.myshopify.com URL.</param>
/// <param name="shopAccessToken">An API access token for the shop.</param>
public AccessScopeService(string myShopifyUrl, string shopAccessToken) : base(myShopifyUrl, shopAccessToken) { }

//oauth endpoints don't support versioning
protected override bool SupportsAPIVersioning => false;

/// <summary>
/// Retrieves a list of access scopes associated to the access token.
/// </summary>
public virtual async Task<IEnumerable<AccessScope>> ListAsync(CancellationToken cancellationToken = default)
{
return await ExecuteGetAsync<IEnumerable<AccessScope>>("oauth/access_scopes.json", "access_scopes", cancellationToken: cancellationToken);
}
/// <inheritdoc />
public virtual async Task<IEnumerable<AccessScope>> ListAsync(CancellationToken cancellationToken = default) =>
await ExecuteGetAsync<IEnumerable<AccessScope>>("oauth/access_scopes.json", "access_scopes", cancellationToken: cancellationToken);
}
}
}
14 changes: 14 additions & 0 deletions ShopifySharp/Services/AccessScope/IAccessScopeService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;

namespace ShopifySharp
{
public interface IAccessScopeService : IShopifyService
{
/// <summary>
/// Retrieves a list of access scopes associated to the access token.
/// </summary>
Task<IEnumerable<AccessScope>> ListAsync(CancellationToken cancellationToken = default);
}
}
50 changes: 15 additions & 35 deletions ShopifySharp/Services/ApplicationCredit/ApplicationCreditService.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
using ShopifySharp.Infrastructure;
using System.Collections.Generic;
using ShopifySharp.Filters;
using ShopifySharp.Infrastructure;
using ShopifySharp.Lists;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using ShopifySharp.Filters;
using ShopifySharp.Lists;
using System.Threading;

namespace ShopifySharp
{
/// <summary>
/// A service for offering credits for payments made via the Application Charge, Recurring Application Charge, and Usage Charge APIs.
/// </summary>
public class ApplicationCreditService : ShopifyService
public class ApplicationCreditService : ShopifyService, IApplicationCreditService
{
/// <summary>
/// Creates a new instance of <see cref="ApplicationCreditService" />.
Expand All @@ -20,38 +19,19 @@ public class ApplicationCreditService : ShopifyService
/// <param name="shopAccessToken">An API access token for the shop.</param>
public ApplicationCreditService(string myShopifyUrl, string shopAccessToken) : base(myShopifyUrl, shopAccessToken) { }

/// <summary>
/// Gets a list of all past and present application credits.
/// </summary>
public virtual async Task<ListResult<ApplicationCredit>> ListAsync(ListFilter<ApplicationCredit> filter, CancellationToken cancellationToken = default)
{
return await ExecuteGetListAsync("application_credits.json", "application_credits", filter, cancellationToken);
}
/// <inheritdoc />
public virtual async Task<ListResult<ApplicationCredit>> ListAsync(ListFilter<ApplicationCredit> filter, CancellationToken cancellationToken = default) =>
await ExecuteGetListAsync("application_credits.json", "application_credits", filter, cancellationToken);

/// <summary>
/// Gets a list of all past and present application credits.
/// </summary>
public virtual async Task<ListResult<ApplicationCredit>> ListAsync(ApplicationCreditListFilter filter, CancellationToken cancellationToken = default)
{
return await ListAsync(filter?.AsListFilter(), cancellationToken);
}
/// <inheritdoc />
public virtual async Task<ListResult<ApplicationCredit>> ListAsync(ApplicationCreditListFilter filter, CancellationToken cancellationToken = default) =>
await ListAsync(filter?.AsListFilter(), cancellationToken);

/// <summary>
/// Retrieves the application credit with the given id.
/// </summary>
/// <param name="id">The application credit's id.</param>
/// <param name="fields">A comma-separated list of fields to include in the response.</param>
/// <param name="cancellationToken">Cancellation Token</param>
public virtual async Task<ApplicationCredit> GetAsync(long id, string fields = null, CancellationToken cancellationToken = default)
{
return await ExecuteGetAsync<ApplicationCredit>($"application_credits/{id}.json", "application_credit", fields, cancellationToken);
}
/// <inheritdoc />
public virtual async Task<ApplicationCredit> GetAsync(long id, string fields = null, CancellationToken cancellationToken = default) =>
await ExecuteGetAsync<ApplicationCredit>($"application_credits/{id}.json", "application_credit", fields, cancellationToken);

/// <summary>
/// Creates a new <see cref="ApplicationCredit"/>.
/// </summary>
/// <param name="credit">A new <see cref="ApplicationCredit"/>. Id should be set to null.</param>
/// <param name="cancellationToken">Cancellation Token</param>
/// <inheritdoc />
public virtual async Task<ApplicationCredit> CreateAsync(ApplicationCredit credit, CancellationToken cancellationToken = default)
{
var req = PrepareRequest($"application_credits.json");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System.Threading;
using System.Threading.Tasks;
using ShopifySharp.Filters;
using ShopifySharp.Lists;

namespace ShopifySharp
{
public interface IApplicationCreditService : IShopifyService
{
/// <summary>
/// Gets a list of all past and present application credits.
/// </summary>
Task<ListResult<ApplicationCredit>> ListAsync(ListFilter<ApplicationCredit> filter, CancellationToken cancellationToken = default);

/// <summary>
/// Gets a list of all past and present application credits.
/// </summary>
Task<ListResult<ApplicationCredit>> ListAsync(ApplicationCreditListFilter filter, CancellationToken cancellationToken = default);

/// <summary>
/// Retrieves the application credit with the given id.
/// </summary>
/// <param name="id">The application credit's id.</param>
/// <param name="fields">A comma-separated list of fields to include in the response.</param>
/// <param name="cancellationToken">Cancellation Token</param>
Task<ApplicationCredit> GetAsync(long id, string fields = null, CancellationToken cancellationToken = default);

/// <summary>
/// Creates a new <see cref="ApplicationCredit"/>.
/// </summary>
/// <param name="credit">A new <see cref="ApplicationCredit"/>. Id should be set to null.</param>
/// <param name="cancellationToken">Cancellation Token</param>
Task<ApplicationCredit> CreateAsync(ApplicationCredit credit, CancellationToken cancellationToken = default);
}
}
92 changes: 20 additions & 72 deletions ShopifySharp/Services/Article/ArticleService.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
using ShopifySharp.Filters;
using ShopifySharp.Infrastructure;
using ShopifySharp.Lists;
using System.Collections.Generic;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using ShopifySharp.Lists;
using System.Threading;

namespace ShopifySharp
{
/// <summary>
/// A service for manipulating a blog's articles.
/// </summary>
public class ArticleService : ShopifyService
public class ArticleService : ShopifyService, IArticleService
{
/// <summary>
/// Creates a new instance of the service.
Expand All @@ -20,40 +20,19 @@ public class ArticleService : ShopifyService
/// <param name="shopAccessToken">An API access token for the shop.</param>
public ArticleService(string myShopifyUrl, string shopAccessToken) : base(myShopifyUrl, shopAccessToken) { }

/// <summary>
/// Gets a list of up to 250 articles belonging to the given blog.
/// </summary>
public virtual async Task<ListResult<Article>> ListAsync(long blogId, ListFilter<Article> filter = null, CancellationToken cancellationToken = default)
{
return await ExecuteGetListAsync($"blogs/{blogId}/articles.json", "articles", filter, cancellationToken);
}
/// <inheritdoc />
public virtual async Task<ListResult<Article>> ListAsync(long blogId, ListFilter<Article> filter = null, CancellationToken cancellationToken = default) =>
await ExecuteGetListAsync($"blogs/{blogId}/articles.json", "articles", filter, cancellationToken);

/// <summary>
/// Gets a list of up to 250 articles belonging to the given blog.
/// </summary>
public virtual async Task<ListResult<Article>> ListAsync(int blogId, ArticleListFilter filter, CancellationToken cancellationToken = default)
{
return await ListAsync(blogId, (ListFilter<Article>) filter, cancellationToken);
}
/// <inheritdoc />
public virtual async Task<ListResult<Article>> ListAsync(int blogId, ArticleListFilter filter, CancellationToken cancellationToken = default) =>
await ListAsync(blogId, (ListFilter<Article>) filter, cancellationToken);

/// <summary>
/// Gets a count of the articles belonging to the given blog.
/// </summary>
/// <param name="blogId">The blog that the articles belong to.</param>
/// <param name="filter">Options for filtering the result.</param>
/// <param name="cancellationToken">Cancellation Token</param>
public virtual async Task<int> CountAsync(long blogId, ArticleCountFilter filter = null, CancellationToken cancellationToken = default)
{
return await ExecuteGetAsync<int>($"blogs/{blogId}/articles/count.json", "count", filter, cancellationToken);
}
/// <inheritdoc />
public virtual async Task<int> CountAsync(long blogId, ArticleCountFilter filter = null, CancellationToken cancellationToken = default) =>
await ExecuteGetAsync<int>($"blogs/{blogId}/articles/count.json", "count", filter, cancellationToken);

/// <summary>
/// Gets an article with the given id.
/// </summary>
/// <param name="blogId">The blog that the article belongs to.</param>
/// <param name="articleId">The article's id.</param>
/// <param name="fields">A comma-separated list of fields to return.</param>
/// <param name="cancellationToken">Cancellation Token</param>
/// <inheritdoc />
public virtual async Task<Article> GetAsync(long blogId, long articleId, string fields = null, CancellationToken cancellationToken = default)
{
var req = PrepareRequest($"blogs/{blogId}/articles/{articleId}.json");
Expand All @@ -67,13 +46,7 @@ public virtual async Task<Article> GetAsync(long blogId, long articleId, string
return response.Result;
}

/// <summary>
/// Creates a new article on the given blog.
/// </summary>
/// <param name="blogId">The blog that the article will belong to.</param>
/// <param name="article">The article being created. Id should be null.</param>
/// <param name="metafields">Optional metafield data that can be returned by the <see cref="MetaFieldService"/>.</param>
/// <param name="cancellationToken">Cancellation Token</param>
/// <inheritdoc />
public virtual async Task<Article> CreateAsync(long blogId, Article article, IEnumerable<MetaField> metafields = null, CancellationToken cancellationToken = default)
{
var req = PrepareRequest($"blogs/{blogId}/articles.json");
Expand All @@ -93,14 +66,7 @@ public virtual async Task<Article> CreateAsync(long blogId, Article article, IEn
return response.Result;
}

/// <summary>
/// Updates an article.
/// </summary>
/// <param name="blogId">The blog that the article belongs to.</param>
/// <param name="articleId">Id of the object being updated.</param>
/// <param name="article">The article being updated.</param>
/// <param name="metafields">Optional metafield data that can be returned by the <see cref="MetaFieldService"/>.</param>
/// <param name="cancellationToken">Cancellation Token</param>
/// <inheritdoc />
public virtual async Task<Article> UpdateAsync(long blogId, long articleId, Article article, IEnumerable<MetaField> metafields = null, CancellationToken cancellationToken = default)
{
var req = PrepareRequest($"blogs/{blogId}/articles/{articleId}.json");
Expand All @@ -120,22 +86,15 @@ public virtual async Task<Article> UpdateAsync(long blogId, long articleId, Arti
return response.Result;
}

/// <summary>
/// Deletes an article with the given id.
/// </summary>
/// <param name="blogId">The blog that the article belongs to.</param>
/// <param name="articleId">The article benig deleted.</param>
/// <param name="cancellationToken">Cancellation Token</param>
/// <inheritdoc />
public virtual async Task DeleteAsync(long blogId, long articleId, CancellationToken cancellationToken = default)
{
var req = PrepareRequest($"blogs/{blogId}/articles/{articleId}.json");

await ExecuteRequestAsync(req, HttpMethod.Delete, cancellationToken);
}

/// <summary>
/// Gets a list of all article authors.
/// </summary>
/// <inheritdoc />
public virtual async Task<IEnumerable<string>> ListAuthorsAsync(CancellationToken cancellationToken = default)
{
var req = PrepareRequest($"articles/authors.json");
Expand All @@ -144,12 +103,7 @@ public virtual async Task<IEnumerable<string>> ListAuthorsAsync(CancellationToke
return response.Result;
}

/// <summary>
/// Gets a list of all article tags.
/// </summary>
/// <param name="limit">The number of tags to return</param>
/// <param name="popular">A flag to indicate only to a certain number of the most popular tags.</param>
/// <param name="cancellationToken">Cancellation Token</param>
/// <inheritdoc />
public virtual async Task<IEnumerable<string>> ListTagsAsync(int? popular = null, int? limit = null, CancellationToken cancellationToken = default)
{
var req = PrepareRequest($"articles/tags.json");
Expand All @@ -168,13 +122,7 @@ public virtual async Task<IEnumerable<string>> ListTagsAsync(int? popular = null
return response.Result;
}

/// <summary>
/// Gets a list of all article tags for the given blog.
/// </summary>
/// <param name="blogId">The blog that the tags belong to.</param>
/// <param name="limit">The number of tags to return</param>
/// <param name="popular">A flag to indicate only to a certain number of the most popular tags.</param>
/// <param name="cancellationToken">Cancellation Token</param>
/// <inheritdoc />
public virtual async Task<IEnumerable<string>> ListTagsForBlogAsync(long blogId, int? popular = null, int? limit = null, CancellationToken cancellationToken = default)
{
var req = PrepareRequest($"blogs/{blogId}/articles/tags.json");
Expand All @@ -193,4 +141,4 @@ public virtual async Task<IEnumerable<string>> ListTagsForBlogAsync(long blogId,
return response.Result;
}
}
}
}
Loading

0 comments on commit 940350e

Please sign in to comment.