discourse_subscription_client 0.1.0.pre11 → 0.1.0.pre12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/models/subscription_client_supplier.rb +5 -7
- data/db/migrate/20230223135957_add_products_to_subscription_client_suppliers.rb +1 -1
- data/lib/discourse_subscription_client/engine.rb +9 -3
- data/lib/discourse_subscription_client/resources.rb +13 -19
- data/lib/discourse_subscription_client/subscriptions/result.rb +3 -2
- data/lib/discourse_subscription_client/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d17f2464b6f962f809428eea6207696f20a1d935ed573ec0f3970242712a8da9
|
4
|
+
data.tar.gz: f226a6927bc9e41fcd199572d5417850212de9d335ed58fa325b58b0842776d3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cda4eb9051cbeb1a62e317a314d79bd08a2e0eb255775adf6e0c45ff53bb527ab3b14338d0a90d4f09fc28a8da20ebb3f375eeba33bc43770d7eb07734d99fa7
|
7
|
+
data.tar.gz: 72cfb38e708e8a4c8bb56cb8d38a7374300d194e68c461ef32bca490a199e00775463ec3196fca50b0166ee6d49ad0b04e9e25fda689811eab127074ac81e915
|
@@ -19,13 +19,11 @@ class SubscriptionClientSupplier < ActiveRecord::Base
|
|
19
19
|
api_key.present?
|
20
20
|
end
|
21
21
|
|
22
|
-
def product_slugs
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
else
|
28
|
-
{}
|
22
|
+
def product_slugs(resource)
|
23
|
+
return {} unless products.present? && products[resource]
|
24
|
+
|
25
|
+
products[resource].each_with_object({}) do |product, result|
|
26
|
+
result[product["product_id"]] = product["product_slug"]
|
29
27
|
end
|
30
28
|
end
|
31
29
|
|
@@ -88,7 +88,7 @@ module DiscourseSubscriptionClient
|
|
88
88
|
end
|
89
89
|
|
90
90
|
def plugin_status_server_url
|
91
|
-
"https://
|
91
|
+
"https://coop.pavilion.tech"
|
92
92
|
end
|
93
93
|
|
94
94
|
def database_exists?
|
@@ -110,9 +110,15 @@ module DiscourseSubscriptionClient
|
|
110
110
|
result = DiscourseSubscriptionClient::Subscriptions::Result.new
|
111
111
|
return result unless subscriptions.exists?
|
112
112
|
|
113
|
-
|
114
|
-
|
113
|
+
resource = subscriptions.first.resource
|
114
|
+
supplier = resource.supplier
|
115
|
+
products = supplier.product_slugs(resource_name)
|
116
|
+
return result unless products.present?
|
117
|
+
|
118
|
+
result.resource = resource
|
119
|
+
result.supplier = supplier
|
115
120
|
result.subscriptions = subscriptions.to_a
|
121
|
+
result.products = products
|
116
122
|
|
117
123
|
result
|
118
124
|
end
|
@@ -42,21 +42,13 @@ module DiscourseSubscriptionClient
|
|
42
42
|
supplier_urls = @resources.map { |resource| resource[:supplier_url] }.uniq.compact
|
43
43
|
|
44
44
|
supplier_urls.each do |url|
|
45
|
-
supplier = SubscriptionClientSupplier.
|
45
|
+
supplier = SubscriptionClientSupplier.find_or_create_by(url: url)
|
46
|
+
request = DiscourseSubscriptionClient::Request.new(:supplier, supplier.id)
|
47
|
+
data = request.perform("#{url}/subscription-server")
|
46
48
|
|
47
|
-
if
|
49
|
+
if valid_supplier_data?(data)
|
50
|
+
supplier.update(name: data[:supplier], products: data[:products])
|
48
51
|
@suppliers << supplier
|
49
|
-
else
|
50
|
-
supplier ||= SubscriptionClientSupplier.create!(url: url)
|
51
|
-
request = DiscourseSubscriptionClient::Request.new(:supplier, supplier.id)
|
52
|
-
data = request.perform("#{url}/subscription-server")
|
53
|
-
|
54
|
-
if valid_supplier_data?(data)
|
55
|
-
supplier.update(name: data[:supplier], products: data[:products])
|
56
|
-
@suppliers << supplier
|
57
|
-
else
|
58
|
-
supplier.destroy!
|
59
|
-
end
|
60
52
|
end
|
61
53
|
end
|
62
54
|
end
|
@@ -98,12 +90,14 @@ module DiscourseSubscriptionClient
|
|
98
90
|
return false unless data.present? && data.is_a?(Hash)
|
99
91
|
return false unless %i[supplier products].all? { |key| data.key?(key) }
|
100
92
|
return false unless data[:supplier].is_a?(String)
|
101
|
-
return false unless data[:products].is_a?(
|
102
|
-
|
103
|
-
data[:products].all? do |
|
104
|
-
|
105
|
-
|
106
|
-
|
93
|
+
return false unless data[:products].is_a?(Hash)
|
94
|
+
|
95
|
+
data[:products].all? do |_resource, products|
|
96
|
+
products.is_a?(Array) &&
|
97
|
+
products.all? do |product|
|
98
|
+
%i[product_id product_slug].all? do |key|
|
99
|
+
product.key?(key) && product[key].is_a?(String)
|
100
|
+
end
|
107
101
|
end
|
108
102
|
end
|
109
103
|
end
|
@@ -5,10 +5,11 @@ module DiscourseSubscriptionClient
|
|
5
5
|
class Result
|
6
6
|
attr_accessor :supplier,
|
7
7
|
:resource,
|
8
|
-
:subscriptions
|
8
|
+
:subscriptions,
|
9
|
+
:products
|
9
10
|
|
10
11
|
def any?
|
11
|
-
supplier.present? && resource.present? && subscriptions.present?
|
12
|
+
supplier.present? && resource.present? && subscriptions.present? && products.present?
|
12
13
|
end
|
13
14
|
end
|
14
15
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: discourse_subscription_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.0.
|
4
|
+
version: 0.1.0.pre12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Angus McLeod
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-05-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: active_model_serializers
|
@@ -293,7 +293,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
293
293
|
- !ruby/object:Gem::Version
|
294
294
|
version: 1.3.1
|
295
295
|
requirements: []
|
296
|
-
rubygems_version: 3.
|
296
|
+
rubygems_version: 3.4.6
|
297
297
|
signing_key:
|
298
298
|
specification_version: 4
|
299
299
|
summary: Discourse plugin subscription client.
|