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
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
|
# File 'lib/AndroidFetcher.rb', line 22
def execute()
latestCheckTimestamp = getPlatformLatestCheckTimestamp()
puts "[AndroidFetcher] Start execute(), latestCheckTimestamp: #{latestCheckTimestamp}"
reviews = []
reviewsInfoLink = "https://androidpublisher.googleapis.com/androidpublisher/v3/applications/#{config.packageName}/reviews"
puts "[AndroidFetcher] Fetch reviews in #{config.packageName}"
loop do
reviewsInfo = googleAPI.request(reviewsInfoLink)
reviewsInfoLink = reviewsInfo&.dig("tokenPagination", "nextPageToken")
customerReviews = reviewsInfo["reviews"]
if customerReviews.nil?
break
end
puts "[AndroidFetcher] Fetch reviews in #{config.packageName}, count: #{customerReviews.length}"
customerReviews.each do |customerReview|
customerReviewID = customerReview&.dig("reviewId")
customerReviewTitle = nil
customerReviewReviewerNickname = customerReview&.dig("authorName")
customerReviewVersionString = "unknown"
customerReviewPlatform = platform
customerReviewCreatedDateTimestamp = 0
= customerReview&.dig("comments", 0, "userComment")
if !.nil?
customerReviewBody = &.dig("text")
customerReviewTerritory = &.dig("reviewerLanguage")
if !customerReviewBody.nil?
customerReviewBody = customerReviewBody.strip
end
customerReviewRating = &.dig("starRating")
if !customerReviewRating.nil?
customerReviewRating = customerReviewRating.to_i
end
customerReviewCreatedDateTimestamp = &.dig("lastModified", "seconds")
if !customerReviewCreatedDateTimestamp.nil?
customerReviewCreatedDateTimestamp = customerReviewCreatedDateTimestamp.to_i
end
androidOSVersion = &.dig("androidOsVersion")
if !androidOSVersion.nil?
customerReviewPlatform = "#{platform} #{androidOSVersion}"
end
versionString = &.dig("appVersionName")
if !versionString.nil?
customerReviewVersionString = "#{versionString}"
versionCode = &.dig("appVersionCode")
if !versionCode.nil?
customerReviewVersionString = "#{customerReviewVersionString}(#{versionCode})"
end
end
deviceInfo = []
manufacturer = &.dig("deviceMetadata", "manufacturer")
if !manufacturer.nil?
deviceInfo.append(manufacturer)
end
productName = &.dig("deviceMetadata", "productName")
if !productName.nil?
deviceInfo.append(productName)
end
if deviceInfo.length > 0
customerReviewReviewerNickname = "#{customerReviewReviewerNickname} - #{deviceInfo.join("/")}"
end
end
if latestCheckTimestamp >= customerReviewCreatedDateTimestamp
reviewsInfoLink = nil
break
else
url = "https://play.google.com/store/apps/details?id=#{config.packageName}&reviewId=#{customerReviewID}"
if !config.accountID.nil? && !config.appID.nil?
url = "https://play.google.com/console/developers/#{config.accountID}/app/#{config.appID}/user-feedback/review-details?reviewId=#{customerReviewID}"
end
reviews.append(Review.new(customerReviewPlatform, customerReviewID, customerReviewReviewerNickname, customerReviewRating, customerReviewTitle, customerReviewBody, customerReviewCreatedDateTimestamp, url, customerReviewVersionString, customerReviewTerritory))
if latestCheckTimestamp == 0
reviewsInfoLink = nil
break
end
end
end
break if reviewsInfoLink.nil?
end
puts "[AndroidFetcher] Fetch reviews in #{config.packageName}, total reviews count: #{reviews.length}"
if reviews.length > 0
reviews = reviews.sort! { |a, b| a.createdDateTimestamp <=> b.createdDateTimestamp }
puts "[AndroidFetcher] latest review: #{reviews.last.body}, #{reviews.last.createdDateTimestamp}"
setPlatformLatestCheckTimestamp(reviews.last.createdDateTimestamp)
if latestCheckTimestamp == 0
sendWelcomMessage()
return
end
processReviews(reviews, platform)
end
end
|