Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[spaceship] Allow for removing app from sale by updating territories #20324

Merged
merged 6 commits into from
Jun 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion deliver/lib/deliver/upload_price_tier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ def upload(options)
app = Deliver.cache[:app]

attributes = {}
territory_ids = []

# Check App update method to understand how to use territory_ids.
territory_ids = nil # nil won't update app's territory_ids, empty array would remove app from sale.

# As of 2020-09-14:
# Official App Store Connect does not have an endpoint to get app prices for an app
Expand Down
6 changes: 4 additions & 2 deletions spaceship/lib/spaceship/connect_api/models/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,12 @@ def self.get(client: nil, app_id: nil, includes: "appStoreVersions")
return client.get_app(app_id: app_id, includes: includes).first
end

def update(client: nil, attributes: nil, app_price_tier_id: nil, territory_ids: nil)
# Updates app attributes, price tier and availability of an app in territories
# Check Tunes patch_app method for explanation how to use territory_ids parameter with allow_removing_from_sale to remove app from sale
def update(client: nil, attributes: nil, app_price_tier_id: nil, territory_ids: nil, allow_removing_from_sale: false)
client ||= Spaceship::ConnectAPI
attributes = reverse_attr_mapping(attributes)
return client.patch_app(app_id: id, attributes: attributes, app_price_tier_id: app_price_tier_id, territory_ids: territory_ids)
return client.patch_app(app_id: id, attributes: attributes, app_price_tier_id: app_price_tier_id, territory_ids: territory_ids, allow_removing_from_sale: allow_removing_from_sale)
end

#
Expand Down
26 changes: 18 additions & 8 deletions spaceship/lib/spaceship/connect_api/tunes/tunes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,15 @@ def post_app(name: nil, version_string: nil, sku: nil, primary_locale: nil, bund
tunes_request_client.post("apps", body)
end

def patch_app(app_id: nil, attributes: {}, app_price_tier_id: nil, territory_ids: nil)
# Updates app attributes, price tier, visibility in regions or countries.
# Use territory_ids with allow_removing_from_sale to remove app from sale
# @param territory_ids updates app visibility in regions or countries.
# Possible values:
# empty array will remove app from sale if allow_removing_from_sale is true,
# array with territory ids will set availability to territories with those ids,
# nil will leave app availability on AppStore as is
# @param allow_removing_from_sale allows for removing app from sale when territory_ids is an empty array
def patch_app(app_id: nil, attributes: {}, app_price_tier_id: nil, territory_ids: nil, allow_removing_from_sale: false)
relationships = {}
included = []

Expand Down Expand Up @@ -173,13 +181,15 @@ def patch_app(app_id: nil, attributes: {}, app_price_tier_id: nil, territory_ids
end

# Territories
territories_data = (territory_ids || []).map do |id|
{ type: "territories", id: id }
end
unless territories_data.empty?
relationships[:availableTerritories] = {
data: territories_data
}
unless territory_ids.nil?
territories_data = territory_ids.map do |id|
{ type: "territories", id: id }
end
if !territories_data.empty? || allow_removing_from_sale
relationships[:availableTerritories] = {
data: territories_data
}
end
end

# Data
Expand Down