Skip to content

Commit

Permalink
add parsing for operating hour (#400)
Browse files Browse the repository at this point in the history
* add parsing for operating hour

* move to include

* update dict value

* bump patch

* add test

* bump beta

* bump beta

* remove beta tag
  • Loading branch information
KennyHuRadar authored Oct 8, 2024
1 parent 6d25648 commit 3545c3c
Show file tree
Hide file tree
Showing 12 changed files with 142 additions and 6 deletions.
2 changes: 1 addition & 1 deletion RadarSDK.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'RadarSDK'
s.version = '3.18.1'
s.version = '3.18.3'
s.summary = 'iOS SDK for Radar, the leading geofencing and location tracking platform'
s.homepage = 'https://radar.com'
s.author = { 'Radar Labs, Inc.' => '[email protected]' }
Expand Down
18 changes: 16 additions & 2 deletions RadarSDK.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,10 @@
DD8E2F7A24018C37002D51AB /* CLLocationManagerMock.m in Sources */ = {isa = PBXBuildFile; fileRef = DD8E2F7924018C37002D51AB /* CLLocationManagerMock.m */; };
DD8E2F7D24018C54002D51AB /* CLVisitMock.m in Sources */ = {isa = PBXBuildFile; fileRef = DD8E2F7C24018C54002D51AB /* CLVisitMock.m */; };
DE1E7644239724FD006F34A1 /* search_geofences.json in Resources */ = {isa = PBXBuildFile; fileRef = DE1E7643239724FD006F34A1 /* search_geofences.json */; };
E658DB072CB46277004E0F01 /* RadarOperatingHour.h in Headers */ = {isa = PBXBuildFile; fileRef = E658DB062CB46277004E0F01 /* RadarOperatingHour.h */; settings = {ATTRIBUTES = (Public, ); }; };
E658DB092CB462AA004E0F01 /* RadarOperatingHour.m in Sources */ = {isa = PBXBuildFile; fileRef = E658DB082CB462AA004E0F01 /* RadarOperatingHour.m */; };
E658DB0A2CB462AA004E0F01 /* RadarOperatingHour.m in Sources */ = {isa = PBXBuildFile; fileRef = E658DB082CB462AA004E0F01 /* RadarOperatingHour.m */; };
E658DB0C2CB46B50004E0F01 /* RadarOperatingHour+Internal.h in Headers */ = {isa = PBXBuildFile; fileRef = E658DB0B2CB46B50004E0F01 /* RadarOperatingHour+Internal.h */; };
E698B6502C6112FA00084371 /* RadarMotionProtocol.h in Headers */ = {isa = PBXBuildFile; fileRef = E698B64F2C6112FA00084371 /* RadarMotionProtocol.h */; settings = {ATTRIBUTES = (Public, ); }; };
E6B93B722C90E2B8003CB858 /* RadarInitializeOptions.h in Headers */ = {isa = PBXBuildFile; fileRef = E6B93B712C90E2B8003CB858 /* RadarInitializeOptions.h */; settings = {ATTRIBUTES = (Public, ); }; };
E6B93B742C90E5B8003CB858 /* RadarInitializeOptions.m in Sources */ = {isa = PBXBuildFile; fileRef = E6B93B732C90E5B8003CB858 /* RadarInitializeOptions.m */; };
Expand Down Expand Up @@ -339,6 +343,9 @@
DDD7BD0325EC3015002473B3 /* RadarRouteMatrix.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RadarRouteMatrix.m; sourceTree = "<group>"; };
DDF1157C2524E18100D575C4 /* RadarTrip.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RadarTrip.m; sourceTree = "<group>"; };
DE1E7643239724FD006F34A1 /* search_geofences.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = search_geofences.json; sourceTree = "<group>"; };
E658DB062CB46277004E0F01 /* RadarOperatingHour.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RadarOperatingHour.h; sourceTree = "<group>"; };
E658DB082CB462AA004E0F01 /* RadarOperatingHour.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RadarOperatingHour.m; sourceTree = "<group>"; };
E658DB0B2CB46B50004E0F01 /* RadarOperatingHour+Internal.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "RadarOperatingHour+Internal.h"; sourceTree = "<group>"; };
E698B64F2C6112FA00084371 /* RadarMotionProtocol.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RadarMotionProtocol.h; sourceTree = "<group>"; };
E6B93B712C90E2B8003CB858 /* RadarInitializeOptions.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RadarInitializeOptions.h; sourceTree = "<group>"; };
E6B93B732C90E5B8003CB858 /* RadarInitializeOptions.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RadarInitializeOptions.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -403,6 +410,7 @@
96A5A0E427AD9F7F007B960B /* RadarRoute.h */,
0114F057284EFDB700ADA4E4 /* RadarRouteMode.h */,
96A5A0F127AD9F7F007B960B /* RadarRouteDistance.h */,
E658DB062CB46277004E0F01 /* RadarOperatingHour.h */,
96A5A0F227AD9F7F007B960B /* RadarRouteDuration.h */,
96A5A0D927AD9F7F007B960B /* RadarRouteGeometry.h */,
96A5A0DD27AD9F7F007B960B /* RadarRouteMatrix.h */,
Expand Down Expand Up @@ -574,8 +582,10 @@
96A5A0B127AD9F40007B960B /* RadarPlace+Internal.h */,
DD236CB22308812600EB88F9 /* RadarPlace.m */,
96A5A0BB27AD9F41007B960B /* RadarPolygonGeometry+Internal.h */,
E658DB0B2CB46B50004E0F01 /* RadarOperatingHour+Internal.h */,
DD236CAB2308812600EB88F9 /* RadarPolygonGeometry.m */,
96A5A0B527AD9F40007B960B /* RadarRegion+Internal.h */,
E658DB082CB462AA004E0F01 /* RadarOperatingHour.m */,
DD236CBC2308812700EB88F9 /* RadarRegion.m */,
96A5A0B327AD9F40007B960B /* RadarRoute+Internal.h */,
DD4D4D1723E60E6300D36C1D /* RadarRoute.m */,
Expand Down Expand Up @@ -649,6 +659,8 @@
019514362BD078D90031ABA2 /* RadarVerifiedLocationToken.h in Headers */,
96A5A10B27AD9F7F007B960B /* RadarTripOptions.h in Headers */,
E698B6502C6112FA00084371 /* RadarMotionProtocol.h in Headers */,
E658DB072CB46277004E0F01 /* RadarOperatingHour.h in Headers */,
E658DB0C2CB46B50004E0F01 /* RadarOperatingHour+Internal.h in Headers */,
E6B93B722C90E2B8003CB858 /* RadarInitializeOptions.h in Headers */,
82F7FAEE2A65FE030055AA4B /* RadarVerificationManager.h in Headers */,
96A5A0C727AD9F41007B960B /* RadarChain+Internal.h in Headers */,
Expand Down Expand Up @@ -844,6 +856,7 @@
files = (
0107AAA726220160008AB52F /* RadarGeofence.m in Sources */,
0107AAC826220184008AB52F /* RadarRouteDistance.m in Sources */,
E658DB092CB462AA004E0F01 /* RadarOperatingHour.m in Sources */,
0107AA952622014C008AB52F /* RadarCoordinate.m in Sources */,
0107AA8F26220146008AB52F /* RadarCircleGeometry.m in Sources */,
0107AAD426220190008AB52F /* RadarRouteGeometry.m in Sources */,
Expand Down Expand Up @@ -904,6 +917,7 @@
files = (
DD8E2F7424018C17002D51AB /* RadarPermissionsHelperMock.m in Sources */,
DD8E2F7724018C25002D51AB /* RadarAPIHelperMock.m in Sources */,
E658DB0A2CB462AA004E0F01 /* RadarOperatingHour.m in Sources */,
96B465BC27D6732500D7119B /* CLLocation+RadarTests.m in Sources */,
E6B93B742C90E5B8003CB858 /* RadarInitializeOptions.m in Sources */,
DD103211237E0C47003DD408 /* RadarSDKTests.m in Sources */,
Expand Down Expand Up @@ -1048,7 +1062,7 @@
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
MARKETING_VERSION = 3.18.1;
MARKETING_VERSION = 3.18.3;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
ONLY_ACTIVE_ARCH = YES;
Expand Down Expand Up @@ -1106,7 +1120,7 @@
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
MARKETING_VERSION = 3.18.1;
MARKETING_VERSION = 3.18.3;
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
OTHER_CFLAGS = "-fembed-bitcode";
Expand Down
6 changes: 6 additions & 0 deletions RadarSDK/Include/RadarGeofence.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#import "RadarGeofenceGeometry.h"
#import <Foundation/Foundation.h>
#import "RadarOperatingHour.h"

/**
Represents a geofence.
Expand Down Expand Up @@ -45,6 +46,11 @@
*/
@property (nonnull, strong, nonatomic, readonly) RadarGeofenceGeometry *geometry;

/**
The optional operating hours for the geofence.
*/
@property (nullable, copy, nonatomic, readonly) RadarOperatingHour *operatingHours;

+ (NSArray<NSDictionary *> *_Nullable)arrayForGeofences:(NSArray<RadarGeofence *> *_Nullable)geofences;
- (NSDictionary *_Nonnull)dictionaryValue;

Expand Down
15 changes: 15 additions & 0 deletions RadarSDK/Include/RadarOperatingHour.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// RadarOperatingHour.h
// RadarSDK
//
// Created by Kenny Hu on 10/7/24.
// Copyright © 2024 Radar Labs, Inc. All rights reserved.
//

#import <Foundation/Foundation.h>

@interface RadarOperatingHour : NSObject

@property (nonatomic, strong, readonly) NSDictionary<NSString *, NSArray<NSArray<NSString *> *> *> *hours;

@end
1 change: 1 addition & 0 deletions RadarSDK/RadarGeofence+Internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
tag:(NSString *_Nullable)tag
externalId:(NSString *_Nullable)externalId
metadata:(NSDictionary *_Nullable)metadata
operatingHours:(RadarOperatingHour *_Nullable)operatingHours
geometry:(RadarGeofenceGeometry *_Nonnull)geometry;
- (instancetype _Nullable)initWithObject:(id _Nonnull)object;

Expand Down
14 changes: 13 additions & 1 deletion RadarSDK/RadarGeofence.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#import "RadarCoordinate+Internal.h"
#import "RadarGeofence+Internal.h"
#import "RadarPolygonGeometry+Internal.h"
#import "RadarOperatingHour+Internal.h"

@implementation RadarGeofence

Expand Down Expand Up @@ -36,6 +37,7 @@ - (instancetype _Nullable)initWithId:(NSString *)_id
tag:(NSString *)tag
externalId:(NSString *_Nullable)externalId
metadata:(NSDictionary *_Nullable)metadata
operatingHours: (RadarOperatingHour *_Nullable) operatingHours
geometry:(RadarGeofenceGeometry *_Nonnull)geometry {
self = [super init];
if (self) {
Expand All @@ -44,6 +46,7 @@ - (instancetype _Nullable)initWithId:(NSString *)_id
_tag = tag;
_externalId = externalId;
_metadata = metadata;
_operatingHours = operatingHours;
_geometry = geometry;
}
return self;
Expand All @@ -61,6 +64,7 @@ - (instancetype _Nullable)initWithObject:(id)object {
NSString *tag;
NSString *externalId;
NSDictionary *metadata;
RadarOperatingHour *operatingHours;
RadarGeofenceGeometry *geometry;

id idObj = dict[@"_id"];
Expand Down Expand Up @@ -88,6 +92,11 @@ - (instancetype _Nullable)initWithObject:(id)object {
metadata = (NSDictionary *)metadataObj;
}

id operatingHoursObj = dict[@"operatingHours"];
if (operatingHoursObj && [operatingHoursObj isKindOfClass:[NSDictionary class]]) {
operatingHours = [[RadarOperatingHour alloc] initWithDictionary:operatingHoursObj];
}

id typeObj = dict[@"type"];
if ([typeObj isKindOfClass:[NSString class]]) {
NSString *type = (NSString *)typeObj;
Expand Down Expand Up @@ -130,7 +139,7 @@ - (instancetype _Nullable)initWithObject:(id)object {
}
}

return [[RadarGeofence alloc] initWithId:_id description:description tag:tag externalId:externalId metadata:metadata geometry:geometry];
return [[RadarGeofence alloc] initWithId:_id description:description tag:tag externalId:externalId metadata:metadata operatingHours:operatingHours geometry:geometry];
}

- (NSMutableArray<RadarCoordinate *> *)getPolygonCoordinates:(NSDictionary *)dict {
Expand Down Expand Up @@ -212,6 +221,9 @@ - (NSDictionary *)dictionaryValue {
[dict setValue:self.externalId forKey:@"externalId"];
[dict setValue:self.__description forKey:@"description"];
[dict setValue:self.metadata forKey:@"metadata"];
if (self.operatingHours) {
[dict setValue:self.operatingHours.hours forKey:@"operatingHours"];
}
if ([self.geometry isKindOfClass:[RadarCircleGeometry class]]) {
RadarCircleGeometry *circleGeometry = (RadarCircleGeometry *)self.geometry;
[dict setValue:@(circleGeometry.radius) forKey:@"geometryRadius"];
Expand Down
15 changes: 15 additions & 0 deletions RadarSDK/RadarOperatingHour+Internal.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// RadarOperatingHour+Internal.h
// RadarSDK
//
// Created by Kenny Hu on 10/7/24.
// Copyright © 2024 Radar Labs, Inc. All rights reserved.
//

#import "RadarOperatingHour.h"

@interface RadarOperatingHour()

- (instancetype)initWithDictionary:(NSDictionary *)dictionary;

@end
47 changes: 47 additions & 0 deletions RadarSDK/RadarOperatingHour.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//
// RadarOperatingHour.m
// RadarSDK
//
// Created by Kenny Hu on 10/7/24.
// Copyright © 2024 Radar Labs, Inc. All rights reserved.
//

#import <Foundation/Foundation.h>

#import "RadarOperatingHour+Internal.h"

@implementation RadarOperatingHour

- (instancetype)initWithDictionary:(NSDictionary *)dictionary {
self = [super init];
if (self) {
NSMutableDictionary *parsedHours = [NSMutableDictionary new];

for (NSString *key in dictionary) {
id value = dictionary[key];

if ([value isKindOfClass:[NSArray class]]) {
NSArray *dayPairs = (NSArray *)value;
NSMutableArray *parsedDayPairs = [NSMutableArray new];

for (id pair in dayPairs) {
if ([pair isKindOfClass:[NSArray class]] && [pair count] == 2) {
NSString *start = pair[0];
NSString *end = pair[1];

if ([start isKindOfClass:[NSString class]] && [end isKindOfClass:[NSString class]]) {
[parsedDayPairs addObject:@[start, end]];
}
}
}

parsedHours[key] = [parsedDayPairs copy];
}
}

_hours = [parsedHours copy];
}
return self;
}

@end
2 changes: 1 addition & 1 deletion RadarSDK/RadarUtils.m
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ + (NSNumber *)timeZoneOffset {
}

+ (NSString *)sdkVersion {
return @"3.18.1";
return @"3.18.3";
}

+ (NSString *)deviceId {
Expand Down
2 changes: 1 addition & 1 deletion RadarSDKMotion.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'RadarSDKMotion'
s.version = '3.18.1'
s.version = '3.18.3'
s.summary = 'Motion detection plugin for RadarSDK, the leading geofencing and location tracking platform'
s.homepage = 'https://radar.com'
s.author = { 'Radar Labs, Inc.' => '[email protected]' }
Expand Down
2 changes: 2 additions & 0 deletions RadarSDKTests/RadarSDKTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -1114,6 +1114,8 @@ - (void)test_Radar_searchGeofences_success {
NSDictionary *geofenceDict = [geofence dictionaryValue];
XCTAssertNotNil(geofenceDict[@"geometryCenter"]);
XCTAssertNotNil(geofenceDict[@"geometryRadius"]);
XCTAssertNotNil(geofenceDict[@"operatingHours"]);


[expectation fulfill];
}];
Expand Down
24 changes: 24 additions & 0 deletions RadarSDKTests/Resources/search_geofences.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,30 @@
"metadata": {
"foo": "bar"
},
"operatingHours":{
"Mon":[
["03:43","12:12"],
["13:45","20:54"]
],
"Tue":[
["08:00","20:30"]
],
"Wed":[
["08:00","20:30"]
],
"Thu":[
["08:00","20:30"]
],
"Fri":[
["08:00","20:30"]
],
"Sat":[
["08:00","18:00"]
],
"Sun":[
["08:00","18:00"]
]
},
"tag": "station",
"externalId": "admiralty",
"geometry": {
Expand Down

0 comments on commit 3545c3c

Please sign in to comment.