Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions RadarSDK/Include/RadarGeofence.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
*/
@property (nullable, copy, nonatomic, readonly) RadarOperatingHours *operatingHours;

@property (nonatomic, readonly) float altitude;

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

Expand Down
2 changes: 2 additions & 0 deletions RadarSDK/Include/RadarUser.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ typedef NS_ENUM(NSInteger, RadarActivityType);
*/
@property (nullable, copy, nonatomic, readonly) NSArray<RadarGeofence *> *geofences;

@property (nullable, copy, nonatomic, readonly) NSArray<RadarGeofence *> *latestGeofencesDwelled;

/**
The user's current place. May be `nil` if the user is not at a place or if Places is not enabled.

Expand Down
12 changes: 11 additions & 1 deletion RadarSDK/RadarAPIClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -541,10 +541,20 @@ - (void)makeTrackRequestWithParams:(NSDictionary *)params
RadarConfig *config = [RadarConfig fromDictionary:res];

id eventsObj = res[@"events"];
id locationMetadataObj = res[@"locationMetadata"];
id userObj = res[@"user"];
if ([userObj isKindOfClass:[NSDictionary class]]) {
NSMutableDictionary *mutableUserObj = [userObj mutableCopy];
mutableUserObj[@"metadata"] = locationMetadata;
if (locationMetadataObj && [locationMetadataObj isKindOfClass:[NSDictionary class]]) {
NSMutableDictionary *mutableLocationMetadata = [locationMetadata mutableCopy];
for (NSString *key in locationMetadataObj) {
mutableLocationMetadata[key] = locationMetadataObj[key];
}
mutableUserObj[@"metadata"] = mutableLocationMetadata;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmmm, is user.metadata the best spot for this. Could be convinced yes, but some clients might be listening and setting user metadata based on this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that is a very unlikely pattern for people to use.
Also this behavior has already been in our SDK since the start of SDK motion, this PR just adds more data from the server into the same dictionary.
So in a sense this PR does not drastically change the return of the user.metadata.

A more "full bodies" approach may include us defining a type wrapping the CLLocation type as the returned type but that feels very heavy handed for the task at hand.

} else {
mutableUserObj[@"metadata"] = locationMetadata;
}

userObj = mutableUserObj;
}
id nearbyGeofencesObj = res[@"nearbyGeofences"];
Expand Down
3 changes: 2 additions & 1 deletion RadarSDK/RadarGeofence+Internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
externalId:(NSString *_Nullable)externalId
metadata:(NSDictionary *_Nullable)metadata
operatingHours:(RadarOperatingHours *_Nullable)operatingHours
geometry:(RadarGeofenceGeometry *_Nonnull)geometry;
geometry:(RadarGeofenceGeometry *_Nonnull)geometry
altitude:(float)altitude;
- (instancetype _Nullable)initWithObject:(id _Nonnull)object;

@end
15 changes: 13 additions & 2 deletions RadarSDK/RadarGeofence.m
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ - (instancetype _Nullable)initWithId:(NSString *)_id
externalId:(NSString *_Nullable)externalId
metadata:(NSDictionary *_Nullable)metadata
operatingHours: (RadarOperatingHours *_Nullable) operatingHours
geometry:(RadarGeofenceGeometry *_Nonnull)geometry {
geometry:(RadarGeofenceGeometry *_Nonnull)geometry
altitude:(float)altitude {
self = [super init];
if (self) {
__id = _id;
Expand All @@ -48,6 +49,7 @@ - (instancetype _Nullable)initWithId:(NSString *)_id
_metadata = metadata;
_operatingHours = operatingHours;
_geometry = geometry;
_altitude = altitude;
}
return self;
}
Expand All @@ -66,6 +68,7 @@ - (instancetype _Nullable)initWithObject:(id)object {
NSDictionary *metadata;
RadarOperatingHours *operatingHours;
RadarGeofenceGeometry *geometry;
float altitude = 0.0;

id idObj = dict[@"_id"];
if (idObj && [idObj isKindOfClass:[NSString class]]) {
Expand Down Expand Up @@ -139,7 +142,12 @@ - (instancetype _Nullable)initWithObject:(id)object {
}
}

return [[RadarGeofence alloc] initWithId:_id description:description tag:tag externalId:externalId metadata:metadata operatingHours:operatingHours geometry:geometry];
id altitudeObj = dict[@"altitude"];
if (altitudeObj && [altitudeObj isKindOfClass:[NSNumber class]]) {
altitude = [((NSNumber *)altitudeObj) floatValue];
}

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

- (NSMutableArray<RadarCoordinate *> *)getPolygonCoordinates:(NSDictionary *)dict {
Expand Down Expand Up @@ -239,6 +247,9 @@ - (NSDictionary *)dictionaryValue {
}
[dict setValue:@"Polygon" forKey:@"type"];
}
if (self.altitude) {
[dict setValue:@(self.altitude) forKey:@"altitude"];
}

return dict;
}
Expand Down
3 changes: 2 additions & 1 deletion RadarSDK/RadarUser+Internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
trip:(RadarTrip *_Nullable)trip
debug:(BOOL)debug
fraud:(RadarFraud *_Nullable)fraud
altitude:(double)altitude;
altitude:(double)altitude
latestGeofencesDwelled:(nullable NSArray<RadarGeofence *> *)latestGeofencesDwelled;
- (instancetype _Nullable)initWithObject:(id _Nonnull)object;

@end
15 changes: 13 additions & 2 deletions RadarSDK/RadarUser.m
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ - (instancetype _Nullable)initWithId:(NSString *)_id
trip:(RadarTrip *_Nullable)trip
debug:(BOOL)debug
fraud:(RadarFraud *_Nullable)fraud
altitude:(double)altitude {
altitude:(double)altitude
latestGeofencesDwelled:(nullable NSArray<RadarGeofence *> *)latestGeofencesDwelled {
self = [super init];
if (self) {
__id = _id;
Expand All @@ -70,6 +71,7 @@ - (instancetype _Nullable)initWithId:(NSString *)_id
_debug = debug;
_fraud = fraud;
_altitude = altitude;
_latestGeofencesDwelled = latestGeofencesDwelled;
}
return self;
}
Expand All @@ -89,6 +91,7 @@ - (instancetype _Nullable)initWithObject:(NSObject *)object {
CLLocation *location;
RadarActivityType activityType = RadarActivityTypeUnknown;
NSArray<RadarGeofence *> *geofences;
NSArray<RadarGeofence *> *latestGeofencesDwelled;
RadarPlace *place;
NSArray<RadarBeacon *> *beacons;
BOOL stopped = NO;
Expand Down Expand Up @@ -195,6 +198,11 @@ - (instancetype _Nullable)initWithObject:(NSObject *)object {
geofences = [RadarGeofence geofencesFromObject:geofencesObj];
}

id latestGeofencesDwelledObj = dict[@"latestGeofencesDwelled"];
if (latestGeofencesDwelledObj && [latestGeofencesDwelledObj isKindOfClass:[NSArray class]]) {
latestGeofencesDwelled = [RadarGeofence geofencesFromObject:latestGeofencesDwelledObj];
}

id placeObj = dict[@"place"];
place = [[RadarPlace alloc] initWithObject:placeObj];

Expand Down Expand Up @@ -328,7 +336,8 @@ - (instancetype _Nullable)initWithObject:(NSObject *)object {
trip:trip
debug:debug
fraud:fraud
altitude:altitude];
altitude:altitude
latestGeofencesDwelled:latestGeofencesDwelled];
}

return nil;
Expand All @@ -349,6 +358,8 @@ - (NSDictionary *)dictionaryValue {
[dict setValue:[Radar stringForActivityType:self.activityType] forKey:@"activityType"];
NSArray *geofencesArr = [RadarGeofence arrayForGeofences:self.geofences];
[dict setValue:geofencesArr forKey:@"geofences"];
NSArray *latestGeofencesDwelledArr = [RadarGeofence arrayForGeofences:self.latestGeofencesDwelled];
[dict setValue:latestGeofencesDwelledArr forKey:@"latestGeofencesDwelled"];
if (self.place) {
NSDictionary *placeDict = [self.place dictionaryValue];
[dict setValue:placeDict forKey:@"place"];
Expand Down