spaceship/lib/spaceship/tunes/app_ratings.rb in fastlane-2.37.0.beta.20170601010043 vs spaceship/lib/spaceship/tunes/app_ratings.rb in fastlane-2.37.0.beta.20170602010027

- old
+ new

@@ -4,51 +4,47 @@ class AppRatings < TunesBase # @return (Spaceship::Tunes::Application) A reference to the application # this version is for attr_accessor :application - # @return (Spaceship::Tunes::AppRatingSummary) A summary of the overall ratings for the application - attr_accessor :rating_summary + # @return (Integer) total number of ratings recevied + attr_accessor :rating_count - # @return (Hash) mapping country codes to a (Spaceship::Tunes::AppRatingSummary) summary of ratings for that country - attr_reader :store_fronts + # @return (Integer) total number of one star ratings recevied + attr_accessor :one_star_rating_count - # @return (Hash) of iTunesConnect version id's to readable version numbers - attr_reader :versions + # @return (Integer) total number of two star ratings recevied + attr_accessor :two_star_rating_count - attr_mapping({ - 'versions' => :versions - }) + # @return (Integer) total number of three star ratings recevied + attr_accessor :three_star_rating_count - class << self - # Create a new object based on a hash. - # This is used to create a new object based on the server response. - def factory(attrs) - obj = self.new(attrs) + # @return (Integer) total number of four star ratings recevied + attr_accessor :four_star_rating_count - obj.unfold_rating_summary(attrs['ratings']) - obj.unfold_store_fronts(attrs['storeFronts']) + # @return (Integer) total number of five star ratings recevied + attr_accessor :five_star_rating_count - return obj - end - end + attr_mapping({ + 'reviewCount' => :review_count, + 'ratingCount' => :rating_count, + 'ratingOneCount' => :one_star_rating_count, + 'ratingTwoCount' => :two_star_rating_count, + 'ratingThreeCount' => :three_star_rating_count, + 'ratingFourCount' => :four_star_rating_count, + 'ratingFiveCount' => :five_star_rating_count + }) - def unfold_rating_summary(attrs) - unfolded_rating_summary = AppRatingSummary.new(attrs) - instance_variable_set(:@rating_summary, unfolded_rating_summary) + # @return (Float) the average rating for this summary (rounded to 2 decimal places) + def average_rating + ((one_star_rating_count + + (two_star_rating_count * 2) + + (three_star_rating_count * 3) + + (four_star_rating_count * 4) + + (five_star_rating_count * 5)) / rating_count.to_f).round(2) end - def unfold_store_fronts(attrs) - unfolded_store_fronts = {} - - attrs.each do |info| - unfolded_store_fronts[info['countryCode']] = AppRatingSummary.new(info['ratings']) - end - - instance_variable_set(:@store_fronts, unfolded_store_fronts) - end - # @return (Array) of Review Objects def reviews(store_front, versionId = '') raw_reviews = client.get_reviews(application.apple_id, application.platform, store_front, versionId) raw_reviews.map do |review| review["value"]["application"] = self.application @@ -120,51 +116,9 @@ end def responded? return true if raw_developer_response false - end - end - - class AppRatingSummary < TunesBase - # @return (Integer) total number of reviews recevied - attr_reader :review_count - - # @return (Integer) total number of ratings recevied - attr_reader :rating_count - - # @return (Integer) total number of one star ratings recevied - attr_reader :one_star_rating_count - - # @return (Integer) total number of two star ratings recevied - attr_reader :two_star_rating_count - - # @return (Integer) total number of three star ratings recevied - attr_reader :three_star_rating_count - - # @return (Integer) total number of four star ratings recevied - attr_reader :four_star_rating_count - - # @return (Integer) total number of five star ratings recevied - attr_reader :five_star_rating_count - - attr_mapping({ - 'reviewCount' => :review_count, - 'ratingCount' => :rating_count, - 'ratingOneCount' => :one_star_rating_count, - 'ratingTwoCount' => :two_star_rating_count, - 'ratingThreeCount' => :three_star_rating_count, - 'ratingFourCount' => :four_star_rating_count, - 'ratingFiveCount' => :five_star_rating_count - }) - - # @return (Float) the average rating for this summary (rounded to 2 decimal places) - def average_rating - ((self.one_star_rating_count + - (self.two_star_rating_count * 2) + - (self.three_star_rating_count * 3) + - (self.four_star_rating_count * 4) + - (self.five_star_rating_count * 5)) / self.rating_count.to_f).round(2) end end end end