immosquare-slack 0.1.1 → 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: d9b52f86dbd4ff1cc0d3ef59fb7c92921e73c8491907204123408c7712361f6a
4
- data.tar.gz: 7179ca47d7f1dbf1bfbbcbe0e16bf2f7f1d4993933c6e96bf79f20b5ac8a894c
3
+ metadata.gz: aa3bbd3b3a57145bcf994af26d5aecc034321ad8c65f5d10ef70011b25dc1399
4
+ data.tar.gz: 2f90ddfa14097c4b9bb06de7c17456d36d8e66cd8121d65a7f1932bcfacf572f
5
5
  SHA512:
6
- metadata.gz: cc6f01081f7afc0a15d95225b2415d4b65e634d6238502b08fe213b3c89e4246418cd82cb8e50c7dc0dfdfa82a70ac14b11b52b13745b8d99d4aa096e3af0b52
7
- data.tar.gz: 8a756f01c5487a449835110ba2a3b28cffdd5d21ebb9df36d787191e97f0acd1b8f2b1f601bf22736ff0d7b661cd35ca1c575fdbd102778034fdc08b86eaec98
6
+ metadata.gz: 555770a445c82bee6d56e3ff877889a9ff24884f977e7c99495d5b9883c319557c9af0957fdf2b20d32884bc91bb40596c8f054243d99173bdc49d1eb3342ef5
7
+ data.tar.gz: 7f8b11fa4d086bb0b29f3d82c6830a2fd24730a0daad4badd4a83f078dc0939f18d5731d75ce917e3d0c7e98412293c2787bc7d85823357335fe3693b349f4c9
@@ -17,14 +17,17 @@ module ImmosquareSlack
17
17
  channel_id = get_channel_id_by_name(channel_name)
18
18
  raise("Channel not found") if channel_id.nil?
19
19
 
20
- url = "https://slack.com/api/chat.postMessage"
21
- text = "#{build_notification_text(channel_id, notify, notify_text) if notify.present?}#{text}"
20
+ url = "https://slack.com/api/chat.postMessage"
21
+ notification_text = notify ? build_notification_text(channel_id, notify, notify_text) : nil
22
+ text = "#{notification_text}#{text}"
22
23
 
23
24
  body = {
24
- :channel => channel_id,
25
- :text => text,
26
- :username => bot_name.presence
25
+ :channel => channel_id,
26
+ :text => text
27
27
  }
28
+
29
+ body[:username] = bot_name if bot_name
30
+
28
31
  make_slack_api_call(url, :method => :post, :body => body)
29
32
  end
30
33
 
@@ -51,20 +54,29 @@ module ImmosquareSlack
51
54
  ##============================================================##
52
55
  ## Méthode récupérant les membres d'un channel et les notifier
53
56
  ## sur le message
57
+ ## on ne peut pas utilser in? si on veut que la gem soit
58
+ ## compatible avec ruby (sans rails)
59
+ ## pareil pour present?
54
60
  ##============================================================##
55
61
  def build_notification_text(channel_id, notify, text = "Hello")
56
- final = if notify.is_a?(Array)
57
- members = ImmosquareSlack::User.list_users
58
- members = members.select {|m| m["profile"]["email"].in?(notify) }
59
- members.map {|m| "<@#{m["id"]}>" }.join(", ")
60
- elsif notify.to_sym == :all
61
- members = get_channel_members(channel_id)
62
- members.map {|m| "<@#{m}>" }.join(", ")
63
- elsif notify.to_sym == :channel
64
- "@channel"
65
- end
62
+ final =
63
+ if notify.is_a?(Array)
64
+ members = ImmosquareSlack::User.list_users
65
+ members = members.select {|m| notify.include?(m["profile"]["email"]) }
66
+ members.map {|m| "<@#{m["id"]}>" }.join(", ")
67
+ elsif notify.to_sym == :all
68
+ members = get_channel_members(channel_id)
69
+ members.map {|m| "<@#{m}>" }.join(", ")
70
+ elsif notify.to_sym == :channel
71
+ "<!channel>"
72
+ elsif notify.to_sym == :here
73
+ "<!here>"
74
+ elsif notify.to_sym == :everyone
75
+ "<!everyone>"
76
+ end
77
+
66
78
 
67
- "#{text} #{final}\n" if final.present?
79
+ "#{text} #{final}\n" if !final.to_s.empty?
68
80
  end
69
81
 
70
82
  end
@@ -1,3 +1,6 @@
1
+ require "json"
2
+ require "httparty"
3
+
1
4
  module ImmosquareSlack
2
5
  module SharedMethods
3
6
  private
@@ -1,3 +1,3 @@
1
1
  module ImmosquareSlack
2
- VERSION = "0.1.1".freeze
2
+ VERSION = "0.1.3".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: immosquare-slack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - IMMO SQUARE
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-12-11 00:00:00.000000000 Z
11
+ date: 2023-12-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty