Skip to content

Commit

Permalink
Update OneSignal action to use v11.0 REST API (#21839)
Browse files Browse the repository at this point in the history
* Update OneSignal API to v11 and add fcm_v1_service_account_json param

* Update OneSignal API

* Update example json

* Logging

* strict encode to base 64

* remove logs

* Update fcm_json env name

* Update tests

* run rubocop

* remove new line
  • Loading branch information
Akramhussain4 committed Jan 30, 2024
1 parent 14037c6 commit 508e535
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
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

0 comments on commit 508e535

Please sign in to comment.