react-native-radar 3.2.0 → 3.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -2,15 +2,15 @@
2
2
 
3
3
  [![npm](https://img.shields.io/npm/v/react-native-radar.svg)](https://www.npmjs.com/package/react-native-radar)
4
4
 
5
- [Radar](https://radar.io) is the leading geofencing and location tracking platform.
5
+ [Radar](https://radar.com) is the leading geofencing and location tracking platform.
6
6
 
7
7
  The Radar SDK abstracts away cross-platform differences between location services, allowing you to add geofencing, location tracking, trip tracking, geocoding, and search to your apps with just a few lines of code.
8
8
 
9
9
  ## Documentation
10
10
 
11
- See the Radar overview documentation [here](https://radar.io/documentation).
11
+ See the Radar overview documentation [here](https://radar.com/documentation).
12
12
 
13
- Then, see the Radar React Native module documentation [here](https://radar.io/documentation/sdk/react-native).
13
+ Then, see the Radar React Native module documentation [here](https://radar.com/documentation/sdk/react-native).
14
14
 
15
15
  ## Examples
16
16
 
@@ -18,4 +18,4 @@ See an example app in `example/`.
18
18
 
19
19
  ## Support
20
20
 
21
- Have questions? We're here to help! Email us at [support@radar.io](mailto:support@radar.io).
21
+ Have questions? We're here to help! Email us at [support@radar.com](mailto:support@radar.com).
@@ -18,7 +18,7 @@ android {
18
18
  minSdkVersion 16
19
19
  targetSdkVersion 31
20
20
  versionCode 1
21
- versionName '3.2.0'
21
+ versionName '3.2.1'
22
22
  }
23
23
  lintOptions {
24
24
  abortOnError false
@@ -45,5 +45,5 @@ repositories {
45
45
 
46
46
  dependencies {
47
47
  api 'com.facebook.react:react-native:+'
48
- api 'io.radar:sdk:3.2.3'
48
+ api 'io.radar:sdk:3.2.4'
49
49
  }
@@ -331,41 +331,165 @@ public class RNRadarModule extends ReactContextBaseJavaModule implements Permiss
331
331
  }
332
332
 
333
333
  @ReactMethod
334
- public void startTrip(ReadableMap optionsMap) {
334
+ public void startTrip(ReadableMap optionsMap, final Promise promise) {
335
335
  try {
336
336
  JSONObject optionsObj = RNRadarUtils.jsonForMap(optionsMap);
337
337
  RadarTripOptions options = RadarTripOptions.fromJson(optionsObj);
338
338
  Radar.startTrip(options, new Radar.RadarTripCallback() {
339
339
  @Override
340
340
  public void onComplete(@NonNull Radar.RadarStatus status, @Nullable RadarTrip trip, @Nullable RadarEvent[] events) {
341
-
341
+ if (promise == null) {
342
+ return;
343
+ }
344
+ try {
345
+ if (status == Radar.RadarStatus.SUCCESS) {
346
+ WritableMap map = Arguments.createMap();
347
+ map.putString("status", status.toString());
348
+ if (trip != null) {
349
+ map.putMap("trip", RNRadarUtils.mapForJson(trip.toJson()));
350
+ }
351
+ if (events != null) {
352
+ map.putArray("events", RNRadarUtils.arrayForJson(RadarEvent.toJson(events)));
353
+ }
354
+ promise.resolve(map);
355
+ } else {
356
+ promise.reject(status.toString(), status.toString());
357
+ }
358
+ } catch (JSONException e) {
359
+ Log.e(TAG, "JSONException", e);
360
+ promise.reject(Radar.RadarStatus.ERROR_SERVER.toString(), Radar.RadarStatus.ERROR_SERVER.toString());
361
+ }
342
362
  }
343
363
  });
344
364
  } catch (JSONException e) {
345
365
  Log.e(TAG, "JSONException", e);
366
+ promise.reject(Radar.RadarStatus.ERROR_BAD_REQUEST.toString(), Radar.RadarStatus.ERROR_BAD_REQUEST.toString());
346
367
  }
347
368
  }
348
369
 
349
370
  @ReactMethod
350
- public void completeTrip() {
371
+ public void completeTrip(final Promise promise) {
351
372
  Radar.completeTrip(new Radar.RadarTripCallback() {
352
373
  @Override
353
374
  public void onComplete(@NonNull Radar.RadarStatus status, @Nullable RadarTrip trip, @Nullable RadarEvent[] events) {
354
-
375
+ if (promise == null) {
376
+ return;
377
+ }
378
+ try {
379
+ if (status == Radar.RadarStatus.SUCCESS) {
380
+ WritableMap map = Arguments.createMap();
381
+ map.putString("status", status.toString());
382
+ if (trip != null) {
383
+ map.putMap("trip", RNRadarUtils.mapForJson(trip.toJson()));
384
+ }
385
+ if (events != null) {
386
+ map.putArray("events", RNRadarUtils.arrayForJson(RadarEvent.toJson(events)));
387
+ }
388
+ promise.resolve(map);
389
+ } else {
390
+ promise.reject(status.toString(), status.toString());
391
+ }
392
+ } catch (JSONException e) {
393
+ Log.e(TAG, "JSONException", e);
394
+ promise.reject(Radar.RadarStatus.ERROR_SERVER.toString(), Radar.RadarStatus.ERROR_SERVER.toString());
395
+ }
355
396
  }
356
397
  });
357
398
  }
358
399
 
359
400
  @ReactMethod
360
- public void cancelTrip() {
401
+ public void cancelTrip(final Promise promise) {
361
402
  Radar.cancelTrip(new Radar.RadarTripCallback() {
362
403
  @Override
363
404
  public void onComplete(@NonNull Radar.RadarStatus status, @Nullable RadarTrip trip, @Nullable RadarEvent[] events) {
364
-
405
+ if (promise == null) {
406
+ return;
407
+ }
408
+ try {
409
+ if (status == Radar.RadarStatus.SUCCESS) {
410
+ WritableMap map = Arguments.createMap();
411
+ map.putString("status", status.toString());
412
+ if (trip != null) {
413
+ map.putMap("trip", RNRadarUtils.mapForJson(trip.toJson()));
414
+ }
415
+ if (events != null) {
416
+ map.putArray("events", RNRadarUtils.arrayForJson(RadarEvent.toJson(events)));
417
+ }
418
+ promise.resolve(map);
419
+ } else {
420
+ promise.reject(status.toString(), status.toString());
421
+ }
422
+ } catch (JSONException e) {
423
+ Log.e(TAG, "JSONException", e);
424
+ promise.reject(Radar.RadarStatus.ERROR_SERVER.toString(), Radar.RadarStatus.ERROR_SERVER.toString());
425
+ }
365
426
  }
366
427
  });
367
428
  }
368
429
 
430
+ @ReactMethod
431
+ public void updateTrip(ReadableMap optionsMap, final Promise promise) {
432
+
433
+ try {
434
+ JSONObject optionsObj = RNRadarUtils.jsonForMap(optionsMap);
435
+ RadarTripOptions options = RadarTripOptions.fromJson(optionsObj.getJSONObject("options"));
436
+ RadarTrip.RadarTripStatus status = RadarTrip.RadarTripStatus.UNKNOWN;
437
+
438
+ if (optionsObj.has("status")) {
439
+ String statusStr = optionsObj.getString("status");
440
+ if (statusStr != null) {
441
+ if (statusStr.equalsIgnoreCase("started")) {
442
+ status = RadarTrip.RadarTripStatus.STARTED;
443
+ } else if (statusStr.equalsIgnoreCase("approaching")) {
444
+ status = RadarTrip.RadarTripStatus.APPROACHING;
445
+ } else if (statusStr.equalsIgnoreCase("arrived")) {
446
+ status = RadarTrip.RadarTripStatus.ARRIVED;
447
+ } else if (statusStr.equalsIgnoreCase("completed")) {
448
+ status = RadarTrip.RadarTripStatus.COMPLETED;
449
+ } else if (statusStr.equalsIgnoreCase("canceled")) {
450
+ status = RadarTrip.RadarTripStatus.CANCELED;
451
+ } else if (statusStr.equalsIgnoreCase("unknown")) {
452
+ status = RadarTrip.RadarTripStatus.UNKNOWN;
453
+ } else {
454
+ promise.reject(Radar.RadarStatus.ERROR_BAD_REQUEST.toString(), Radar.RadarStatus.ERROR_BAD_REQUEST.toString());
455
+ }
456
+ }
457
+ } else {
458
+ promise.reject(Radar.RadarStatus.ERROR_BAD_REQUEST.toString(), Radar.RadarStatus.ERROR_BAD_REQUEST.toString());
459
+ }
460
+
461
+ Radar.updateTrip(options, status, new Radar.RadarTripCallback() {
462
+ @Override
463
+ public void onComplete(@NonNull Radar.RadarStatus status, @Nullable RadarTrip trip, @Nullable RadarEvent[] events) {
464
+ if (promise == null) {
465
+ return;
466
+ }
467
+ try {
468
+ if (status == Radar.RadarStatus.SUCCESS) {
469
+ WritableMap map = Arguments.createMap();
470
+ map.putString("status", status.toString());
471
+ if (trip != null) {
472
+ map.putMap("trip", RNRadarUtils.mapForJson(trip.toJson()));
473
+ }
474
+ if (events != null) {
475
+ map.putArray("events", RNRadarUtils.arrayForJson(RadarEvent.toJson(events)));
476
+ }
477
+ promise.resolve(map);
478
+ } else {
479
+ promise.reject(status.toString(), status.toString());
480
+ }
481
+ } catch (JSONException e) {
482
+ Log.e(TAG, "JSONException", e);
483
+ promise.reject(Radar.RadarStatus.ERROR_SERVER.toString(), Radar.RadarStatus.ERROR_SERVER.toString());
484
+ }
485
+ }
486
+ });
487
+ } catch (JSONException e) {
488
+ Log.e(TAG, "JSONException", e);
489
+ promise.reject(Radar.RadarStatus.ERROR_BAD_REQUEST.toString(), Radar.RadarStatus.ERROR_BAD_REQUEST.toString());
490
+ }
491
+ }
492
+
369
493
  @ReactMethod
370
494
  public void getContext(final Promise promise) {
371
495
  if (promise == null) {
@@ -1 +1 @@
1
- github "radarlabs/radar-sdk-ios" "3.1.7"
1
+ github "radarlabs/radar-sdk-ios" "3.2.3"
package/ios/RNRadar.m CHANGED
@@ -314,17 +314,140 @@ RCT_EXPORT_METHOD(rejectEvent:(NSString *)eventId) {
314
314
  [Radar rejectEventId:eventId];
315
315
  }
316
316
 
317
- RCT_EXPORT_METHOD(startTrip:(NSDictionary *)optionsDict) {
317
+ RCT_EXPORT_METHOD(startTrip:(NSDictionary *)optionsDict resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) {
318
318
  RadarTripOptions *options = [RadarTripOptions tripOptionsFromDictionary:optionsDict];
319
- [Radar startTripWithOptions:options];
319
+
320
+ __block RCTPromiseResolveBlock resolver = resolve;
321
+ __block RCTPromiseRejectBlock rejecter = reject;
322
+
323
+ [Radar startTripWithOptions:options completionHandler:^(RadarStatus status, RadarTrip * _Nullable trip, NSArray<RadarEvent *> * _Nullable events) {
324
+
325
+ if (status == RadarStatusSuccess && resolver) {
326
+ NSMutableDictionary *dict = [NSMutableDictionary new];
327
+ [dict setObject:[Radar stringForStatus:status] forKey:@"status"];
328
+ if (trip) {
329
+ [dict setObject:[trip dictionaryValue] forKey:@"trip"];
330
+ }
331
+ if (events) {
332
+ [dict setObject:[RadarEvent arrayForEvents:events] forKey:@"events"];
333
+ }
334
+ resolver(dict);
335
+ } else if (rejecter) {
336
+ rejecter([Radar stringForStatus:status], [Radar stringForStatus:status], nil);
337
+ }
338
+ resolver = nil;
339
+ rejecter = nil;
340
+ }];
320
341
  }
321
342
 
322
- RCT_EXPORT_METHOD(completeTrip) {
323
- [Radar completeTrip];
343
+ RCT_EXPORT_METHOD(completeTrip:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) {
344
+
345
+ __block RCTPromiseResolveBlock resolver = resolve;
346
+ __block RCTPromiseRejectBlock rejecter = reject;
347
+
348
+ [Radar completeTripWithCompletionHandler:^(RadarStatus status, RadarTrip * _Nullable trip, NSArray<RadarEvent *> * _Nullable events) {
349
+ if (status == RadarStatusSuccess && resolver) {
350
+ NSMutableDictionary *dict = [NSMutableDictionary new];
351
+ [dict setObject:[Radar stringForStatus:status] forKey:@"status"];
352
+ if (trip) {
353
+ [dict setObject:[trip dictionaryValue] forKey:@"trip"];
354
+ }
355
+ if (events) {
356
+ [dict setObject:[RadarEvent arrayForEvents:events] forKey:@"events"];
357
+ }
358
+ resolver(dict);
359
+ } else if (rejecter) {
360
+ rejecter([Radar stringForStatus:status], [Radar stringForStatus:status], nil);
361
+ }
362
+ resolver = nil;
363
+ rejecter = nil;
364
+ }];
324
365
  }
325
366
 
326
- RCT_EXPORT_METHOD(cancelTrip) {
327
- [Radar cancelTrip];
367
+ RCT_EXPORT_METHOD(cancelTrip:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) {
368
+ __block RCTPromiseResolveBlock resolver = resolve;
369
+ __block RCTPromiseRejectBlock rejecter = reject;
370
+
371
+ [Radar cancelTripWithCompletionHandler:^(RadarStatus status, RadarTrip * _Nullable trip, NSArray<RadarEvent *> * _Nullable events) {
372
+ if (status == RadarStatusSuccess && resolver) {
373
+ NSMutableDictionary *dict = [NSMutableDictionary new];
374
+ [dict setObject:[Radar stringForStatus:status] forKey:@"status"];
375
+ if (trip) {
376
+ [dict setObject:[trip dictionaryValue] forKey:@"trip"];
377
+ }
378
+ if (events) {
379
+ [dict setObject:[RadarEvent arrayForEvents:events] forKey:@"events"];
380
+ }
381
+ resolver(dict);
382
+ } else if (rejecter) {
383
+ rejecter([Radar stringForStatus:status], [Radar stringForStatus:status], nil);
384
+ }
385
+ resolver = nil;
386
+ rejecter = nil;
387
+ }];
388
+ }
389
+
390
+ RCT_EXPORT_METHOD(updateTrip:(NSDictionary *)optionsDict resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) {
391
+ if (optionsDict == nil) {
392
+ if (reject) {
393
+ reject([Radar stringForStatus:RadarStatusErrorBadRequest], [Radar stringForStatus:RadarStatusErrorBadRequest], nil);
394
+ }
395
+
396
+ return;
397
+ }
398
+
399
+ RadarTripOptions *options = [RadarTripOptions tripOptionsFromDictionary:optionsDict[@"options"]];
400
+ NSString *statusStr = optionsDict[@"status"];
401
+
402
+ RadarTripStatus status = RadarTripStatusUnknown;
403
+ if (statusStr) {
404
+ if ([statusStr isEqualToString:@"started"]) {
405
+ status = RadarTripStatusStarted;
406
+ } else if ([statusStr isEqualToString:@"approaching"]) {
407
+ status = RadarTripStatusApproaching;
408
+ } else if ([statusStr isEqualToString:@"arrived"]) {
409
+ status = RadarTripStatusArrived;
410
+ } else if ([statusStr isEqualToString:@"completed"]) {
411
+ status = RadarTripStatusCompleted;
412
+ } else if ([statusStr isEqualToString:@"canceled"]) {
413
+ status = RadarTripStatusCanceled;
414
+ } else if ([statusStr isEqualToString:@"unknown"]) {
415
+ status = RadarTripStatusUnknown;
416
+ } else {
417
+ if (reject) {
418
+ reject([Radar stringForStatus:RadarStatusErrorBadRequest], [Radar stringForStatus:RadarStatusErrorBadRequest], nil);
419
+ }
420
+
421
+ return;
422
+ }
423
+ } else {
424
+ if (reject) {
425
+ reject([Radar stringForStatus:RadarStatusErrorBadRequest], [Radar stringForStatus:RadarStatusErrorBadRequest], nil);
426
+ }
427
+
428
+ return;
429
+ }
430
+
431
+ __block RCTPromiseResolveBlock resolver = resolve;
432
+ __block RCTPromiseRejectBlock rejecter = reject;
433
+
434
+ [Radar updateTripWithOptions:options status:status completionHandler:^(RadarStatus status, RadarTrip * _Nullable trip, NSArray<RadarEvent *> * _Nullable events) {
435
+ if (status == RadarStatusSuccess && resolver) {
436
+ NSMutableDictionary *dict = [NSMutableDictionary new];
437
+ [dict setObject:[Radar stringForStatus:status] forKey:@"status"];
438
+ if (trip) {
439
+ [dict setObject:[trip dictionaryValue] forKey:@"trip"];
440
+ }
441
+ if (events) {
442
+ [dict setObject:[RadarEvent arrayForEvents:events] forKey:@"events"];
443
+ }
444
+ resolver(dict);
445
+ } else if (rejecter) {
446
+ rejecter([Radar stringForStatus:status], [Radar stringForStatus:status], nil);
447
+ }
448
+ resolver = nil;
449
+ rejecter = nil;
450
+ }];
328
451
  }
329
452
 
330
453
  RCT_EXPORT_METHOD(getContext:(NSDictionary *)locationDict resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) {
package/js/index.js CHANGED
@@ -74,6 +74,10 @@ const cancelTrip = () => (
74
74
  NativeModules.RNRadar.cancelTrip()
75
75
  );
76
76
 
77
+ const updateTrip = options => (
78
+ NativeModules.RNRadar.updateTrip(options)
79
+ );
80
+
77
81
  const acceptEvent = (eventId, verifiedPlaceId) => (
78
82
  NativeModules.RNRadar.acceptEvent(eventId, verifiedPlaceId)
79
83
  );
@@ -148,6 +152,7 @@ const Radar = {
148
152
  acceptEvent,
149
153
  rejectEvent,
150
154
  startTrip,
155
+ updateTrip,
151
156
  completeTrip,
152
157
  cancelTrip,
153
158
  getContext,
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "react-native-radar",
3
3
  "description": "React Native module for Radar, the leading geofencing and location tracking platform",
4
- "homepage": "https://radar.io",
4
+ "homepage": "https://radar.com",
5
5
  "license": "Apache-2.0",
6
- "version": "3.2.0",
6
+ "version": "3.2.1",
7
7
  "main": "js/index.js",
8
8
  "files": [
9
9
  "android",
@@ -15,5 +15,5 @@ Pod::Spec.new do |s|
15
15
  s.platform = :ios, "10.0"
16
16
 
17
17
  s.dependency "React"
18
- s.dependency "RadarSDK", "~> 3.2.1"
18
+ s.dependency "RadarSDK", "~> 3.2.3"
19
19
  end