Skip to content

Commit

Permalink
Merge pull request #3 from carrot-ar/gn/nested-json-fix
Browse files Browse the repository at this point in the history
BeaconInfo JSON tweak
  • Loading branch information
gonzalonunez committed Nov 14, 2017
2 parents a66555a + ec98c94 commit 15ff447
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 3 deletions.
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
language: swift
osx_image: xcode9
xcode_sdk: iphonesimulator11.0
script:
- xcodebuild clean test -project Parrot.xcodeproj -scheme Parrot -destination "platform=iOS Simulator,name=iPhone X,OS=11.0" CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO ONLY_ACTIVE_ARCH=NO -quiet
2 changes: 1 addition & 1 deletion Parrot.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|

s.name = "Parrot"
s.version = "0.0.4"
s.version = "0.0.5"
s.summary = "Parrot is a (very) small Swift framework that helps with advertising an iOS device as an iBeacon as well as monitoring/ranging for iBeacons."
s.description = <<-DESC
Parrot is (very) small Swift framework that helps with iBeacon related functionality on iOS. BeaconAdvertiser advertises an iOS device as an iBeacon, and BeaconRanger monitors/ranges for iBeacons.
Expand Down
58 changes: 58 additions & 0 deletions Parrot.xcodeproj/xcshareddata/xcschemes/ParrotTests.xcscheme
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0900"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "AB7519F31FB24DFC00285CF0"
BuildableName = "ParrotTests.xctest"
BlueprintName = "ParrotTests"
ReferencedContainer = "container:Parrot.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
9 changes: 7 additions & 2 deletions Parrot/BeaconInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,18 @@ extension BeaconInfo: Codable {
}
uuid = proximityUUID
identifier = try values.decode(String.self, forKey: .identifier)
params = try values.decode(BeaconRegionParams.self, forKey: .params)
params = (try? values.decode(BeaconRegionParams.self, forKey: .params)) ?? .none
}

public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(uuid.uuidString, forKey: .uuid)
try container.encode(identifier, forKey: .identifier)
try container.encode(params, forKey: .params)
switch params {
case .major, .both:
try container.encode(params, forKey: .params)
case .none:
break
}
}
}
18 changes: 18 additions & 0 deletions ParrotTests/ParrotTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,24 @@ class ParrotTests: XCTestCase {
}
}

func testNoNestedParamsDictionaryJSON() {
let dict = [
"identifier": "com.ParrotTests.Beacon",
"uuid": "E621E1F8-C36C-495A-93FC-0C247A3E6E5F"
]
let data = try! JSONSerialization.data(withJSONObject: dict, options: [])
print(try! JSONSerialization.jsonObject(with: data, options: []))
let decoded = try? JSONDecoder().decode(BeaconInfo.self, from: data)
XCTAssertNotNil(decoded)
dump(decoded)
switch decoded!.params {
case .none:
break
default:
XCTAssert(false, "Unexpected BeaconParams \(String(describing: decoded?.params))")
}
}

func testBeaconInfoJSON() {
let params = BeaconRegionParams.both(major: 100, minor: 50)
let beaconInfo = BeaconInfo(uuid: uuid, identifier: identifier, params: params)
Expand Down

0 comments on commit 15ff447

Please sign in to comment.