Example usage for com.facebook.react.bridge Promise resolve

List of usage examples for com.facebook.react.bridge Promise resolve

Introduction

In this page you can find the example usage for com.facebook.react.bridge Promise resolve.

Prototype

void resolve(@Nullable Object value);

Source Link

Document

Successfully resolve the Promise with an optional value.

Usage

From source file:by.iba.gomel.avkhonia.MFReactNativeBind.WLResourceRequestRN.java

License:Apache License

@ReactMethod
public void asyncRequestWithURL(String url, String method, final Promise promise) {
    try {/*ww  w.j  av  a2  s.c o  m*/
        Log.d("IBATimesheet", "REQUEST TO MFP - " + url);
        WLResourceRequest request = new WLResourceRequest(URI.create(url), method, DEFAULT_TIMEOUT);
        request.send(new WLResponseListener() {
            public void onSuccess(WLResponse response) {
                try {
                    promise.resolve(response.getResponseText());
                    Log.d("Success", response.getResponseText());
                } catch (Exception e) {
                    Log.d("IBATimesheet", "ERROR PROMISE RESOLVE: " + e);
                }
            }

            public void onFailure(WLFailResponse response) {
                promise.reject(response.getErrorStatusCode(),
                        response.getErrorMsg() + " - " + response.getErrorStatusCode());
                Log.d("Failure", response.getErrorMsg());
            }
        });
    } catch (IllegalViewOperationException e) {
        promise.reject("failure", e.getMessage(), e);
    }
}

From source file:by.iba.gomel.avkhonia.MFReactNativeBind.WLResourceRequestRN.java

License:Apache License

@ReactMethod
public void asyncRequestWithURLBody(String url, String method, String params, final Promise promise) {
    try {//w  w  w . j av  a2 s .  com
        Log.d("IBATimesheet", "REQUEST TO MFP - " + url);
        String logbody = params;
        while (logbody.length() > 400) {
            Log.d("IBATimesheet", "REQUEST BODY - " + logbody.substring(0, 400));
            logbody = logbody.substring(400);
        }
        Log.d("IBATimesheet", "REQUEST BODY - " + logbody);
        WLResourceRequest request = new WLResourceRequest(URI.create(url), method, DEFAULT_TIMEOUT);
        request.send(new JSONObject(params), new WLResponseListener() {
            public void onSuccess(WLResponse response) {
                promise.resolve(response.getResponseText());
                Log.d("Success", response.getResponseText());
            }

            public void onFailure(WLFailResponse response) {
                promise.reject(response.getErrorStatusCode(),
                        response.getErrorMsg() + " - " + response.getErrorStatusCode());
                Log.d("Failure", response.getErrorMsg());
            }
        });
    } catch (Exception e) {
        promise.reject("failure", e.getMessage(), e);
    }
}

From source file:com.amazonaws.reactnative.dynamodb.AWSRNDynamoDBClient.java

License:Open Source License

@ReactMethod
public void DeleteTable(final ReadableMap options, final Promise promise) {
    try {//from   ww  w .  j  a v a2  s. co m
        final DeleteTableRequest request = gson.fromJson(
                new JSONObject(AWSRNClientMarshaller.readableMapToMap(options)).toString(),
                DeleteTableRequest.class);
        final DeleteTableResult response = dynamodbClient.deleteTable(request);
        final WritableMap map = AWSRNClientMarshaller.jsonToReact(new JSONObject(gson.toJson(response)));
        promise.resolve(map);
    } catch (Exception e) {
        promise.reject(e);
        return;
    }
}

From source file:com.amazonaws.reactnative.dynamodb.AWSRNDynamoDBClient.java

License:Open Source License

@ReactMethod
public void BatchGetItem(final ReadableMap options, final Promise promise) {
    try {// w  ww.jav  a 2 s .  c o  m
        final BatchGetItemRequest request = gson.fromJson(
                new JSONObject(AWSRNClientMarshaller.readableMapToMap(options)).toString(),
                BatchGetItemRequest.class);
        final BatchGetItemResult response = dynamodbClient.batchGetItem(request);
        final WritableMap map = AWSRNClientMarshaller.jsonToReact(new JSONObject(gson.toJson(response)));
        promise.resolve(map);
    } catch (Exception e) {
        promise.reject(e);
        return;
    }
}

From source file:com.amazonaws.reactnative.dynamodb.AWSRNDynamoDBClient.java

License:Open Source License

@ReactMethod
public void DescribeTable(final ReadableMap options, final Promise promise) {
    try {//from  ww  w  .  j  a va2s .  c  o m
        final DescribeTableRequest request = gson.fromJson(
                new JSONObject(AWSRNClientMarshaller.readableMapToMap(options)).toString(),
                DescribeTableRequest.class);
        final DescribeTableResult response = dynamodbClient.describeTable(request);
        final WritableMap map = AWSRNClientMarshaller.jsonToReact(new JSONObject(gson.toJson(response)));
        promise.resolve(map);
    } catch (Exception e) {
        promise.reject(e);
        return;
    }
}

From source file:com.amazonaws.reactnative.dynamodb.AWSRNDynamoDBClient.java

License:Open Source License

@ReactMethod
public void PutItem(final ReadableMap options, final Promise promise) {
    try {/*from w w  w. ja  va2  s.c om*/
        final PutItemRequest request = gson.fromJson(
                new JSONObject(AWSRNClientMarshaller.readableMapToMap(options)).toString(),
                PutItemRequest.class);
        final PutItemResult response = dynamodbClient.putItem(request);
        final WritableMap map = AWSRNClientMarshaller.jsonToReact(new JSONObject(gson.toJson(response)));
        promise.resolve(map);
    } catch (Exception e) {
        promise.reject(e);
        return;
    }
}

From source file:com.amazonaws.reactnative.dynamodb.AWSRNDynamoDBClient.java

License:Open Source License

@ReactMethod
public void Query(final ReadableMap options, final Promise promise) {
    try {/*from  w  ww.  j a  v a  2 s .c o m*/
        final QueryRequest request = gson.fromJson(
                new JSONObject(AWSRNClientMarshaller.readableMapToMap(options)).toString(), QueryRequest.class);
        final QueryResult response = dynamodbClient.query(request);
        final WritableMap map = AWSRNClientMarshaller.jsonToReact(new JSONObject(gson.toJson(response)));
        promise.resolve(map);
    } catch (Exception e) {
        promise.reject(e);
        return;
    }
}

From source file:com.amazonaws.reactnative.dynamodb.AWSRNDynamoDBClient.java

License:Open Source License

@ReactMethod
public void Scan(final ReadableMap options, final Promise promise) {
    try {//ww  w  . j a v  a 2 s. co  m
        final ScanRequest request = gson.fromJson(
                new JSONObject(AWSRNClientMarshaller.readableMapToMap(options)).toString(), ScanRequest.class);
        final ScanResult response = dynamodbClient.scan(request);
        final WritableMap map = AWSRNClientMarshaller.jsonToReact(new JSONObject(gson.toJson(response)));
        promise.resolve(map);
    } catch (Exception e) {
        promise.reject(e);
        return;
    }
}

From source file:com.amazonaws.reactnative.dynamodb.AWSRNDynamoDBClient.java

License:Open Source License

@ReactMethod
public void DeleteItem(final ReadableMap options, final Promise promise) {
    try {/*ww w.  ja v  a2s . c om*/
        final DeleteItemRequest request = gson.fromJson(
                new JSONObject(AWSRNClientMarshaller.readableMapToMap(options)).toString(),
                DeleteItemRequest.class);
        final DeleteItemResult response = dynamodbClient.deleteItem(request);
        final WritableMap map = AWSRNClientMarshaller.jsonToReact(new JSONObject(gson.toJson(response)));
        promise.resolve(map);
    } catch (Exception e) {
        promise.reject(e);
        return;
    }
}

From source file:com.amazonaws.reactnative.dynamodb.AWSRNDynamoDBClient.java

License:Open Source License

@ReactMethod
public void UpdateItem(final ReadableMap options, final Promise promise) {
    try {/*  w  w  w  . j a v  a  2s .co  m*/
        final UpdateItemRequest request = gson.fromJson(
                new JSONObject(AWSRNClientMarshaller.readableMapToMap(options)).toString(),
                UpdateItemRequest.class);
        final UpdateItemResult response = dynamodbClient.updateItem(request);
        final WritableMap map = AWSRNClientMarshaller.jsonToReact(new JSONObject(gson.toJson(response)));
        promise.resolve(map);
    } catch (Exception e) {
        promise.reject(e);
        return;
    }
}