def update_availability!(app_id, availability)
      r = request(:get, "ra/apps/#{app_id}/pricing/intervals")
      data = parse_response(r, 'data')

      data["countriesChanged"] = true
      data["countries"] = availability.territories.map { |territory| { 'code' => territory.code } }
      data["theWorld"] = availability.include_future_territories.nil? ? true : availability.include_future_territories

      # InitializespreOrder (if needed)
      data["preOrder"] ||= {}

      # Sets app_available_date to nil if cleared_for_preorder if false
      # This is need for apps that have never set either of these before
      # API will error out if cleared_for_preorder is false and app_available_date has a date
      cleared_for_preorder = availability.cleared_for_preorder
      app_available_date = cleared_for_preorder ? availability.app_available_date : nil
      data["b2bAppEnabled"] = availability.b2b_app_enabled
      data["educationalDiscount"] = availability.educational_discount
      data["preOrder"]["clearedForPreOrder"] = { "value" => cleared_for_preorder, "isEditable" => true, "isRequired" => true, "errorKeys" => nil }
      data["preOrder"]["appAvailableDate"] = { "value" => app_available_date, "isEditable" => true, "isRequired" => true, "errorKeys" => nil }
      data["b2bUsers"] = availability.b2b_app_enabled ? availability.b2b_users.map { |user| { "value" => { "add" => user.add, "delete" => user.delete, "dsUsername" => user.ds_username } } } : []

      # send the changes back to Apple
      r = request(:post) do |req|
        req.url("ra/apps/#{app_id}/pricing/intervals")
        req.body = data.to_json
        req.headers['Content-Type'] = 'application/json'
      end
      handle_itc_response(r.body)
      data = parse_response(r, 'data')
      Spaceship::Tunes::Availability.factory(data)
    end
def update_availability!(app_id, availability)
      r = request(:get, "ra/apps/#{app_id}/pricing/intervals")
      data = parse_response(r, 'data')

      data["countriesChanged"] = true
      data["countries"] = availability.territories.map { |territory| { 'code' => territory.code } }
      data["theWorld"] = availability.include_future_territories.nil? ? true : availability.include_future_territories

      # InitializespreOrder (if needed)
      data["preOrder"] ||= {}

      # Sets app_available_date to nil if cleared_for_preorder if false
      # This is need for apps that have never set either of these before
      # API will error out if cleared_for_preorder is false and app_available_date has a date
      cleared_for_preorder = availability.cleared_for_preorder
      app_available_date = cleared_for_preorder ? availability.app_available_date : nil
      data["b2bAppEnabled"] = availability.b2b_app_enabled
      data["educationalDiscount"] = availability.educational_discount
      data["preOrder"]["clearedForPreOrder"] = { "value" => cleared_for_preorder, "isEditable" => true, "isRequired" => true, "errorKeys" => nil }
      data["preOrder"]["appAvailableDate"] = { "value" => app_available_date, "isEditable" => true, "isRequired" => true, "errorKeys" => nil }
      data["b2bUsers"] = availability.b2b_app_enabled ? availability.b2b_users.map { |user| { "value" => { "add" => user.add, "delete" => user.delete, "dsUsername" => user.ds_username } } } : []

      # send the changes back to Apple
      r = request(:post) do |req|
        req.url("ra/apps/#{app_id}/pricing/intervals")
        req.body = data.to_json
        req.headers['Content-Type'] = 'application/json'
      end
      handle_itc_response(r.body)
      data = parse_response(r, 'data')
      Spaceship::Tunes::Availability.factory(data)
    end
@!group Availability

 Updates the availability

 @note Although this information is publicly available, the current spaceship implementation requires you to have a logged in client to access it
 @param app_id (String): The id of your app
 @param availability (Availability): The availability update

 @return [Spaceship::Tunes::Availability] the new Availability