class Ruboty::AppAnnie::Actions::ListReviews

Public Instance Methods

call() click to toggle source
# File lib/ruboty/app_annie/actions/list_reviews.rb, line 5
def call
  initialize_date_conditions

  case
  when !exists_reviews?
    return true
  else
    list_reviews
  end
end

Private Instance Methods

account() click to toggle source
# File lib/ruboty/app_annie/actions/list_reviews.rb, line 52
def account
  client.accounts.body.accounts.select { |a| a.market == market }.first
end
android_string() click to toggle source
# File lib/ruboty/app_annie/actions/list_reviews.rb, line 71
def android_string
  ENV["APP_ANNIE_ANDROID_STRING"] || "Android:"
end
exists_reviews?() click to toggle source
# File lib/ruboty/app_annie/actions/list_reviews.rb, line 18
def exists_reviews?
  !reviews.empty?
end
given_country() click to toggle source
# File lib/ruboty/app_annie/actions/list_reviews.rb, line 124
def given_country
  message[:country]
end
given_days_ago() click to toggle source
# File lib/ruboty/app_annie/actions/list_reviews.rb, line 120
def given_days_ago
  message[:days_ago]
end
given_end_date() click to toggle source
# File lib/ruboty/app_annie/actions/list_reviews.rb, line 116
def given_end_date
  @end_date ||= message[:end_date]
end
given_market() click to toggle source
# File lib/ruboty/app_annie/actions/list_reviews.rb, line 102
def given_market
  message[:market]
end
given_product_id() click to toggle source
# File lib/ruboty/app_annie/actions/list_reviews.rb, line 106
def given_product_id
  message[:product_id]
rescue IndexError
  nil
end
given_start_date() click to toggle source
# File lib/ruboty/app_annie/actions/list_reviews.rb, line 112
def given_start_date
  @start_date ||= message[:start_date]
end
initialize_date_conditions() click to toggle source
# File lib/ruboty/app_annie/actions/list_reviews.rb, line 26
def initialize_date_conditions
  days_ago = Date.today.ago(given_days_ago.to_i.days).to_date.to_s
  @start_date = days_ago
  @end_date = days_ago
rescue IndexError
end
ios_string() click to toggle source
# File lib/ruboty/app_annie/actions/list_reviews.rb, line 67
def ios_string
  ENV["APP_ANNIE_IOS_STRING"] || "iOS:"
end
list_reviews() click to toggle source
# File lib/ruboty/app_annie/actions/list_reviews.rb, line 22
def list_reviews
  message.reply(reviews.join("\n\n"))
end
market() click to toggle source
# File lib/ruboty/app_annie/actions/list_reviews.rb, line 95
def market
  case given_market
  when "ios" then "ios"
  when "android" then "google-play"
  end
end
market_string(market) click to toggle source
# File lib/ruboty/app_annie/actions/list_reviews.rb, line 60
def market_string(market)
  case market
  when "ios" then ios_string
  when "google-play" then android_string
  end
end
negative_star_string() click to toggle source
# File lib/ruboty/app_annie/actions/list_reviews.rb, line 87
def negative_star_string
  ENV["APP_ANNIE_NEGATIVE_STAR_STRING"] || "☆"
end
positive_star_string() click to toggle source
# File lib/ruboty/app_annie/actions/list_reviews.rb, line 83
def positive_star_string
  ENV["APP_ANNIE_POSITIVE_STAR_STRING"] || "★"
end
product(product_id) click to toggle source
# File lib/ruboty/app_annie/actions/list_reviews.rb, line 56
def product(product_id)
  client.product_details(market, product_id).body.product
end
product_reviews(product_id, product_name) click to toggle source
# File lib/ruboty/app_annie/actions/list_reviews.rb, line 46
def product_reviews(product_id, product_name)
  client.product_reviews(market, product_id, given_start_date, given_end_date, given_country).body.reviews.map do |review|
    "#{market_string(market)} #{product_name} #{version_string(review)}\n" + "> #{rating_string(review)}#{title_string(review)}\n" + "> ```#{review.text}```"
  end
end
rating_string(review) click to toggle source
# File lib/ruboty/app_annie/actions/list_reviews.rb, line 79
def rating_string(review)
  (positive_star_string * review.rating) + (negative_star_string * (5 - review.rating))
end
reviews() click to toggle source
# File lib/ruboty/app_annie/actions/list_reviews.rb, line 33
def reviews
  reply_reviews = []
  if given_product_id.nil?
    client.products(account.account_id).body.products.select{ |p| p.status }.map do |p|
      reply_reviews << product_reviews(p.product_id, p.product_name)
    end
  else
    product = product(given_product_id)
    reply_reviews = product_reviews(product.product_id, product.product_name)
  end
  reply_reviews
end
title_string(review) click to toggle source
# File lib/ruboty/app_annie/actions/list_reviews.rb, line 91
def title_string(review)
  review.title.nil? ? "" : " / *#{review.title}*"
end
version_string(review) click to toggle source
# File lib/ruboty/app_annie/actions/list_reviews.rb, line 75
def version_string(review)
  review.version.nil? ? "" : "- v#{review.version}"
end