Skip to content

Commit c4e8115

Browse files
authored
Merge pull request #34 from OneSignal/fixing_ios_entrypoint
Fixing iOS entrypoint and both platform's unit tests
2 parents c007d03 + 8204840 commit c4e8115

5 files changed

Lines changed: 39 additions & 18 deletions

File tree

lib/oscli.rb

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,18 @@ def execute
4242
NetworkHandler.instance.send_track_error(app_id: "", platform: type, lang: lang, error_message: error_track_message)
4343
exit(1)
4444
end
45-
if !target
46-
target = entrypoint
45+
targetname = target
46+
if !targetname
47+
targetname = entrypoint
4748
end
48-
path = Dir.pwd
49-
ios_proj = OSProject::IOS.new(path, target, language, appid)
50-
xcodeproj_path = path + '/' + entrypoint + '.xcodeproj'
49+
dir = entrypoint.slice(0, entrypoint.rindex('/')) # => "/path/to"
50+
path = Dir.pwd + '/' + dir
51+
ios_proj = OSProject::IOS.new(path, targetname, language, appid)
52+
xcodeproj_path = Dir.pwd + '/' + entrypoint + '.xcodeproj'
5153
ios_proj.install_onesignal!(xcodeproj_path)
5254
elsif type_downcase == 'android'
53-
OSProject::GoogleAndroid.new(entrypoint, appid).add_sdk!()
55+
dir = Dir.pwd
56+
OSProject::GoogleAndroid.new(entrypoint, appid, dir).add_sdk!()
5457
else
5558
puts 'Invalid type (ios or android)'
5659
error_track_message = "User provide invalid type: #{type}"

lib/osnetwork.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
require 'clamp'
2+
require 'net/http'
23
require_relative 'osproject'
34
require_relative 'osproject_ios'
45
require_relative 'osproject_android'

lib/osproject_android.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44

55
class OSProject::GoogleAndroid < OSProject
66
attr_accessor :app_class_location
7+
attr_accessor :dir
78

8-
def initialize(app_class_location, os_app_id)
9+
def initialize(app_class_location, os_app_id, dir)
910
@app_class_location = app_class_location
10-
11+
@dir = dir
1112
directory_split = app_class_location.split('/', -1)
1213
lang_array = directory_split[-1].split(".")
1314

@@ -19,7 +20,6 @@ def initialize(app_class_location, os_app_id)
1920
end
2021

2122
lang = lang_array[1]
22-
dir = Dir.pwd
2323

2424
unless lang == "java" || lang == "kt"
2525
puts 'Invalid language (java or kotlin)'
@@ -58,7 +58,6 @@ def add_sdk!
5858
lang_index = (app_directory_split.index "main") + 2
5959
# Get Package directory in the form of ex: com.orgname.appname
6060
package_directory = app_directory_split.slice(lang_index..-2).join(".")
61-
6261
puts "Application class will be created under #{dir}/#{app_class_location}\nThis is needed for SDK init code. By saying (N) you can setup the init code by following https://documentation.onesignal.com/docs/android-sdk-setup#step-3-add-required-code.\nProceed with creation? (Y/N)"
6362
user_response = STDIN.gets.chomp.downcase
6463

@@ -293,6 +292,7 @@ def add_application_init_code(project_dir, app_class_location, lang)
293292

294293
def has_sdk?
295294
# TODO: more robust testing
296-
return File.readlines(dir + '/app/build.gradle').grep(/OneSignal/).any?
295+
return File.readlines(dir + '/build.gradle').grep(/onesignal/).any? &&
296+
File.readlines(dir + '/app/build.gradle').grep(/onesignal/).any?
297297
end
298298
end

lib/osproject_ios.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ def _create_nse()
173173
plist_path =
174174
if lang == :swift
175175
SWIFT_NSE_INFO_PLIST_PATH
176-
elsif lang == :objc
176+
else
177177
OBJC_NSE_INFO_PLIST_PATH
178178
end
179179
FileUtils.cp_r(cli_dir + plist_path, nsePath)

spec/osproject_spec.rb

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,37 @@
2323
FileUtils.cp_r(sampledir, projdir, verbose: true)
2424
end
2525
after(:all) do
26-
#FileUtils.remove_entry tmpdir
26+
FileUtils.remove_entry tmpdir
2727
end
2828
context sampledirname do
2929
it "successfully instantitates the object" do
30-
proj = proj_class.new(projdir, 'targetname', lang, 'app_id')
31-
expect(proj.type.to_s).to eq platform
32-
expect(proj.dir).to eq projdir
30+
if platform == 'googleandroid'
31+
langextension =
32+
if lang == 'kotlin'
33+
'kt'
34+
else
35+
lang
36+
end
37+
appclasspath = 'app/src/main/'+lang+'/com/onesignal/spec/samples/'+lang+'_bottom_nav/ApplicationClass.'+langextension
38+
proj = proj_class.new(appclasspath, 'app_id', projdir)
39+
elsif platform =='iOS'
40+
proj = proj_class.new(projdir, 'targetname', lang, 'app_id')
41+
expect(proj.type.to_s).to eq platform
42+
expect(proj.dir).to eq projdir
43+
end
3344
end
3445
it "successfully adds sdk" do
35-
3646
if platform == 'googleandroid'
47+
langextension =
48+
if lang == 'kotlin'
49+
'kt'
50+
else
51+
lang
52+
end
3753
# For Android samples, we have a appclassfile symlink in the proj root dir
3854
# When users use the CLI, they specify the file.
39-
proj = proj_class.new(projdir, '.appclassfile', lang, 'app_id')
55+
appclasspath = 'app/src/main/java/com/onesignal/spec/samples/'+lang+'_bottom_nav/ApplicationClass.'+langextension
56+
proj = proj_class.new(appclasspath, 'app_id', projdir)
4057
expect(proj.has_sdk?()).to eq false
4158
proj.add_sdk!()
4259
expect(proj.has_sdk?()).to eq true

0 commit comments

Comments
 (0)