Class: GoogleSheetProcessor
- Defined in:
- lib/Processors/GoogleSheetProcessor.rb
Instance Attribute Summary collapse
-
#formatValues ⇒ Object
Returns the value of attribute formatValues.
-
#googleAPI ⇒ Object
Returns the value of attribute googleAPI.
-
#keywordsInclude ⇒ Object
Returns the value of attribute keywordsInclude.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#ratingsInclude ⇒ Object
Returns the value of attribute ratingsInclude.
-
#sheetID ⇒ Object
Returns the value of attribute sheetID.
-
#sheetName ⇒ Object
Returns the value of attribute sheetName.
-
#territoriesInclude ⇒ Object
Returns the value of attribute territoriesInclude.
-
#timeZoneOffset ⇒ Object
Returns the value of attribute timeZoneOffset.
Attributes inherited from Processor
#baseExecutePath, #config, #configFilePath
Instance Method Summary collapse
-
#initialize(config, configFilePath, baseExecutePath) ⇒ GoogleSheetProcessor
constructor
A new instance of GoogleSheetProcessor.
- #processReviews(reviews, platform) ⇒ Object
Constructor Details
#initialize(config, configFilePath, baseExecutePath) ⇒ GoogleSheetProcessor
Returns a new instance of GoogleSheetProcessor.
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 47 48 49 50 51 52 |
# File 'lib/Processors/GoogleSheetProcessor.rb', line 13 def initialize(config, configFilePath, baseExecutePath) @config = config @configFilePath = configFilePath @baseExecutePath = baseExecutePath @logger = ZLogger.new(baseExecutePath) keyFilePath = Helper.unwrapRequiredParameter(config, "googleSheetAPIKeyFilePath") if Pathname.new(keyFilePath).absolute? configDir = File.dirname(configFilePath) keyFilePath = "#{configDir}#{keyFilePath}" end @googleAPI = GoogleAPI.new(keyFilePath, baseExecutePath, ["https://www.googleapis.com/auth/drive", "https://www.googleapis.com/auth/drive.file", "https://www.googleapis.com/auth/spreadsheets"]) @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 @timeZoneOffset = Helper.unwrapRequiredParameter(config, "googleSheetTimeZoneOffset") @sheetID = Helper.unwrapRequiredParameter(config, "googleSheetID") @sheetName = Helper.unwrapRequiredParameter(config, "googleSheetName") @formatValues = [] if !config["values"].nil? @formatValues = config["values"] end puts "[GoogleSheetProcessor] Init Success." end |
Instance Attribute Details
#formatValues ⇒ Object
Returns the value of attribute formatValues.
11 12 13 |
# File 'lib/Processors/GoogleSheetProcessor.rb', line 11 def formatValues @formatValues end |
#googleAPI ⇒ Object
Returns the value of attribute googleAPI.
11 12 13 |
# File 'lib/Processors/GoogleSheetProcessor.rb', line 11 def googleAPI @googleAPI end |
#keywordsInclude ⇒ Object
Returns the value of attribute keywordsInclude.
11 12 13 |
# File 'lib/Processors/GoogleSheetProcessor.rb', line 11 def keywordsInclude @keywordsInclude end |
#logger ⇒ Object
Returns the value of attribute logger.
11 12 13 |
# File 'lib/Processors/GoogleSheetProcessor.rb', line 11 def logger @logger end |
#ratingsInclude ⇒ Object
Returns the value of attribute ratingsInclude.
11 12 13 |
# File 'lib/Processors/GoogleSheetProcessor.rb', line 11 def @ratingsInclude end |
#sheetID ⇒ Object
Returns the value of attribute sheetID.
11 12 13 |
# File 'lib/Processors/GoogleSheetProcessor.rb', line 11 def sheetID @sheetID end |
#sheetName ⇒ Object
Returns the value of attribute sheetName.
11 12 13 |
# File 'lib/Processors/GoogleSheetProcessor.rb', line 11 def sheetName @sheetName end |
#territoriesInclude ⇒ Object
Returns the value of attribute territoriesInclude.
11 12 13 |
# File 'lib/Processors/GoogleSheetProcessor.rb', line 11 def territoriesInclude @territoriesInclude end |
#timeZoneOffset ⇒ Object
Returns the value of attribute timeZoneOffset.
11 12 13 |
# File 'lib/Processors/GoogleSheetProcessor.rb', line 11 def timeZoneOffset @timeZoneOffset end |
Instance Method Details
#processReviews(reviews, platform) ⇒ Object
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 99 100 101 102 103 104 105 |
# File 'lib/Processors/GoogleSheetProcessor.rb', line 54 def processReviews(reviews, platform) if reviews.length < 1 return reviews end filterReviews = reviews if .length > 0 filterReviews = filterReviews.select{ |review| .map{ || .to_i }.include? review. } 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 values = [] filterReviews.each do |review| cols = [] formatValues.each do |formatValue| formatValue = formatValue.gsub("%TITLE%", review.title || "") formatValue = formatValue.gsub("%BODY%", review.body || "") formatValue = formatValue.gsub("%RATING%", review..nil? ? "" :review..to_s) formatValue = formatValue.gsub("%PLATFORM%", review.platform || "") formatValue = formatValue.gsub("%ID%", review.id || "") formatValue = formatValue.gsub("%USERNAME%", review.userName || "") formatValue = formatValue.gsub("%URL%", review.url || "") formatValue = formatValue.gsub("%TERRITORY%", review.territory || "") formatValue = formatValue.gsub("%APPVERSION%", review.appVersion || "") formatValue = formatValue.gsub("%CREATEDDATE%", review.createdDateTimestamp.nil? ? "" : Time.at(review.createdDateTimestamp).getlocal(timeZoneOffset).to_s) cols.append(formatValue) end values.append(cols) end page = 1 limit = 500 values.each_slice(limit) do |value| puts "[GoogleSheetProcessor] Insert rows(#{page}/#{(values.length/limit).ceil + 1}) to #{sheetID}-#{sheetName}" page += 1 googleAPI.request("https://sheets.googleapis.com/v4/spreadsheets/#{sheetID}/values/#{sheetName}!A1:append?valueInputOption=RAW", "POST", {:values => value}) end return reviews end |