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] Check if app removed from sale #21902

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
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
2 changes: 2 additions & 0 deletions spaceship/lib/spaceship/connect_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
require 'spaceship/connect_api/models/custom_app_user'
require 'spaceship/connect_api/models/pre_release_version'

require 'spaceship/connect_api/models/app_availability'
require 'spaceship/connect_api/models/territory_availability'
require 'spaceship/connect_api/models/app_data_usage'
require 'spaceship/connect_api/models/app_data_usage_category'
require 'spaceship/connect_api/models/app_data_usage_data_protection'
Expand Down
2 changes: 1 addition & 1 deletion spaceship/lib/spaceship/connect_api/api_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def initialize(cookie: nil, current_team_id: nil, token: nil, csrf_tokens: nil,
# Forwarding to class level if using web session.
def hostname
if @token
return "https://api.appstoreconnect.apple.com/v1/"
return "https://api.appstoreconnect.apple.com/"
end
return self.class.hostname
end
Expand Down
30 changes: 30 additions & 0 deletions spaceship/lib/spaceship/connect_api/models/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ def self.type
return "apps"
end

def removed_from_sale?
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if it shouldn't be renamed to removed_from_sale_or_not_ready?

ready_for_distribution = get_ready_for_distribution_app_store_version(includes: nil)
return true if ready_for_distribution.nil?
territoryAvailabilities = get_app_availabilities.territory_availabilities
availabilities = territoryAvailabilities.map(&:available)
return availabilities.all?(false)
end

#
# Apps
#
Expand Down Expand Up @@ -153,6 +161,16 @@ def fetch_latest_app_info(client: nil, includes: Spaceship::ConnectAPI::AppInfo:
return resp.to_models.first
end

#
# App Availabilities
#

def get_app_availabilities(client: nil, filter: {}, includes: "territoryAvailabilities", limit: { "territoryAvailabilities": 200 })
client ||= Spaceship::ConnectAPI
resp = client.get_app_availabilities(app_id: id, filter: filter, includes: includes, limit: limit, sort: nil)
return resp.to_models.first
end

#
# Available Territories
#
Expand Down Expand Up @@ -293,6 +311,18 @@ def get_pending_release_app_store_version(client: nil, platform: nil, includes:
return get_app_store_versions(client: client, filter: filter, includes: includes).first
end

def get_ready_for_distribution_app_store_version(client: nil, platform: nil, includes: Spaceship::ConnectAPI::AppStoreVersion::ESSENTIAL_INCLUDES)
client ||= Spaceship::ConnectAPI
platform ||= Spaceship::ConnectAPI::Platform::IOS
filter = {
appVersionState: [
Spaceship::ConnectAPI::AppStoreVersion::AppVersionState::READY_FOR_DISTRIBUTION
].join(','),
platform: platform
}
return get_app_store_versions(client: client, filter: filter, includes: includes).first
end

def get_app_store_versions(client: nil, filter: {}, includes: Spaceship::ConnectAPI::AppStoreVersion::ESSENTIAL_INCLUDES, limit: nil, sort: nil)
client ||= Spaceship::ConnectAPI
if limit.nil?
Expand Down
23 changes: 23 additions & 0 deletions spaceship/lib/spaceship/connect_api/models/app_availability.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
require_relative '../model'
module Spaceship
class ConnectAPI
class AppAvailability
include Spaceship::ConnectAPI::Model

attr_accessor :app
attr_accessor :available_in_new_territories

attr_accessor :territoryAvailabilities

attr_mapping({
app: 'app',
availableInNewTerritories: 'available_in_new_territories',
territoryAvailabilities: 'territory_availabilities'
})

def self.type
return 'appAvailabilities'
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
require_relative '../model'
module Spaceship
class ConnectAPI
class TerritoryAvailability
include Spaceship::ConnectAPI::Model

attr_accessor :available
attr_accessor :content_statuses
attr_accessor :pre_order_enabled
attr_accessor :pre_order_publish_date
attr_accessor :release_date

module ContentStatus
AVAILABLE = "AVAILABLE"
AVAILABLE_FOR_PREORDER_ON_DATE = "AVAILABLE_FOR_PREORDER_ON_DATE"
PROCESSING_TO_NOT_AVAILABLE = "PROCESSING_TO_NOT_AVAILABLE"
PROCESSING_TO_AVAILABLE = "PROCESSING_TO_AVAILABLE"
PROCESSING_TO_PRE_ORDER = "PROCESSING_TO_PRE_ORDER"
AVAILABLE_FOR_SALE_UNRELEASED_APP = "AVAILABLE_FOR_SALE_UNRELEASED_APP"
PREORDER_ON_UNRELEASED_APP = "PREORDER_ON_UNRELEASED_APP"
AVAILABLE_FOR_PREORDER = "AVAILABLE_FOR_PREORDER"
MISSING_RATING = "MISSING_RATING"
CANNOT_SELL_RESTRICTED_RATING = "CANNOT_SELL_RESTRICTED_RATING"
BRAZIL_REQUIRED_TAX_ID = "BRAZIL_REQUIRED_TAX_ID"
MISSING_GRN = "MISSING_GRN"
UNVERIFIED_GRN = "UNVERIFIED_GRN"
CANNOT_SELL_SEVENTEEN_PLUS_APPS = "CANNOT_SELL_SEVENTEEN_PLUS_APPS"
CANNOT_SELL_SEXUALLY_EXPLICIT = "CANNOT_SELL_SEXUALLY_EXPLICIT"
CANNOT_SELL_NON_IOS_GAMES = "CANNOT_SELL_NON_IOS_GAMES"
CANNOT_SELL_SEVENTEEN_PLUS_GAMES = "CANNOT_SELL_SEVENTEEN_PLUS_GAMES"
CANNOT_SELL_FREQUENT_INTENSE_GAMBLING = "CANNOT_SELL_FREQUENT_INTENSE_GAMBLING"
CANNOT_SELL_CASINO = "CANNOT_SELL_CASINO"
CANNOT_SELL_CASINO_WITHOUT_GRAC = "CANNOT_SELL_CASINO_WITHOUT_GRAC"
CANNOT_SELL_CASINO_WITHOUT_AGE_VERIFICATION = "CANNOT_SELL_CASINO_WITHOUT_AGE_VERIFICATION"
CANNOT_SELL_FREQUENT_INTENSE_ALCOHOL_TOBACCO_DRUGS = "CANNOT_SELL_FREQUENT_INTENSE_ALCOHOL_TOBACCO_DRUGS"
CANNOT_SELL_FREQUENT_INTENSE_VIOLENCE = "CANNOT_SELL_FREQUENT_INTENSE_VIOLENCE"
CANNOT_SELL_FREQUENT_INTENSE_SEXUAL_CONTENT_NUDITY = "CANNOT_SELL_FREQUENT_INTENSE_SEXUAL_CONTENT_NUDITY"
CANNOT_SELL_INFREQUENT_MILD_ALCOHOL_TOBACCO_DRUGS = "CANNOT_SELL_INFREQUENT_MILD_ALCOHOL_TOBACCO_DRUGS"
CANNOT_SELL_INFREQUENT_MILD_SEXUAL_CONTENT_NUDITY = "CANNOT_SELL_INFREQUENT_MILD_SEXUAL_CONTENT_NUDITY"
CANNOT_SELL_ADULT_ONLY = "CANNOT_SELL_ADULT_ONLY"
CANNOT_SELL_FREQUENT_INTENSE = "CANNOT_SELL_FREQUENT_INTENSE"
CANNOT_SELL_FREQUENT_INTENSE_WITHOUT_GRAC = "CANNOT_SELL_FREQUENT_INTENSE_WITHOUT_GRAC"
CANNOT_SELL_GAMBLING_CONTESTS = "CANNOT_SELL_GAMBLING_CONTESTS"
CANNOT_SELL_GAMBLING = "CANNOT_SELL_GAMBLING"
CANNOT_SELL_CONTESTS = "CANNOT_SELL_CONTESTS"
CANNOT_SELL = "CANNOT_SELL"
end

attr_mapping({
available: 'available',
contentStatuses: 'content_statuses',
preOrderEnabled: 'pre_order_enabled',
preOrderPublishDate: 'pre_order_publish_date',
releaseDate: 'release_date'
})

def self.type
return 'territoryAvailabilities'
end
end
end
end
2 changes: 1 addition & 1 deletion spaceship/lib/spaceship/connect_api/provisioning/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def initialize(cookie: nil, current_team_id: nil, token: nil, another_client: ni
end

def self.hostname
'https://developer.apple.com/services-account/v1/'
'https://developer.apple.com/services-account/'
end

#
Expand Down
46 changes: 25 additions & 21 deletions spaceship/lib/spaceship/connect_api/provisioning/provisioning.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ module Spaceship
class ConnectAPI
module Provisioning
module API
module Version
V1 = "v1"
end

def provisioning_request_client=(provisioning_request_client)
@provisioning_request_client = provisioning_request_client
end
Expand All @@ -19,12 +23,12 @@ def provisioning_request_client

def get_bundle_ids(filter: {}, includes: nil, fields: nil, limit: nil, sort: nil)
params = provisioning_request_client.build_params(filter: filter, includes: includes, fields: fields, limit: limit, sort: sort)
provisioning_request_client.get("bundleIds", params)
provisioning_request_client.get("#{Version::V1}/bundleIds", params)
end

def get_bundle_id(bundle_id_id: {}, includes: nil)
params = provisioning_request_client.build_params(filter: nil, includes: includes, limit: nil, sort: nil)
provisioning_request_client.get("bundleIds/#{bundle_id_id}", params)
provisioning_request_client.get("#{Version::V1}/bundleIds/#{bundle_id_id}", params)
end

def post_bundle_id(name:, platform:, identifier:, seed_id:)
Expand All @@ -42,7 +46,7 @@ def post_bundle_id(name:, platform:, identifier:, seed_id:)
}
}

provisioning_request_client.post("bundleIds", body)
provisioning_request_client.post("#{Version::V1}/bundleIds", body)
end

#
Expand All @@ -51,12 +55,12 @@ def post_bundle_id(name:, platform:, identifier:, seed_id:)

def get_bundle_id_capabilities(bundle_id_id:, includes: nil, limit: nil, sort: nil)
params = provisioning_request_client.build_params(filter: nil, includes: includes, limit: limit, sort: sort)
provisioning_request_client.get("bundleIds/#{bundle_id_id}/bundleIdCapabilities", params)
provisioning_request_client.get("#{Version::V1}/bundleIds/#{bundle_id_id}/bundleIdCapabilities", params)
end

def get_available_bundle_id_capabilities(bundle_id_id:)
params = provisioning_request_client.build_params(filter: { bundleId: bundle_id_id })
provisioning_request_client.get("capabilities", params)
provisioning_request_client.get("#{Version::V1}/capabilities", params)
end

def post_bundle_id_capability(bundle_id_id:, capability_type:, settings: [])
Expand All @@ -83,7 +87,7 @@ def post_bundle_id_capability(bundle_id_id:, capability_type:, settings: [])
}
}
}
provisioning_request_client.post("bundleIdCapabilities", body)
provisioning_request_client.post("#{Version::V1}/bundleIdCapabilities", body)
end

def patch_bundle_id_capability(bundle_id_id:, seed_id:, enabled: false, capability_type:, settings: [])
Expand Down Expand Up @@ -118,11 +122,11 @@ def patch_bundle_id_capability(bundle_id_id:, seed_id:, enabled: false, capabili
}
}

provisioning_request_client.patch("bundleIds/#{bundle_id_id}", body)
provisioning_request_client.patch("#{Version::V1}/bundleIds/#{bundle_id_id}", body)
end

def delete_bundle_id_capability(bundle_id_capability_id:)
provisioning_request_client.delete("bundleIdCapabilities/#{bundle_id_capability_id}")
provisioning_request_client.delete("#{Version::V1}/bundleIdCapabilities/#{bundle_id_capability_id}")
end

#
Expand All @@ -132,15 +136,15 @@ def delete_bundle_id_capability(bundle_id_capability_id:)
def get_certificates(profile_id: nil, filter: {}, includes: nil, fields: nil, limit: nil, sort: nil)
params = provisioning_request_client.build_params(filter: filter, includes: includes, fields: fields, limit: limit, sort: sort)
if profile_id.nil?
provisioning_request_client.get("certificates", params)
provisioning_request_client.get("#{Version::V1}/certificates", params)
else
provisioning_request_client.get("profiles/#{profile_id}/certificates", params)
provisioning_request_client.get("#{Version::V1}/profiles/#{profile_id}/certificates", params)
end
end

def get_certificate(certificate_id: nil, includes: nil)
params = provisioning_request_client.build_params(filter: nil, includes: includes, limit: nil, sort: nil)
provisioning_request_client.get("certificates/#{certificate_id}", params)
provisioning_request_client.get("#{Version::V1}/certificates/#{certificate_id}", params)
end

def post_certificate(attributes: {})
Expand All @@ -151,13 +155,13 @@ def post_certificate(attributes: {})
}
}

provisioning_request_client.post("certificates", body)
provisioning_request_client.post("#{Version::V1}/certificates", body)
end

def delete_certificate(certificate_id: nil)
raise "Certificate id is nil" if certificate_id.nil?

provisioning_request_client.delete("certificates/#{certificate_id}")
provisioning_request_client.delete("#{Version::V1}/certificates/#{certificate_id}")
end

#
Expand All @@ -167,9 +171,9 @@ def delete_certificate(certificate_id: nil)
def get_devices(profile_id: nil, filter: {}, includes: nil, fields: nil, limit: nil, sort: nil)
params = provisioning_request_client.build_params(filter: filter, includes: includes, fields: fields, limit: limit, sort: sort)
if profile_id.nil?
provisioning_request_client.get("devices", params)
provisioning_request_client.get("#{Version::V1}/devices", params)
else
provisioning_request_client.get("profiles/#{profile_id}/devices", params)
provisioning_request_client.get("#{Version::V1}/profiles/#{profile_id}/devices", params)
end
end

Expand All @@ -187,7 +191,7 @@ def post_device(name: nil, platform: nil, udid: nil)
}
}

provisioning_request_client.post("devices", body)
provisioning_request_client.post("#{Version::V1}/devices", body)
end

def patch_device(id: nil, status: nil, new_name: nil)
Expand All @@ -206,7 +210,7 @@ def patch_device(id: nil, status: nil, new_name: nil)
}
}

provisioning_request_client.patch("devices/#{id}", body)
provisioning_request_client.patch("#{Version::V1}/devices/#{id}", body)
end

#
Expand All @@ -215,7 +219,7 @@ def patch_device(id: nil, status: nil, new_name: nil)

def get_profiles(filter: {}, includes: nil, fields: nil, limit: nil, sort: nil)
params = provisioning_request_client.build_params(filter: filter, includes: includes, fields: fields, limit: limit, sort: sort)
provisioning_request_client.get("profiles", params)
provisioning_request_client.get("#{Version::V1}/profiles", params)
end

def post_profiles(bundle_id_id: nil, certificates: nil, devices: nil, attributes: {})
Expand Down Expand Up @@ -250,19 +254,19 @@ def post_profiles(bundle_id_id: nil, certificates: nil, devices: nil, attributes
}
}

provisioning_request_client.post("profiles", body)
provisioning_request_client.post("#{Version::V1}/profiles", body)
end

def get_profile_bundle_id(profile_id: nil)
raise "Profile id is nil" if profile_id.nil?

provisioning_request_client.get("profiles/#{profile_id}/bundleId")
provisioning_request_client.get("#{Version::V1}/profiles/#{profile_id}/bundleId")
end

def delete_profile(profile_id: nil)
raise "Profile id is nil" if profile_id.nil?

provisioning_request_client.delete("profiles/#{profile_id}")
provisioning_request_client.delete("#{Version::V1}/profiles/#{profile_id}")
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion spaceship/lib/spaceship/connect_api/testflight/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def initialize(cookie: nil, current_team_id: nil, token: nil, another_client: ni
end

def self.hostname
'https://appstoreconnect.apple.com/iris/v1/'
'https://appstoreconnect.apple.com/iris/'
end
end
end
Expand Down