Class: SlackProcessor

Inherits:
Processor show all
Defined in:
lib/Processors/SlackProcessor.rb

Defined Under Namespace

Classes: Payload

Instance Attribute Summary collapse

Attributes inherited from Processor

#baseExecutePath, #config, #configFilePath

Instance Method Summary collapse

Constructor Details

#initialize(config, configFilePath, baseExecutePath) ⇒ SlackProcessor

Returns a new instance of SlackProcessor.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/Processors/SlackProcessor.rb', line 14

def initialize(config, configFilePath, baseExecutePath)
    @config = config
    @configFilePath = configFilePath
    @baseExecutePath = baseExecutePath

    @botToken = config["slackBotToken"]
    @inCommingWebHookURL = config["slackInCommingWebHookURL"]
    @targetChannel = config["slackBotTargetChannel"]
    @timeZoneOffset = Helper.unwrapRequiredParameter(config, "slackTimeZoneOffset")

    if (botToken.nil? && inCommingWebHookURL.nil?) || (botToken == "" && inCommingWebHookURL == "")
        raise "must specify slackBotToken or slackInCommingWebHookURL in SlackProcessor."
    elsif !botToken.nil? && botToken != "" && (targetChannel.nil? || targetChannel == "")
        raise "must specify slackBotTargetChannel in SlackProcessor."
    end
end

Instance Attribute Details

#botTokenObject

Returns the value of attribute botToken.



12
13
14
# File 'lib/Processors/SlackProcessor.rb', line 12

def botToken
  @botToken
end

#inCommingWebHookURLObject

Returns the value of attribute inCommingWebHookURL.



12
13
14
# File 'lib/Processors/SlackProcessor.rb', line 12

def inCommingWebHookURL
  @inCommingWebHookURL
end

#targetChannelObject

Returns the value of attribute targetChannel.



12
13
14
# File 'lib/Processors/SlackProcessor.rb', line 12

def targetChannel
  @targetChannel
end

#timeZoneOffsetObject

Returns the value of attribute timeZoneOffset.



12
13
14
# File 'lib/Processors/SlackProcessor.rb', line 12

def timeZoneOffset
  @timeZoneOffset
end

Instance Method Details

#processReviews(reviews, platform) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/Processors/SlackProcessor.rb', line 31

def processReviews(reviews, platform)
    reviews.each_slice(10) do |reviewGroup|
        payload = Payload.new()
        payload.attachments = []

        reviewGroup.each do |review|
            attachment = Payload::Attachment.new()

            stars = "★" * review.rating + "☆" * (5 - review.rating)
            color = review.rating >= 4 ? "good" : (review.rating > 2 ? "warning" : "danger")
            date = Time.at(review.createdDateTimestamp).getlocal(timeZoneOffset)
            
            title = "#{stars}"
            if !review.title.nil?
                title = "#{review.title} - #{stars}"
            end
                
            attachment.color = color
            attachment.author_name = review.userName
            attachment.fallback = title
            attachment.title = title
            attachment.text = review.body
            attachment.footer = "#{platform} - #{review.platform} - #{review.appVersion} - #{review.territory} - <#{review.url}|#{date}>"
            
            payload.attachments.append(attachment)
        end

        result = request(payload)
        if result["ok"] != true
            Helper.logError(result)
        end
    end

    return reviews
end

#sendWelcomMessage(platform) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/Processors/SlackProcessor.rb', line 67

def sendWelcomMessage(platform)
    payload = Payload.new()
    payload.attachments = []

    attachment = Payload::Attachment.new()
        
    title = "ZReviewTender Standing By :astronaut:"
    body = "#{platform} Init Success!, will resend App Review to this channel automatically."
    
    attachment.color = "good"
    attachment.author_name = "ZhgChgLi"
    attachment.fallback = title
    attachment.title = title
    attachment.text = body
    attachment.footer = "<https://github.com/ZhgChgLi/ZReviewTender|ZReviewTender>, <https://github.com/ZhgChgLi/ZReviewTender/issues|Report an issue>, Powered by <https://zhgchg.li|ZhgChgLi>."
    
    payload.attachments.append(attachment)

    request(payload)
end