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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6182382e0517359b04736dd702fc121669e40775a138eaf6bab7493ae722591a
4
- data.tar.gz: 4554111e5f4b3659cfbf5d1ac70bed551237435e32c5265acf8a8093ca7db5d4
3
+ metadata.gz: d17f2464b6f962f809428eea6207696f20a1d935ed573ec0f3970242712a8da9
4
+ data.tar.gz: f226a6927bc9e41fcd199572d5417850212de9d335ed58fa325b58b0842776d3
5
5
  SHA512:
6
- metadata.gz: 2988268b14449153a71e2345489f8cc97861b1d6562d62901724ba0db2151465a58bc153bffad9d5a516e2218cfd761523a0d95d8ca90a3e0c24351c1f21365b
7
- data.tar.gz: e7d340f95ce7995c7edb4444987daec675706e056898613a2b7526af5010d5a239249e764d4e7804a0e3c75ac1ae0f16386c03e9c691d72ce0ff0f96bfeb45d1
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
- if products.present?
24
- products.each_with_object({}) do |product, result|
25
- result[product["product_id"]] = product["product_slug"]
26
- end
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
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  class AddProductsToSubscriptionClientSuppliers < ActiveRecord::Migration[7.0]
4
4
  def change
5
- add_column :subscription_client_suppliers, :products, :json
5
+ add_column :subscription_client_suppliers, :products, :json, if_not_exists: true
6
6
  end
7
7
  end
@@ -88,7 +88,7 @@ module DiscourseSubscriptionClient
88
88
  end
89
89
 
90
90
  def plugin_status_server_url
91
- "https://discourse.pluginmanager.org"
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
- result.resource = subscriptions.first.resource
114
- result.supplier = subscriptions.first.resource.supplier
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.find_by(url: url)
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 supplier&.name
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?(Array)
102
-
103
- data[:products].all? do |product|
104
- product.is_a?(Hash) &&
105
- %i[product_id product_slug].all? do |key|
106
- product.key?(key) && product[key].is_a?(String)
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DiscourseSubscriptionClient
4
- VERSION = "0.1.0.pre11"
4
+ VERSION = "0.1.0.pre12"
5
5
  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.pre11
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-03-29 00:00:00.000000000 Z
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.3.26
296
+ rubygems_version: 3.4.6
297
297
  signing_key:
298
298
  specification_version: 4
299
299
  summary: Discourse plugin subscription client.