Class: AsanaProcessor

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

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) ⇒ AsanaProcessor

Returns a new instance of AsanaProcessor.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/Processors/AsanaProcessor.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"
    @token = Helper.unwrapRequiredParameter(config, "asanaToken")
    @projectID = Helper.unwrapRequiredParameter(config, "asanaProjectID")
    @taskTitleTemplate = Helper.unwrapRequiredParameter(config, "asanaTaskTitleTemplate")
    @taskBodyTemplate = Helper.unwrapRequiredParameter(config, "asanaTaskBodyTemplate")
    @timeZoneOffset = Helper.unwrapRequiredParameter(config, "asanaTimeZoneOffset")
    @sectionName = nil
    if !config["asanaSectionName"].nil? && config["asanaSectionName"] != ""
        @sectionName = config["asanaSectionName"].strip
    end

    @keywordsInclude = []
    if !config["keywordsInclude"].nil?
        @keywordsInclude = config["keywordsInclude"]
    end

    @ratingsInclude = []
    if !config["ratingsInclude"].nil?
        @ratingsInclude = config["ratingsInclude"]
    end

    @territoriesInclude = []
    if !config["territoriesInclude"].nil?
        @territoriesInclude = config["territoriesInclude"]
    end

    puts "[AsanaProcessor] Init Success."
end

Instance Attribute Details

#asanaAPIURLObject

Returns the value of attribute asanaAPIURL.



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

def asanaAPIURL
  @asanaAPIURL
end

#keywordsIncludeObject

Returns the value of attribute keywordsInclude.



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

def keywordsInclude
  @keywordsInclude
end

#loggerObject

Returns the value of attribute logger.



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

def logger
  @logger
end

#projectIDObject

Returns the value of attribute projectID.



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

def projectID
  @projectID
end

#ratingsIncludeObject

Returns the value of attribute ratingsInclude.



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

def ratingsInclude
  @ratingsInclude
end

#sectionNameObject

Returns the value of attribute sectionName.



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

def sectionName
  @sectionName
end

#taskBodyTemplateObject

Returns the value of attribute taskBodyTemplate.



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

def taskBodyTemplate
  @taskBodyTemplate
end

#taskTitleTemplateObject

Returns the value of attribute taskTitleTemplate.



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

def taskTitleTemplate
  @taskTitleTemplate
end

#territoriesIncludeObject

Returns the value of attribute territoriesInclude.



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

def territoriesInclude
  @territoriesInclude
end

#timeZoneOffsetObject

Returns the value of attribute timeZoneOffset.



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

def timeZoneOffset
  @timeZoneOffset
end

#tokenObject

Returns the value of attribute token.



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

def token
  @token
end

Instance Method Details

#processReviews(reviews, platform) ⇒ Object



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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/Processors/AsanaProcessor.rb', line 48

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

    sectionID = findSectionIDFromSectionName(sectionName)

    filterReviews = reviews
    
    if ratingsInclude.length > 0
        filterReviews = filterReviews.select{ |review| ratingsInclude.map{ |rating| rating.to_i }.include? review.rating }
    end

    if territoriesInclude.length > 0
        filterReviews = filterReviews.select{ |review| territoriesInclude.map{ |territory| territory.upcase }.include? review.territory.upcase }
    end

    if keywordsInclude.length > 0
        keywordsInclude.select{ |keywordsInclude| keywordsInclude != "" }.each do |keywordInclude|
            filterReviews = filterReviews.select{ |review| review.body.include? keywordInclude }
        end
    end

    filterReviews.each do |review|
        title = renderReview(taskTitleTemplate, review, timeZoneOffset)
        body = renderReview(taskBodyTemplate, review, timeZoneOffset)
        
        requestTaskData = {
            "name": title,
            "notes": body,
            "projects": [projectID.to_s]
        }

        if !review.createdDateTimestamp.nil?
            requestTaskData['due_at'] = Time.at(review.createdDateTimestamp).iso8601
        end

        taskData = asanaAPI("/tasks", "POST", requestTaskData)
        taskData = taskData["data"]

        review.tempData["asanaTaskGID"] = taskData["gid"]
        
        if !sectionID.nil? && !taskData.nil?
            asanaAPI("/sections/#{sectionID}/addTask", "POST", {"task": taskData["gid"]})
        end

        puts "[AsanaProcessor] Insert Review #{title} as a task to asana project."
    end

    return reviews
end