require 'appstore_kit_fork/httpclient.rb' require 'appstore_kit_fork/token_generator' require 'appstore_kit_fork/version' require 'appstore_kit_fork/mappers/app_list_response_mapper' require 'appstore_kit_fork/mappers/app_response_mapper' require 'appstore_kit_fork/mappers/user_list_response_mapper' require 'appstore_kit_fork/mappers/build_list_response_mapper' require 'appstore_kit_fork/mappers/build_details_response_mapper' require 'appstore_kit_fork/mappers/app_version_mapper' module AppstoreKitFork # Class used for communicating with the App Store Connect API class Client def initialize(issuer_id, key_id, private_key) token_generator = TokenGenerator.new( issuer_id, key_id, private_key ) @httpclient = HTTPClient.new('https://api.appstoreconnect.apple.com/v1') @httpclient.class.headers( 'Authorization' => "Bearer #{token_generator.generate_token}" ) end def apps(bundle_id) @httpclient.get "/apps?filter[bundleId]=#{bundle_id}", AppListResponseMapper.new end def users @httpclient.get '/users', UserListResponseMapper.new end def app_builds(app) @httpclient.get "/apps/#{app.id}/builds", BuildListResponseMapper.new end def app(id) @httpclient.get "/apps/#{id}", AppResponseMapper.new end def prepare_submission_versions(id, platform) release_version(id, "PREPARE_FOR_SUBMISSION", platform) end def ready_sale_versions(id, platform) release_version(id, "READY_FOR_SALE", platform) end def release_version(id, state, platform) @httpclient.get "/apps/#{id}/appStoreVersions?filter[appStoreState]=#{state}&filter[platform]=#{platform}", VersionResponseMapper.new end def build_beta_details(build) @httpclient.get( "/buildBetaDetails/#{build.id}", BuildDetailsResponseMapper.new ) end end end