Skip to content

Commit

Permalink
[spaceship] Allow for removing app from sale by updating territories (#…
Browse files Browse the repository at this point in the history
…20324)

* [spaceship] Allow for removing app from sale by updating territories with an empty array of ids.

* Remove parenthesis

* [deliver] Fix upload_price_tier to not remove app from sale by updating territories with an empty array of ids.

* [spaceship] Add documentation

* Add allow_removing_from_sale param to decide if empty array allows for removing apps from sale

* Run rubocop
  • Loading branch information
lucgrabowski committed Jun 29, 2022
1 parent 6f81747 commit b7d5632
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 11 deletions.
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

0 comments on commit b7d5632

Please sign in to comment.