immosquare-slack 0.1.2 → 0.1.4
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 +4 -4
 - data/lib/immosquare-slack/channel.rb +27 -20
 - data/lib/immosquare-slack/shared_methods.rb +3 -0
 - data/lib/immosquare-slack/version.rb +1 -1
 - metadata +2 -2
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 106e9053feb1cdfe92a719e3be1346a9c98c28ae19a8d79819e0cc620537649d
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 9aba643342384868d859d7112dc4ff71d3179e0d9d3a5e7bc029c212229f137a
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 28261195cc6fb873c5998edede356390ed49f8415b7eabacf66c4df812d75a51e601930d762bde87e0402eb7eeb6d68a521a1ba37e193d01b8957e2d39ae1628
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 9a4a2a88aaa7d367cc5688fd92b6895ef7f25c14002be4faa66e07d17956ac15e88f26b39ed356af600903cedd9f95e4b46e5b2aa846a9aaba9b28f05143799e
         
     | 
| 
         @@ -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 
     | 
| 
       21 
     | 
    
         
            -
                     
     | 
| 
      
 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 
     | 
| 
       25 
     | 
    
         
            -
                      :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,25 +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 = 
     | 
| 
       57 
     | 
    
         
            -
             
     | 
| 
       58 
     | 
    
         
            -
             
     | 
| 
       59 
     | 
    
         
            -
             
     | 
| 
       60 
     | 
    
         
            -
             
     | 
| 
       61 
     | 
    
         
            -
             
     | 
| 
       62 
     | 
    
         
            -
             
     | 
| 
       63 
     | 
    
         
            -
             
     | 
| 
       64 
     | 
    
         
            -
             
     | 
| 
       65 
     | 
    
         
            -
             
     | 
| 
       66 
     | 
    
         
            -
             
     | 
| 
       67 
     | 
    
         
            -
             
     | 
| 
       68 
     | 
    
         
            -
             
     | 
| 
       69 
     | 
    
         
            -
             
     | 
| 
      
 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
         
     | 
| 
       70 
77 
     | 
    
         | 
| 
       71 
78 
     | 
    
         | 
| 
       72 
     | 
    
         
            -
                    "#{text} #{final}\n" if final. 
     | 
| 
      
 79 
     | 
    
         
            +
                    "#{text} #{final}\n" if !final.to_s.empty?
         
     | 
| 
       73 
80 
     | 
    
         
             
                  end
         
     | 
| 
       74 
81 
     | 
    
         | 
| 
       75 
82 
     | 
    
         
             
                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. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.1.4
         
     | 
| 
       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 
     | 
    
         
            +
            date: 2023-12-12 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: httparty
         
     |