class Ruboty::AppAnnie::Actions::ListRanks

Public Instance Methods

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

  case
  when !exists_ranks?
    return true
  else
    list_ranks
  end
end

Private Instance Methods

account() click to toggle source
# File lib/ruboty/app_annie/actions/list_ranks.rb, line 51
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_ranks.rb, line 70
def android_string
  ENV["APP_ANNIE_ANDROID_STRING"] || "Android:"
end
exists_ranks?() click to toggle source
# File lib/ruboty/app_annie/actions/list_ranks.rb, line 18
def exists_ranks?
  !ranks.empty?
end
given_category() click to toggle source
# File lib/ruboty/app_annie/actions/list_ranks.rb, line 105
def given_category
  message[:category]
end
given_country() click to toggle source
# File lib/ruboty/app_annie/actions/list_ranks.rb, line 101
def given_country
  message[:country]
end
given_days_ago() click to toggle source
# File lib/ruboty/app_annie/actions/list_ranks.rb, line 97
def given_days_ago
  message[:days_ago]
end
given_end_date() click to toggle source
# File lib/ruboty/app_annie/actions/list_ranks.rb, line 93
def given_end_date
  @end_date ||= message[:end_date]
end
given_feed() click to toggle source
# File lib/ruboty/app_annie/actions/list_ranks.rb, line 85
def given_feed
  message[:feed]
end
given_market() click to toggle source
# File lib/ruboty/app_annie/actions/list_ranks.rb, line 81
def given_market
  message[:market]
end
given_start_date() click to toggle source
# File lib/ruboty/app_annie/actions/list_ranks.rb, line 89
def given_start_date
  @start_date ||= message[:start_date]
end
initialize_date_conditions() click to toggle source
# File lib/ruboty/app_annie/actions/list_ranks.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_ranks.rb, line 66
def ios_string
  ENV["APP_ANNIE_IOS_STRING"] || "iOS:"
end
list_ranks() click to toggle source
# File lib/ruboty/app_annie/actions/list_ranks.rb, line 22
def list_ranks
  message.reply(ranks.join("\n"))
end
market() click to toggle source
# File lib/ruboty/app_annie/actions/list_ranks.rb, line 74
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_ranks.rb, line 59
def market_string(market)
  case market
  when "ios" then ios_string
  when "google-play" then android_string
  end
end
product(product_id) click to toggle source
# File lib/ruboty/app_annie/actions/list_ranks.rb, line 55
def product(product_id)
  client.product_details(market, product_id).body.product
end
product_ranks(product_id, product_name) click to toggle source
# File lib/ruboty/app_annie/actions/list_ranks.rb, line 42
def product_ranks(product_id, product_name)
  response = client.product_ranks(market, product_id, given_start_date, given_end_date, given_country, given_category, given_feed).body.product_ranks
  return if response.empty?

  response.first.ranks.map do |key, value|
    "#{market_string(market)} #{key} #{value} #{product_name}"
  end
end
ranks() click to toggle source
# File lib/ruboty/app_annie/actions/list_ranks.rb, line 33
def ranks
  reply_ranks = []
  client.products(account.account_id).body.products.select{ |p| p.status }.map do |p|
    reply_rank = product_ranks(p.product_id, p.product_name)
    reply_ranks << reply_rank unless reply_rank.nil?
  end
  reply_ranks
end