Class: SlackProcessor
- Defined in:
- lib/Processors/SlackProcessor.rb
Defined Under Namespace
Classes: Payload
Instance Attribute Summary collapse
-
#botToken ⇒ Object
Returns the value of attribute botToken.
-
#inCommingWebHookURL ⇒ Object
Returns the value of attribute inCommingWebHookURL.
-
#targetChannel ⇒ Object
Returns the value of attribute targetChannel.
-
#timeZoneOffset ⇒ Object
Returns the value of attribute timeZoneOffset.
Attributes inherited from Processor
#baseExecutePath, #config, #configFilePath
Instance Method Summary collapse
-
#initialize(config, configFilePath, baseExecutePath) ⇒ SlackProcessor
constructor
A new instance of SlackProcessor.
- #processReviews(reviews, platform) ⇒ Object
- #sendWelcomMessage(platform) ⇒ Object
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
#botToken ⇒ Object
Returns the value of attribute botToken.
12 13 14 |
# File 'lib/Processors/SlackProcessor.rb', line 12 def botToken @botToken end |
#inCommingWebHookURL ⇒ Object
Returns the value of attribute inCommingWebHookURL.
12 13 14 |
# File 'lib/Processors/SlackProcessor.rb', line 12 def inCommingWebHookURL @inCommingWebHookURL end |
#targetChannel ⇒ Object
Returns the value of attribute targetChannel.
12 13 14 |
# File 'lib/Processors/SlackProcessor.rb', line 12 def targetChannel @targetChannel end |
#timeZoneOffset ⇒ Object
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. = [] reviewGroup.each do |review| = Payload::Attachment.new() stars = "★" * review. + "☆" * (5 - review.) color = review. >= 4 ? "good" : (review. > 2 ? "warning" : "danger") date = Time.at(review.createdDateTimestamp).getlocal(timeZoneOffset) title = "#{stars}" if !review.title.nil? title = "#{review.title} - #{stars}" end .color = color . = review.userName .fallback = title .title = title .text = review.body . = "#{platform} - #{review.platform} - #{review.appVersion} - #{review.territory} - <#{review.url}|#{date}>" payload..append() 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. = [] = Payload::Attachment.new() title = "ZReviewTender Standing By :astronaut:" body = "#{platform} Init Success!, will resend App Review to this channel automatically." .color = "good" . = "ZhgChgLi" .fallback = title .title = title .text = body . = "<https://github.com/ZhgChgLi/ZReviewTender|ZReviewTender>, <https://github.com/ZhgChgLi/ZReviewTender/issues|Report an issue>, Powered by <https://zhgchg.li|ZhgChgLi>." payload..append() request(payload) end |