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

[action][OneSignal] Update to use v11.0 REST API #21839

Merged
merged 10 commits into from
Jan 30, 2024
16 changes: 14 additions & 2 deletions fastlane/lib/fastlane/actions/onesignal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,19 @@ def self.run(params)
payload["apns_p12_password"] = apns_p12_password || ""
end

unless params[:fcm_json].nil?
data = File.read(params[:fcm_json])
fcm_json = Base64.strict_encode64(data)
payload["fcm_v1_service_account_json"] = fcm_json
end

payload["gcm_key"] = android_token unless android_token.nil?
payload["android_gcm_sender_id"] = android_gcm_sender_id unless android_gcm_sender_id.nil?
payload["organization_id"] = organization_id unless organization_id.nil?

# here's the actual lifting - POST or PUT to OneSignal

json_headers = { 'Content-Type' => 'application/json', 'Authorization' => "Basic #{auth_token}" }
url = +'https://onesignal.com/api/v1/apps'
url = +'https://api.onesignal.com/apps'
url << '/' + app_id if is_update
uri = URI.parse(url)
http = Net::HTTP.new(uri.host, uri.port)
Expand Down Expand Up @@ -122,6 +127,11 @@ def self.available_options
sensitive: true,
optional: true),

FastlaneCore::ConfigItem.new(key: :fcm_json,
env_name: "FCM_JSON",
description: "FCM Service Account JSON File (in .json format)",
optional: true),

FastlaneCore::ConfigItem.new(key: :apns_p12,
env_name: "APNS_P12",
description: "APNS P12 File (in .p12 format)",
Expand Down Expand Up @@ -169,6 +179,7 @@ def self.example_code
app_name: "Name for OneSignal App",
android_token: "Your Android GCM key (optional)",
android_gcm_sender_id: "Your Android GCM Sender ID (optional)",
fcm_json: "Path to FCM Service Account JSON File (optional)",
apns_p12: "Path to Apple .p12 file (optional)",
apns_p12_password: "Password for .p12 file (optional)",
apns_env: "production/sandbox (defaults to production)",
Expand All @@ -180,6 +191,7 @@ def self.example_code
app_name: "New Name for OneSignal App",
android_token: "Your Android GCM key (optional)",
android_gcm_sender_id: "Your Android GCM Sender ID (optional)",
fcm_json: "Path to FCM Service Account JSON File (optional)",
apns_p12: "Path to Apple .p12 file (optional)",
apns_p12_password: "Password for .p12 file (optional)",
apns_env: "production/sandbox (defaults to production)",
Expand Down
4 changes: 2 additions & 2 deletions fastlane/spec/actions_specs/onesignal_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

context 'and is create' do
before :each do
stub_request(:post, 'https://onesignal.com/api/v1/apps').to_return(status: 200, body: '{}')
stub_request(:post, 'https://api.onesignal.com/apps').to_return(status: 200, body: '{}')
end

it 'outputs success message' do
Expand All @@ -30,7 +30,7 @@

context 'and is update' do
before :each do
stub_request(:put, "https://onesignal.com/api/v1/apps/#{app_id}").to_return(status: 200, body: '{}')
stub_request(:put, "https://api.onesignal.com/apps/#{app_id}").to_return(status: 200, body: '{}')
end

it 'outputs success message' do
Expand Down