discourse_subscription_client 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/db/migrate/20240917131841_add_keys_to_subscription_client_resource.rb +8 -0
- data/lib/discourse_subscription_client/subscriptions/update_result.rb +34 -14
- data/lib/discourse_subscription_client/subscriptions.rb +4 -0
- data/lib/discourse_subscription_client/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7100f3f61c70ca7b6c85e41160a7f06c4c1222aa55c69fc4772dc0053b1e381a
|
4
|
+
data.tar.gz: 63c8355e974192f6642e63699ddc14bbe7fb176cd0456776e04560b04a579657
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 07b49001753c66976c6bd4f8aef241813179e7895356a3f776b6d596869fb7904a6d2fdbacc01d8cad3450e9a432a59e8fd2f440a008e356a9a0652eb4f7abc1
|
7
|
+
data.tar.gz: bfcff448a51fe8b32354d497bc4901edf7839d0ba5e53f304a268762ef9314cae19de0a1ee1e36b87c989f28b2daff2d8485ff38dc238d42dc4ef47e7b2677c0
|
@@ -0,0 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class AddKeysToSubscriptionClientResource < ActiveRecord::Migration[7.0]
|
4
|
+
def change
|
5
|
+
add_column :subscription_client_resources, :access_key_id, :string, if_not_exists: true
|
6
|
+
add_column :subscription_client_resources, :secret_access_key, :string, if_not_exists: true
|
7
|
+
end
|
8
|
+
end
|
@@ -3,16 +3,21 @@
|
|
3
3
|
module ::DiscourseSubscriptionClient
|
4
4
|
class Subscriptions
|
5
5
|
class UpdateResult
|
6
|
-
|
6
|
+
REQUIRED_SUBSCRIPTION_KEYS ||= %i[
|
7
7
|
resource_id
|
8
8
|
product_id
|
9
9
|
price_id
|
10
10
|
].freeze
|
11
|
-
|
11
|
+
OPTIONAL_SUBSCRIPTION_KEYS ||= %i[
|
12
12
|
product_name
|
13
13
|
price_name
|
14
14
|
].freeze
|
15
|
-
|
15
|
+
SUBSCRIPTION_KEYS = REQUIRED_SUBSCRIPTION_KEYS + OPTIONAL_SUBSCRIPTION_KEYS
|
16
|
+
REQUIRED_RESOURCE_KEYS ||= %i[
|
17
|
+
resource
|
18
|
+
access_key_id
|
19
|
+
secret_access_key
|
20
|
+
]
|
16
21
|
|
17
22
|
attr_reader :errors,
|
18
23
|
:errored_suppliers,
|
@@ -35,16 +40,10 @@ module ::DiscourseSubscriptionClient
|
|
35
40
|
return []
|
36
41
|
end
|
37
42
|
|
38
|
-
|
39
|
-
|
40
|
-
subscriptions_data =
|
41
|
-
subscriptions_data
|
42
|
-
.map(&:symbolize_keys)
|
43
|
-
.each { |data| data[:resource_id] = data[:resource] }
|
44
|
-
.select { |data| REQUIRED_KEYS.all? { |key| data.key?(key) } }
|
43
|
+
subscriptions_data = format_subscriptions_data(subscriptions_data)
|
44
|
+
resources_data = format_resources_data(raw_data[:resources])
|
45
45
|
|
46
46
|
# we only care about subscriptions for resources on this instance
|
47
|
-
|
48
47
|
resources = SubscriptionClientResource.where(
|
49
48
|
supplier_id: supplier.id,
|
50
49
|
name: subscriptions_data.map { |data| data[:resource] }
|
@@ -56,9 +55,11 @@ module ::DiscourseSubscriptionClient
|
|
56
55
|
if resource.present?
|
57
56
|
data[:resource_id] = resource.id
|
58
57
|
result << OpenStruct.new(
|
59
|
-
required: data.slice(*
|
60
|
-
create: data.slice(*
|
61
|
-
subscription: nil
|
58
|
+
required: data.slice(*REQUIRED_SUBSCRIPTION_KEYS),
|
59
|
+
create: data.slice(*SUBSCRIPTION_KEYS),
|
60
|
+
subscription: nil,
|
61
|
+
resource: resource,
|
62
|
+
resource_data: resources_data[resource.name]
|
62
63
|
)
|
63
64
|
else
|
64
65
|
info("no_resource", supplier, resource: data[:resource])
|
@@ -66,6 +67,25 @@ module ::DiscourseSubscriptionClient
|
|
66
67
|
end
|
67
68
|
end
|
68
69
|
|
70
|
+
def format_subscriptions_data(subscriptions_data)
|
71
|
+
subscriptions_data
|
72
|
+
.map(&:symbolize_keys)
|
73
|
+
.each { |data| data[:resource_id] = data[:resource] }
|
74
|
+
.select { |data| REQUIRED_SUBSCRIPTION_KEYS.all? { |key| data.key?(key) } }
|
75
|
+
end
|
76
|
+
|
77
|
+
def format_resources_data(resources_data)
|
78
|
+
return {} unless resources_data
|
79
|
+
|
80
|
+
resources_data
|
81
|
+
.compact
|
82
|
+
.map(&:symbolize_keys)
|
83
|
+
.select { |data| REQUIRED_RESOURCE_KEYS.all? { |key| data.key?(key) } }
|
84
|
+
.each_with_object({}) do |data, result|
|
85
|
+
result[data[:resource]] = data.slice(:access_key_id, :secret_access_key)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
69
89
|
def connection_error(supplier)
|
70
90
|
error("supplier_connection", supplier)
|
71
91
|
end
|
@@ -37,6 +37,8 @@ module DiscourseSubscriptionClient
|
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
|
+
DiscourseEvent.trigger(:subscription_client_subscriptions_updated, @result)
|
41
|
+
|
40
42
|
@result.errors.blank?
|
41
43
|
end
|
42
44
|
|
@@ -85,6 +87,8 @@ module DiscourseSubscriptionClient
|
|
85
87
|
@result.failed_to_create_subscription(supplier, subscription_ids: data.required)
|
86
88
|
end
|
87
89
|
end
|
90
|
+
|
91
|
+
data.resource.update(data.resource_data) if data.resource.present? && data.resource_data.present?
|
88
92
|
end
|
89
93
|
end
|
90
94
|
|
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.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Angus McLeod
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-09-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: active_model_serializers
|
@@ -258,6 +258,7 @@ files:
|
|
258
258
|
- db/migrate/20230221100535_create_subscription_client_subscriptions.rb
|
259
259
|
- db/migrate/20230221100540_create_subscription_client_requests.rb
|
260
260
|
- db/migrate/20230223135957_add_products_to_subscription_client_suppliers.rb
|
261
|
+
- db/migrate/20240917131841_add_keys_to_subscription_client_resource.rb
|
261
262
|
- extensions/discourse_subscription_client/current_user_serializer.rb
|
262
263
|
- extensions/discourse_subscription_client/guardian.rb
|
263
264
|
- extensions/discourse_subscription_client/site_serializer.rb
|