Class: SlackAndAsanaConnector

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

Defined Under Namespace

Classes: Payload

Instance Attribute Summary collapse

Attributes inherited from Processor

#baseExecutePath, #config, #configFilePath

Instance Method Summary collapse

Methods inherited from Processor

#renderReview

Constructor Details

#initialize(config, configFilePath, baseExecutePath) ⇒ SlackAndAsanaConnector

Returns a new instance of SlackAndAsanaConnector.



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/Processors/SlackAndAsanaConnector.rb', line 13

def initialize(config, configFilePath, baseExecutePath)
    @config = config
    @configFilePath = configFilePath
    @baseExecutePath = baseExecutePath
    @logger = ZLogger.new(baseExecutePath)

    @asanaAPIURL = "https://app.asana.com/api/1.0"
    @asanaToken = Helper.unwrapRequiredParameter(config, "asanaToken")
    @slackBotToken = Helper.unwrapRequiredParameter(config, "slackBotToken")

    puts "[SlackAndAsanaConnector] Init Success."
end

Instance Attribute Details

#asanaAPIURLObject

Returns the value of attribute asanaAPIURL.



11
12
13
# File 'lib/Processors/SlackAndAsanaConnector.rb', line 11

def asanaAPIURL
  @asanaAPIURL
end

#asanaTokenObject

Returns the value of attribute asanaToken.



11
12
13
# File 'lib/Processors/SlackAndAsanaConnector.rb', line 11

def asanaToken
  @asanaToken
end

#loggerObject

Returns the value of attribute logger.



11
12
13
# File 'lib/Processors/SlackAndAsanaConnector.rb', line 11

def logger
  @logger
end

#projectIDObject

Returns the value of attribute projectID.



11
12
13
# File 'lib/Processors/SlackAndAsanaConnector.rb', line 11

def projectID
  @projectID
end

#slackBotTokenObject

Returns the value of attribute slackBotToken.



11
12
13
# File 'lib/Processors/SlackAndAsanaConnector.rb', line 11

def slackBotToken
  @slackBotToken
end

Instance Method Details

#processReviews(reviews, platform) ⇒ Object



26
27
28
29
30
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
66
67
68
69
70
71
72
# File 'lib/Processors/SlackAndAsanaConnector.rb', line 26

def processReviews(reviews, platform)        
    if reviews.length < 1
        return reviews
    end

    pendingReviews = reviews.dup

    loop do
        review = pendingReviews.shift

        result =  retrieveSlackMessage(review)
        if !result["ok"]
            if result["error"] == "ratelimited"
                puts "[SlackAndAsanaConnector] Reached Rate Limited, sleep 1 sec..."
                sleep(1)
                pendingReviews.insert(0, review)
            end
        else
            sendAsanaCommentMessage(review, "ref: #{result["permalink"]}")
        end

        puts "[SlackAndAsanaConnector] Connect Slack Message to Asana Task, rest: #{pendingReviews.length}"
        break if pendingReviews.length < 1
    end

    pendingReviews = reviews.dup

    loop do
        review = pendingReviews.shift
        asanaTaskURL = retrieveAsanaTaskURL(review)
        if !asanaTaskURL.nil?
            result =  sendSlackCommnetMessage(review, "<#{asanaTaskURL}| Go To *Asana Task*>")
            if !result["ok"]
                if result["error"] == "ratelimited"
                    puts "[SlackAndAsanaConnector] Reached Rate Limited, sleep 1 sec..."
                    sleep(1)
                    pendingReviews.insert(0, review)
                end
            end
        end

        puts "[SlackAndAsanaConnector] Connect Asana Task to Slack Message, rest: #{pendingReviews.length}"
        break if pendingReviews.length < 1
    end

    return reviews
end