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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1e9c613aa210fef7c5beacc341e3f704e131d67c5b79af85857458b0386c14a1
4
- data.tar.gz: 99cd4b1e1f61ad63f1f8d96ecf81091442cea1e4141c9b41a0c3f02da3018418
3
+ metadata.gz: 7100f3f61c70ca7b6c85e41160a7f06c4c1222aa55c69fc4772dc0053b1e381a
4
+ data.tar.gz: 63c8355e974192f6642e63699ddc14bbe7fb176cd0456776e04560b04a579657
5
5
  SHA512:
6
- metadata.gz: 0d2b1d5314c41feaeda861642cd459466861945a9596990353db26c5124ea7f758215bf1b2f9d6beee810ca0400f9fadb3b4da3b8bfe6ec3b609093090bb5339
7
- data.tar.gz: 8c412d3337fe1c7f6790ada74217bd678d50ab411a20bb908ac829c39ad086d9776880bfc921ecfdd3f250d0511a59c9dbdf96814dff767370a3f6f0dd58c804
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
- REQUIRED_KEYS ||= %i[
6
+ REQUIRED_SUBSCRIPTION_KEYS ||= %i[
7
7
  resource_id
8
8
  product_id
9
9
  price_id
10
10
  ].freeze
11
- OPTIONAL_KEYS ||= %i[
11
+ OPTIONAL_SUBSCRIPTION_KEYS ||= %i[
12
12
  product_name
13
13
  price_name
14
14
  ].freeze
15
- KEYS = REQUIRED_KEYS + OPTIONAL_KEYS
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
- # subscriptions must be properly formed
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(*REQUIRED_KEYS),
60
- create: data.slice(*KEYS),
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
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DiscourseSubscriptionClient
4
- VERSION = "0.1.2"
4
+ VERSION = "0.1.3"
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.2
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-02-23 00:00:00.000000000 Z
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