ZReviewTender 0.0.5 → 0.0.6

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: 4905d8141a111bf59431bb91ae97e09b7a1b1d55c311c0ccda08b3ef0c9b6fc8
4
- data.tar.gz: 346a8c5be0271f0be78bcfa0947333f7e2283988785d3ade883799fae38ed205
3
+ metadata.gz: 2807fe3efdfb17de59b50713359ba58097f36482389f1d4089056103d16be154
4
+ data.tar.gz: 8366edb466dda73e67a553084b7b96e97f42c03e4cdb8dc2509e2edacd2f1d3b
5
5
  SHA512:
6
- metadata.gz: b4a3eba5f67873c14d40bf96ec20820a2ba4e985722f42132b1983bfa60b40eb475088be78c958d13e2c1be43bd03b8965509efcafb5adc01757333d0d44720a
7
- data.tar.gz: db5d1acb0233c84fe06dbcb654dbda40ee97b25eb85f52d74dfd77ea7f34779f072ca25c4d2367b5500bf780a0ffbc5e49d7b8b592012e9f92387b96d032acc8
6
+ metadata.gz: 6eb36009c81955c741701b5c57559d67a16c1fd7df2528b2893ceae37f40c00879d81d8a6a65d4eae930d6125b2f33492f966837ed440acd15d56e42a631c378
7
+ data.tar.gz: 108d45d065e7f045a5bb88c72fe8e8e79b132f5bb42cdb7e9f00191a4b660e3ff726f4027d79889e5b0d0c67975cf56c02494754449641774f5107b2fb1ed96b
@@ -9,7 +9,7 @@ require "time"
9
9
 
10
10
  class SlackProcessor < Processor
11
11
 
12
- attr_accessor :botToken, :inCommingWebHookURL, :targetChannel, :timeZoneOffset
12
+ attr_accessor :botToken, :inCommingWebHookURL, :targetChannel, :timeZoneOffset, :attachmentGroupByNumber
13
13
 
14
14
  def initialize(config, configFilePath, baseExecutePath)
15
15
  @config = config
@@ -20,6 +20,11 @@ class SlackProcessor < Processor
20
20
  @inCommingWebHookURL = config["slackInCommingWebHookURL"]
21
21
  @targetChannel = config["slackBotTargetChannel"]
22
22
  @timeZoneOffset = Helper.unwrapRequiredParameter(config, "slackTimeZoneOffset")
23
+ @attachmentGroupByNumber = 1
24
+
25
+ if !config['slackAttachmentGroupByNumber'].nil? && config['slackAttachmentGroupByNumber'] != "" && config['slackAttachmentGroupByNumber'].to_i > 0 && config['slackAttachmentGroupByNumber'].to_i < 100
26
+ @attachmentGroupByNumber = config['slackAttachmentGroupByNumber'].to_i
27
+ end
23
28
 
24
29
  if (botToken.nil? && inCommingWebHookURL.nil?) || (botToken == "" && inCommingWebHookURL == "")
25
30
  raise "must specify slackBotToken or slackInCommingWebHookURL in SlackProcessor."
@@ -30,35 +35,51 @@ class SlackProcessor < Processor
30
35
 
31
36
  def processReviews(reviews, platform)
32
37
 
33
- # 1 review 1 message
34
- reviews.each do |review|
38
+ pendingPayloads = []
39
+
40
+ # Slack Message Limit: posting one message per second per channel
41
+ reviews.each_slice(attachmentGroupByNumber) do |reviewGroup|
35
42
  payload = Payload.new()
36
43
  payload.attachments = []
37
-
38
- attachment = Payload::Attachment.new()
39
44
 
40
- stars = "★" * review.rating + "☆" * (5 - review.rating)
41
- color = review.rating >= 4 ? "good" : (review.rating > 2 ? "warning" : "danger")
42
- date = Time.at(review.createdDateTimestamp).getlocal(timeZoneOffset)
43
-
44
- title = "#{stars}"
45
- if !review.title.nil?
46
- title = "#{review.title} - #{stars}"
47
- end
45
+ reviewGroup.each do |review|
46
+ attachment = Payload::Attachment.new()
47
+
48
+ stars = "★" * review.rating + "☆" * (5 - review.rating)
49
+ color = review.rating >= 4 ? "good" : (review.rating > 2 ? "warning" : "danger")
50
+ date = Time.at(review.createdDateTimestamp).getlocal(timeZoneOffset)
48
51
 
49
- attachment.color = color
50
- attachment.author_name = review.userName
51
- attachment.fallback = title
52
- attachment.title = title
53
- attachment.text = review.body
54
- attachment.footer = "#{platform} - #{review.platform} - #{review.appVersion} - #{review.territory} - <#{review.url}|#{date}>"
55
-
56
- payload.attachments.append(attachment)
52
+ title = "#{stars}"
53
+ if !review.title.nil?
54
+ title = "#{review.title} - #{stars}"
55
+ end
56
+
57
+ attachment.color = color
58
+ attachment.author_name = review.userName
59
+ attachment.fallback = title
60
+ attachment.title = title
61
+ attachment.text = review.body
62
+ attachment.footer = "#{platform} - #{review.platform} - #{review.appVersion} - #{review.territory} - <#{review.url}|#{date}>"
63
+
64
+ payload.attachments.append(attachment)
65
+ end
66
+
67
+ pendingPayloads.append(payload)
68
+ end
69
+
70
+ loop do
71
+ payload = pendingPayloads.pop
57
72
 
58
73
  result = request(payload)
59
- if !result
74
+ if !result[:ok]
60
75
  Helper.logError(result)
76
+ if result[:message] == "ratelimited"
77
+ sleep(1)
78
+ pendingPayloads.append(payload)
79
+ end
61
80
  end
81
+
82
+ break if pendingPayloads.length < 1
62
83
  end
63
84
 
64
85
  return reviews
@@ -108,10 +129,10 @@ class SlackProcessor < Processor
108
129
  res = http.request(req)
109
130
 
110
131
  if isInCommingWebHook
111
- return res.body == "ok"
132
+ return {"ok":res.body == "ok", "message":nil}
112
133
  else
113
134
  result = JSON.parse(res.body)
114
- return result["ok"] == true
135
+ return {"ok":result["ok"] == true, "message":result['error']}
115
136
  end
116
137
 
117
138
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ZReviewTender
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - ZhgChgLi