lib/spaceship/tunes/app_version.rb in spaceship-0.9.1 vs lib/spaceship/tunes/app_version.rb in spaceship-0.10.0

- old
+ new

@@ -1,9 +1,10 @@ module Spaceship module Tunes # Represents an editable version of an iTunes Connect Application # This can either be the live or the edit version retrieved via the app + # rubocop:disable Metrics/ClassLength class AppVersion < TunesBase # @return (Spaceship::Tunes::Application) A reference to the application # this version is for attr_accessor :application @@ -171,40 +172,32 @@ # rubocop:enable Style/PredicateName # Call this method to make sure the given languages are available for this app # You should call this method before accessing the name, description and other localized values # This will create the new language if it's not available yet and do nothing if everything's there - # def create_languages!(languages) - # raise "Please pass an array" unless languages.kind_of?Array + # Important: Due to a bug you have to fetch the `edit_version` again, as it doesn't get refreshed immediately + def create_languages(languages) + languages = [languages] if languages.kind_of?(String) + raise "Please pass an array" unless languages.kind_of? Array - # copy_from = self.languages.first - # languages.each do |language| - # # First, see if it's already available - # found = self.languages.find do |local| - # local['language'] == language - # end + copy_from = self.languages.find { |a| a['language'] == 'en-US' } || self.languages.first - # unless found - # new_language = copy_from.dup - # new_language['language'] = language - # [:description, :releaseNotes, :keywords].each do |key| - # new_language[key.to_s]['value'] = nil - # end + languages.each do |language| + # First, see if it's already available + found = self.languages.find do |local| + local['language'] == language + end + next if found - # self.languages << new_language - # unfold_languages + new_language = copy_from.clone + new_language['language'] = language - # # Now we need to set a useless `pageLanguageValue` value because iTC says so, after adding a new version - # self.languages.each do |current| - # current['pageLanguageValue'] = current['language'] - # end - # end - # end + self.languages << new_language + end + nil + end - # languages - # end - # Returns an array of all builds that can be sent to review def candidate_builds res = client.candidate_builds(self.application.apple_id, self.version_id) builds = [] res.each do |attrs| @@ -222,13 +215,56 @@ raw_data.set(['preReleaseBuildTrainVersionString'], build.train_version) raw_data.set(['preReleaseBuildUploadDate'], build.upload_date) true end + # Set the age restriction rating + # Call it like this: + # v.update_rating({ + # 'CARTOON_FANTASY_VIOLENCE' => 0, + # 'MATURE_SUGGESTIVE' => 2, + # 'UNRESTRICTED_WEB_ACCESS' => 0, + # 'GAMBLING_CONTESTS' => 0 + # }) + # + # Available Values + # https://github.com/KrauseFx/deliver/blob/master/Reference.md + def update_rating(hash) + raise "Must be a hash" unless hash.kind_of?(Hash) + + hash.each do |key, value| + to_edit = self.raw_data['ratings']['nonBooleanDescriptors'].find do |current| + current['name'].include?(key) + end + + if to_edit + to_set = "NONE" if value == 0 + to_set = "INFREQUENT_MILD" if value == 1 + to_set = "FREQUENT_INTENSE" if value == 2 + raise "Invalid value '#{value}' for '#{key}', must be 0-2" unless to_set + to_edit['level'] = "ITC.apps.ratings.level.#{to_set}" + else + # Maybe it's a boolean descriptor? + to_edit = self.raw_data['ratings']['booleanDescriptors'].find do |current| + current['name'].include?(key) + end + + if to_edit + to_set = "NO" + to_set = "YES" if value.to_i > 0 + to_edit['level'] = "ITC.apps.ratings.level.#{to_set}" + else + raise "Could not find option '#{key}' in the list of available options" + end + end + end + true + end + # Push all changes that were made back to iTunes Connect def save! - client.update_app_version!(application.apple_id, is_live?, raw_data) + client.update_app_version!(application.apple_id, self.version_id, raw_data) end # @return (String) An URL to this specific resource. You can enter this URL into your browser def url url = "https://itunesconnect.apple.com/WebObjects/iTunesConnect.woa/ra/ng/app/904332168/ios/versioninfo/" @@ -531,7 +567,8 @@ def raw_data_details raw_data["details"]["value"] end end + # rubocop:enable Metrics/ClassLength end end