Skip to content

Commit 2944c92

Browse files
committed
Remove shared library and adjust object references.
1 parent dd676fc commit 2944c92

19 files changed

+342
-45
lines changed

src/Umbraco.Cms.Integrations.Commerce.Shopify/Controllers/ProductsController.cs

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
using System.Threading.Tasks;
2-
2+
using Umbraco.Cms.Integrations.Commerce.Shopify.Models;
33
using Umbraco.Cms.Integrations.Commerce.Shopify.Models.Dtos;
4-
using Umbraco.Cms.Integrations.Shared.Models;
5-
using Umbraco.Cms.Integrations.Shared.Models.Dtos;
6-
using Umbraco.Cms.Integrations.Shared.Services;
4+
using Umbraco.Cms.Integrations.Commerce.Shopify.Services;
75

86

97
#if NETCOREAPP
@@ -22,9 +20,9 @@ namespace Umbraco.Cms.Integrations.Commerce.Shopify.Controllers
2220
[PluginController("UmbracoCmsIntegrationsCommerceShopify")]
2321
public class ProductsController : UmbracoAuthorizedApiController
2422
{
25-
private readonly IApiService<ProductsListDto> _apiService;
23+
private readonly IShopifyService _apiService;
2624

27-
public ProductsController(IApiService<ProductsListDto> apiService)
25+
public ProductsController(IShopifyService apiService)
2826
{
2927
_apiService = apiService;
3028
}

src/Umbraco.Cms.Integrations.Commerce.Shopify/Editors/ShopifyProductPickerConfiguration.cs

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using Umbraco.Cms.Integrations.Commerce.Shopify.Models;
2-
using Umbraco.Cms.Integrations.Shared.Models;
32

43
#if NETCOREAPP
54
using Umbraco.Cms.Core.PropertyEditors;

src/Umbraco.Cms.Integrations.Commerce.Shopify/Editors/ShopifyProductPickerValueConverter.cs

+3-4
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
using System.Collections.Generic;
33
using System.Linq;
44

5-
using Umbraco.Cms.Integrations.Commerce.Shopify.Models.Dtos;
65
using Umbraco.Cms.Integrations.Commerce.Shopify.Models.ViewModels;
7-
using Umbraco.Cms.Integrations.Shared.Services;
6+
using Umbraco.Cms.Integrations.Commerce.Shopify.Services;
87

98
#if NETCOREAPP
109
using Umbraco.Cms.Core.PropertyEditors;
@@ -18,9 +17,9 @@ namespace Umbraco.Cms.Integrations.Commerce.Shopify.Editors
1817
{
1918
public class ShopifyProductPickerValueConverter : PropertyValueConverterBase
2019
{
21-
private readonly IApiService<ProductsListDto> _apiService;
20+
private readonly IShopifyService _apiService;
2221

23-
public ShopifyProductPickerValueConverter(IApiService<ProductsListDto> apiService)
22+
public ShopifyProductPickerValueConverter(IShopifyService apiService)
2423
{
2524
_apiService = apiService;
2625
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using Newtonsoft.Json;
2+
3+
namespace Umbraco.Cms.Integrations.Commerce.Shopify.Models
4+
{
5+
public class ConfigurationType
6+
{
7+
[JsonProperty("value")]
8+
public string Value { get; private set; }
9+
10+
private ConfigurationType(string value)
11+
{
12+
Value = value;
13+
}
14+
15+
public static ConfigurationType Api => new ConfigurationType("API");
16+
17+
public static ConfigurationType OAuth => new ConfigurationType("OAuth");
18+
19+
20+
public static ConfigurationType None => new ConfigurationType("None");
21+
}
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using Newtonsoft.Json;
2+
3+
namespace Umbraco.Cms.Integrations.Commerce.Shopify.Models.Dtos
4+
{
5+
public class ErrorDto
6+
{
7+
[JsonProperty("status")]
8+
public string Status { get; set; }
9+
10+
[JsonProperty("message")]
11+
public string Message { get; set; }
12+
}
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using Newtonsoft.Json;
2+
3+
namespace Umbraco.Cms.Integrations.Commerce.Shopify.Models.Dtos
4+
{
5+
public class OAuthRequestDto
6+
{
7+
[JsonProperty("code")]
8+
public string Code { get; set; }
9+
}
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using System.Collections.Generic;
2+
3+
using Newtonsoft.Json;
4+
5+
namespace Umbraco.Cms.Integrations.Commerce.Shopify.Models.Dtos
6+
{
7+
public class ResponseDto<T>
8+
where T : class
9+
{
10+
[JsonProperty("isValid")]
11+
public bool IsValid { get; set; }
12+
13+
[JsonProperty("isExpired")]
14+
public bool IsExpired { get; set; }
15+
16+
[JsonProperty("result")]
17+
public T Result { get; set; }
18+
19+
[JsonProperty("message")]
20+
public string Message { get; set; }
21+
22+
}
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using Newtonsoft.Json;
2+
3+
namespace Umbraco.Cms.Integrations.Commerce.Shopify.Models
4+
{
5+
public class EditorSettings
6+
{
7+
public EditorSettings()
8+
{
9+
Type = ConfigurationType.None;
10+
}
11+
12+
[JsonProperty("isValid")]
13+
public bool IsValid { get; set; }
14+
15+
[JsonProperty("type")]
16+
public ConfigurationType Type { get; set; }
17+
}
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System.Runtime.Serialization;
2+
3+
namespace Umbraco.Cms.Integrations.Commerce.Shopify.Models
4+
{
5+
[DataContract]
6+
public class NumberRange
7+
{
8+
[DataMember(Name = "min")]
9+
public int? Min { get; set; }
10+
11+
[DataMember(Name = "max")]
12+
public int? Max { get; set; }
13+
}
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Reflection;
4+
5+
using Newtonsoft.Json;
6+
using Newtonsoft.Json.Serialization;
7+
8+
namespace Umbraco.Cms.Integrations.Commerce.Shopify.Resolvers
9+
{
10+
public class JsonPropertyRenameContractResolver : DefaultContractResolver
11+
{
12+
private readonly Dictionary<Type, Dictionary<string, string>> _renames;
13+
14+
public JsonPropertyRenameContractResolver()
15+
{
16+
_renames = new Dictionary<Type, Dictionary<string, string>>();
17+
}
18+
19+
public void RenameProperty(Type type, string propertyName, string newJsonPropertyName)
20+
{
21+
if (!_renames.ContainsKey(type))
22+
_renames[type] = new Dictionary<string, string>();
23+
24+
_renames[type][propertyName] = newJsonPropertyName;
25+
}
26+
27+
protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization)
28+
{
29+
var property = base.CreateProperty(member, memberSerialization);
30+
31+
if (IsRenamed(property.DeclaringType, property.PropertyName, out var newJsonPropertyName))
32+
property.PropertyName = newJsonPropertyName;
33+
34+
return property;
35+
}
36+
37+
private bool IsRenamed(Type type, string jsonPropertyName, out string newJsonPropertyName)
38+
{
39+
if (!_renames.TryGetValue(type, out var renames) || !renames.TryGetValue(jsonPropertyName, out newJsonPropertyName))
40+
{
41+
newJsonPropertyName = null;
42+
return false;
43+
}
44+
45+
return true;
46+
}
47+
}
48+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
using System;
2+
3+
using Newtonsoft.Json;
4+
5+
#if NETCOREAPP
6+
using Umbraco.Cms.Core.Cache;
7+
using Umbraco.Extensions;
8+
#else
9+
using Umbraco.Core.Cache;
10+
#endif
11+
12+
13+
namespace Umbraco.Cms.Integrations.Commerce.Shopify.Services
14+
{
15+
public class CacheHelper : ICacheHelper
16+
{
17+
private readonly IAppPolicyCache _cache;
18+
19+
public CacheHelper(AppCaches appCaches)
20+
{
21+
_cache = appCaches.RuntimeCache;
22+
}
23+
24+
public bool TryGetCachedItem<T>(string key, out T item) where T : class
25+
{
26+
var serializedItem = _cache.GetCacheItem<string>(key);
27+
28+
item = string.IsNullOrEmpty(serializedItem)
29+
? null
30+
: JsonConvert.DeserializeObject<T>(serializedItem);
31+
32+
return !string.IsNullOrEmpty(serializedItem);
33+
}
34+
35+
public void AddCachedItem(string key, string item)
36+
{
37+
_cache.InsertCacheItem(key, () => item, TimeSpan.FromHours(1));
38+
}
39+
40+
public void ClearCachedItems()
41+
{
42+
_cache.Clear();
43+
}
44+
}
45+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+

2+
namespace Umbraco.Cms.Integrations.Commerce.Shopify.Services
3+
{
4+
public interface ICacheHelper
5+
{
6+
bool TryGetCachedItem<T>(string key, out T item) where T : class;
7+
8+
void AddCachedItem(string key, string serializedItem);
9+
10+
void ClearCachedItems();
11+
}
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System.Threading.Tasks;
2+
3+
using Umbraco.Cms.Integrations.Commerce.Shopify.Models;
4+
using Umbraco.Cms.Integrations.Commerce.Shopify.Models.Dtos;
5+
6+
namespace Umbraco.Cms.Integrations.Commerce.Shopify.Services
7+
{
8+
public interface IShopifyService
9+
{
10+
EditorSettings GetApiConfiguration();
11+
12+
string GetAuthorizationUrl();
13+
14+
Task<string> GetAccessToken(OAuthRequestDto request);
15+
16+
Task<ResponseDto<ProductsListDto>> ValidateAccessToken();
17+
18+
void RevokeAccessToken();
19+
20+
Task<ResponseDto<ProductsListDto>> GetResults();
21+
}
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+

2+
namespace Umbraco.Cms.Integrations.Commerce.Shopify.Services
3+
{
4+
public interface ITokenService
5+
{
6+
bool TryGetParameters(string key, out string value);
7+
8+
void SaveParameters(string key, string serializedParams);
9+
10+
void RemoveParameters(string key);
11+
}
12+
}

src/Umbraco.Cms.Integrations.Commerce.Shopify/Services/SettingsService.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ namespace Umbraco.Cms.Integrations.Commerce.Shopify.Services
33
{
44
public class SettingsService
55
{
6-
public static string OAuthProxyBaseUrl = "https://localhost:44364/";
7-
6+
public static string OAuthProxyBaseUrl = "https://hubspot-forms-auth.umbraco.com/"; // for local testing: "https://localhost:44364/";
7+
88
public static string OAuthProxyEndpoint = "{0}oauth/v1/token";
99

1010
public static string ShopifyOAuthProxyUrl = $"{OAuthProxyBaseUrl}oauth/shopify";

0 commit comments

Comments
 (0)