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] added b2b and educational discount to app #17490

Merged
merged 2 commits into from
Oct 23, 2020

Conversation

joshdholtz
Copy link
Member

Motivation and Context

Fixes #17244

Description

  • New model Spaceship::ConnectAPI::CustomAppUser
    • Spaceship::ConnectAPI::CustomAppUser.create
    • Spaceship::ConnectAPI::CustomAppUser.all
    • user.delete!
  • New model Spaceship::ConnectAPI::CustomAppOrganization
    • Spaceship::ConnectAPI::CustomAppOrganization.create
    • Spaceship::ConnectAPI::CustomAppOrganization.all
    • organization.delete!
  • New methods on Spaceship::ConnectAPI::App model
    • app.enable_b2b
    • app.disable_b2b
    • app.enable_educational_discount
    • app.disable_educational_discount

Example

lane :test_b2b do                                                                                                                             
  require 'pp'                                                                                                                                
  require 'spaceship'                                                                                                                         
                                                                                                                                              
  #Spaceship::ConnectAPI.auth                                                                                                                 
  Spaceship::ConnectAPI.login('your@email.com', team_name: 'Your Team Name')                                                                    
  app = Spaceship::ConnectAPI::App.get(app_id: "your-app-id")                                                                                  
                                                                                                                                              
  custom_app_users = Spaceship::ConnectAPI::CustomAppUser.all(app_id: app.id)                                                                 
  custom_app_users.each do |user|                                                                                                             
    if UI.confirm("Delete #{user.apple_id}?")                                                                                                 
      user.delete!                                                                                                                            
      UI.message "Deleted custom app user..."                                                                                                 
    end                                                                                                                                       
  end                                                                                                                                         
                                                                                                                                              
  custom_app_organizations = Spaceship::ConnectAPI::CustomAppOrganization.all(app_id: app.id)                                                 
  custom_app_organizations.each do |organization|                                                                                             
    if UI.confirm("Delete #{organization.name}?")                                                                                             
      organization.delete!                                                                                                                    
      UI.message "Deleted custom app organization..."                                                                                         
    end                                                                                                                                       
  end                                                                                                                                         
                                                                                                                                              
  if UI.confirm("Enable B2B?")                                                                                                                
    app.enable_b2b                                                                                                                            
  elsif UI.confirm("Disable B2B?")                                                                                                            
    app.disable_b2b                                                                                                                           
                                                                                                                                              
    if UI.confirm("Enable educational discount?")                                                                                             
      app.enable_educational_discount                                                                                                         
    elsif UI.confirm("Disable educational discount?")                                                                                         
      app.disable_educational_discount                                                                                                        
    end                                                                                                                                       
  end

  if UI.confirm("Add user?")                                                                                                                  
    apple_id = UI.input("Apple ID?")                                                                                                          
    Spaceship::ConnectAPI::CustomAppUser.create(app_id: app.id, apple_id: apple_id)                                                           
  end                                                                                                                                         
                                                                                                                                              
  if UI.confirm("Add organization?")
    id = UI.input("ID?")
    name = UI.input("Name?")
    Spaceship::ConnectAPI::CustomAppOrganization.create(app_id: app.id, device_enrollment_program_id: id, name: name)
  end
end

Testing Steps

Update Gemfile and run bundle install, bundle update fastlane, or bundle update

gem "fastlane", :git => "https://github.com/fastlane/fastlane.git", :branch => "joshdholtz-spaceship-connect-b2b"

@mattinasi
Copy link

I was able to test this and it works well! I only used the CustomAppOrganization, not the CustomAppUser.

Adding an org worked fine, and enabling B2B worked fine. However I was not able to disable B2B on an app that already had it enabled. I get the error When an app has NOT_APPLICABLE education discount, only CUSTOM app distribution is possible

I believe this is because the enable_b2b call sets the education discount to NOT_APPLICABLE, but the disable_b2b does not set it back?

def disable_b2b
update(attributes: {
distributionType: DistributionType::APP_STORE
})

Choose a reason for hiding this comment

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

I am getting an error on this because the educational discount type is still NOT_APPLICABLE, but that is not acceptable when distribution type is 'APP_STORE'

When an app has NOT_APPLICABLE education discount, only CUSTOM app distribution is possible

Copy link
Member Author

Choose a reason for hiding this comment

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

Ahhhhh.... good catch! I will make that change 😊

Copy link
Member Author

Choose a reason for hiding this comment

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

This should be fixed now!

class CustomAppOrganization
include Spaceship::ConnectAPI::Model

attr_accessor :device_enrollment_program_id

Choose a reason for hiding this comment

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

consider more consistent names for these attributes? dep_id and dep_name maybe?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is the name of it in the App Store Connect API model/resource so we've been sticking with those exact same names so it also matches what is (or will be) in the official doc 😇

@mattinasi
Copy link

Looks good!

@joshdholtz joshdholtz merged commit 60ce99a into master Oct 23, 2020
@joshdholtz joshdholtz deleted the joshdholtz-spaceship-connect-b2b branch October 23, 2020 19:09
@fastlane-bot
Copy link

Hey @joshdholtz 👋

Thank you for your contribution to fastlane and congrats on getting this pull request merged 🎉
The code change now lives in the master branch, however it wasn't released to RubyGems yet.
We usually ship about once a week, and your PR will be included in the next one.

Please let us know if this change requires an immediate release by adding a comment here 👍
We'll notify you once we shipped a new release with your changes 🚀

@fastlane-bot
Copy link

Congratulations! 🎉 This was released as part of fastlane 2.165.0 🚀

@fastlane fastlane locked and limited conversation to collaborators Dec 23, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Availability and B2B information through ConnectAPI?
3 participants