gitlab-customer-support-operations_slack 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 197f06808537284ce01293feb93a28b2b87a3793a47aa33085972230d099a5c5
4
+ data.tar.gz: 7c4c638d220665f180c54667b391430062636bd6db50f979f90d6ee579110ee0
5
+ SHA512:
6
+ metadata.gz: c0689cc4b6364cdbbd2f993bb298effc8216b1484e7268ac2ac3ac885751d8722d4863b2f4e92bded29be157600aa76487b94fc7239af2ccbf81e6af91b48e72
7
+ data.tar.gz: 211680f8bef17a53b8dee7231b2957e8d7ab660ec9fdd5bebd64db558823ef60a673dccbf8e79d82ee2de65b03e536121030bea67fa3a6dc2e298b3920f7af16
@@ -0,0 +1,112 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Defines the module SupportOps.
4
+ module SupportOps
5
+ # Defines the module Slack
6
+ module Slack
7
+ ##
8
+ # Defines the class Base within the module {SupportOps::Slack}.
9
+ #
10
+ # @author Jason Colyer
11
+ # @since 1.0.0
12
+ class Base
13
+ class << self
14
+ def client
15
+ Configuration.config.client
16
+ end
17
+
18
+ def configure
19
+ yield Configuration.config
20
+ end
21
+
22
+ def define_attributes(*attrs)
23
+ @attributes = attrs
24
+ attrs.each do |attr|
25
+ attr_accessor attr
26
+ end
27
+ end
28
+
29
+ def attributes
30
+ @attributes || []
31
+ end
32
+
33
+ def readonly_attributes(*attrs)
34
+ return @readonly_attributes || [] if attrs.empty?
35
+
36
+ @readonly_attributes = attrs
37
+ end
38
+ end
39
+
40
+ def initialize(attributes = {}, client = nil)
41
+ @client = client
42
+ @original_attributes = {}
43
+ set_attributes(attributes)
44
+ store_original_attributes
45
+ end
46
+
47
+ def store_original_attributes
48
+ @original_attributes = {}
49
+ self.class.attributes.each do |attr|
50
+ @original_attributes[attr] = instance_variable_get("@#{attr}")
51
+ end
52
+ end
53
+
54
+ def save!
55
+ ensure_client_present!
56
+ create_record
57
+ end
58
+
59
+ def client=(new_client)
60
+ @client = new_client
61
+ end
62
+
63
+ protected
64
+
65
+ attr_reader :attributes, :original_attributes
66
+
67
+ def set_attributes(attributes)
68
+ return unless attributes
69
+
70
+ attrs = attributes.transform_keys(&:to_sym)
71
+
72
+ self.class.attributes.each do |attr|
73
+ instance_variable_set("@#{attr}", attrs[attr])
74
+ end
75
+ end
76
+
77
+ def attributes_for_save
78
+ if send(:url) == nil
79
+ self.class.attributes
80
+ .reject { |attr| self.class.readonly_attributes.include?(attr) }
81
+ .each_with_object({}) do |attr, hash|
82
+ hash[attr] = send(attr)
83
+ end
84
+ else
85
+ self.class.attributes
86
+ .reject { |attr| self.class.readonly_attributes.include?(attr) }
87
+ .each_with_object({}) do |attr, hash|
88
+ current_value = send(attr)
89
+ original_value = @original_attributes[attr]
90
+
91
+ hash[attr] = current_value if attr == :url
92
+ if original_value != current_value
93
+ hash[attr] = current_value
94
+ end
95
+ end
96
+ end
97
+ end
98
+
99
+ def client
100
+ @client ||= self.class.client
101
+ end
102
+
103
+ def ensure_client_present!
104
+ raise 'No client configured. Use SupportOps::Slack.configure to set up the client.' unless client
105
+ end
106
+
107
+ def create_record
108
+ raise NotImplementedError
109
+ end
110
+ end
111
+ end
112
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Defines the module SupportOps.
4
+ module SupportOps
5
+ # Defines the module Slack
6
+ module Slack
7
+ ##
8
+ # Defines the class Client within the module {SupportOps::Slack}.
9
+ #
10
+ # @author Jason Colyer
11
+ # @since 1.0.0
12
+ class Client
13
+ class Error < StandardError; end
14
+ class RequestError < Error; end
15
+ class ResourceNotFound < Error; end
16
+
17
+ attr_reader :connection
18
+
19
+ def initialize(config = SupportOps::Slack::Configuration.new)
20
+ @connection = generate_connection(config)
21
+ end
22
+
23
+ def retry_options(config)
24
+ {
25
+ max: config[:retry_max],
26
+ interval: config[:retry_interval],
27
+ interval_randomness: config[:retry_randomness],
28
+ backoff_factor: config[:retry_backoff],
29
+ exceptions: config[:retry_exceptions]
30
+ }
31
+ end
32
+
33
+ def generate_connection(config)
34
+ Faraday.new(config[:url]) do |c|
35
+ c.request :retry, retry_options(config)
36
+ c.adapter Faraday.default_adapter
37
+ c.headers['Content-Type'] = 'application/json'
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,79 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Defines the module SupportOps.
4
+ module SupportOps
5
+ # Defines the module Slack
6
+ module Slack
7
+ ##
8
+ # Defines the module Configuration within the module {SupportOps::Slack}.
9
+ #
10
+ # @author Jason Colyer
11
+ # @since 1.0.0
12
+ module Configuration
13
+ ##
14
+ # Setup a Slack client configuration
15
+ #
16
+ # @author Jason Colyer
17
+ # @since 1.0.0
18
+ # @overload configure(key: value)
19
+ # @param retry_backoff [Integer] See {Config#retry_backoff}
20
+ # @param retry_exceptions [Array] See {Config#retry_exceptions}
21
+ # @param retry_interval [Integer] See {Config#retry_interval}
22
+ # @param retry_max [Integer] See {Config#retry_max}
23
+ # @param retry_randomness [Integer] See {Config#retry_randomness}
24
+ # @param url [String] See {Config#url}
25
+ # @example
26
+ # require 'support_ops_slack'
27
+ #
28
+ # SupportOps::Slack::Configuration.configure do |config|
29
+ # config.url = ENV.fetch('SLACK_URL')
30
+ # end
31
+ def self.configure
32
+ yield config
33
+ end
34
+
35
+ def self.config
36
+ @config ||= Config.new
37
+ end
38
+
39
+ def self.reset!
40
+ @config = Config.new
41
+ end
42
+
43
+ ##
44
+ # Defined the class Config within the module {SupportOps::Slack::Configuration}
45
+ #
46
+ # @author Jason Colyer
47
+ # @since 1.0.0
48
+ # @attr [Integer] retry_backoff multiplier applied to the retry_interval after each retry attempt, causing exponential backoff. Defaults to 2
49
+ # @attr [Array] retry_exceptions Specifies which types of exceptions or errors should trigger the retry mechanism.
50
+ # @attr [Integer] retry_interval The base time interval (typically in seconds or milliseconds) between retry attempts. Defaults to 1
51
+ # @attr [Integer] retry_max The maximum number of retry attempts that will be made when an operation fails. Defaults to 5
52
+ # @attr [Float] retry_randomness Adds a random element to the retry interval to prevent "thundering herd" problems where many systems retry simultaneously. Defaults to 0.5
53
+ # @attr [String] url The URL to use
54
+ class Config
55
+ attr_accessor :url, :retry_max, :retry_interval, :retry_randomness,
56
+ :retry_backoff, :retry_exceptions,
57
+
58
+ def initialize
59
+ @retry_backoff = 2
60
+ @retry_exceptions = Faraday::Retry::Middleware::DEFAULT_EXCEPTIONS + [Faraday::ConnectionFailed]
61
+ @retry_interval = 1
62
+ @retry_max = 5
63
+ @retry_randomness = 0.5
64
+ end
65
+
66
+ def client
67
+ @client ||= Client.new(
68
+ retry_max: retry_max,
69
+ retry_interval: retry_interval,
70
+ retry_randomness: retry_randomness,
71
+ retry_backoff: retry_backoff,
72
+ retry_exceptions: retry_exceptions,
73
+ url: url
74
+ )
75
+ end
76
+ end
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Defines the module SupportOps.
4
+ module SupportOps
5
+ # Defines the module Slack
6
+ module Slack
7
+ ##
8
+ # Defines the class Messages within the module {SupportOps::Slack}.
9
+ #
10
+ # @author Jason Colyer
11
+ # @since 1.0.0
12
+ # @attr [String] text The text to send
13
+ class Messages < SupportOps::Slack::Base
14
+ # @!parse
15
+ # # Create a Message (i.e. post a message)
16
+ # #
17
+ # # @author Jason Colyer
18
+ # # @since 1.0.0
19
+ # # @note This is inherited from {SupportOps::Slack::Base#save!}
20
+ # # @example
21
+ # # require 'support_ops_slack'
22
+ # #
23
+ # # SupportOps::Slack::Configuration.configure do |config|
24
+ # # config.url = ENV.fetch('SLACK_URL')
25
+ # # end
26
+ # #
27
+ # # new_message = SupportOps::Slack::Messages.new
28
+ # # new_message.text = 'This is a test'
29
+ # # new_message.save!
30
+ # def save!; end
31
+ define_attributes :text
32
+ readonly_attributes :text
33
+
34
+ private
35
+
36
+ ##
37
+ # @private
38
+ def create_record
39
+ data = { text: self.text }.to_json
40
+ response = client.connection.post('', data)
41
+ raise "Unable to create message => #{response.body}" unless response.status == 200
42
+ true
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Defines the module SupportOps.
4
+ module SupportOps
5
+ ##
6
+ # Defines the module Slack within the module {SupportOps}.
7
+ #
8
+ # @author Jason Colyer
9
+ # @since 1.0.0
10
+ module Slack
11
+ # This one should always be first
12
+ require "#{__dir__}/slack/base"
13
+ # Order does not matter here
14
+ require "#{__dir__}/slack/client"
15
+ require "#{__dir__}/slack/configuration"
16
+ require "#{__dir__}/slack/messages"
17
+ end
18
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ $VERBOSE = nil
4
+
5
+ ##
6
+ # Defines the module SupportOps
7
+ # @author Jason Colyer
8
+ # @since 1.0.0
9
+ module SupportOps; end
10
+
11
+ require 'active_support'
12
+ require 'active_support/time'
13
+ require 'base64'
14
+ require 'cgi'
15
+ require 'digest'
16
+ require 'erb'
17
+ require 'faraday'
18
+ require 'faraday/multipart'
19
+ require 'faraday/retry'
20
+ require 'json'
21
+ require 'oj'
22
+ require 'restforce'
23
+ require 'yaml'
24
+
25
+ # This one should always be first
26
+
27
+ # Order does not matter here
28
+ require "#{__dir__}/support_ops_slack/slack"
metadata ADDED
@@ -0,0 +1,92 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gitlab-customer-support-operations_slack
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Jason Colyer
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2025-07-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 2.11.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 2.11.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday-multipart
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 1.0.4
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 1.0.4
41
+ - !ruby/object:Gem::Dependency
42
+ name: faraday-retry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 2.2.1
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 2.2.1
55
+ description: Slack gem of GitLab Customer Support Operations
56
+ email:
57
+ executables: []
58
+ extensions: []
59
+ extra_rdoc_files: []
60
+ files:
61
+ - lib/support_ops_slack.rb
62
+ - lib/support_ops_slack/slack.rb
63
+ - lib/support_ops_slack/slack/base.rb
64
+ - lib/support_ops_slack/slack/client.rb
65
+ - lib/support_ops_slack/slack/configuration.rb
66
+ - lib/support_ops_slack/slack/messages.rb
67
+ homepage: https://gitlab.com/reyloc/gitlab-customer-support-operations_slack
68
+ licenses:
69
+ - MIT
70
+ metadata:
71
+ bug_tracker_uri: https://gitlab.com/reyloc/gitlab-customer-support-operations_slack/-/issues
72
+ documentation_uri: https://reyloc.gitlab.io/gitlab-customer-support-operations_slack/
73
+ post_install_message:
74
+ rdoc_options: []
75
+ require_paths:
76
+ - lib
77
+ required_ruby_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - '='
80
+ - !ruby/object:Gem::Version
81
+ version: 3.2.2
82
+ required_rubygems_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ requirements: []
88
+ rubygems_version: 3.4.22
89
+ signing_key:
90
+ specification_version: 4
91
+ summary: GitLab Customer Support Operations > Slack
92
+ test_files: []