Skip to content
This repository was archived by the owner on Mar 14, 2019. It is now read-only.

Commit

Permalink
feat(): allow to check for previous session
Browse files Browse the repository at this point in the history
* [Shared] Updated README.md

* [Shared] Addede 'hasActiveSession' function
  • Loading branch information
PaolinoD authored and ihadeed committed Mar 17, 2017
1 parent 82ce529 commit 2e09892
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 7 deletions.
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,19 @@ postRequest(path, body, success, error)
* **body**: The reqeust body
Makes a POST request to LinkedIn REST API. You can view the possible paths [here](https://developer.linkedin.com/docs).

### viewProfile
### openProfile
```js
viewProfile(memberId)
openProfile(memberId)
```
* **memberId**: Member Id of the user
Opens a member's profile in the LinkedIn app.

### hasActiveSession
```js
hasActiveSession()
```
Function returning true if an active session is found, false otherwise. Should be used to avoid unnecessary login


## Example
```js
Expand Down
13 changes: 13 additions & 0 deletions src/android/LinkedIn.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.apache.cordova.CordovaInterface;
import org.apache.cordova.CordovaPlugin;
import org.apache.cordova.CallbackContext;
import org.apache.cordova.PluginResult;

import org.apache.cordova.CordovaWebView;
import org.json.JSONArray;
Expand Down Expand Up @@ -62,6 +63,8 @@ public boolean execute(final String action, JSONArray args, CallbackContext call
getRequest(args, callbackContext);
} else if(action.equals("postRequest")) {
postRequest(args, callbackContext);
} else if(action.equals("hasActiveSession")) {
hasActiveSession(callbackContext);
} else {
return false;
}
Expand Down Expand Up @@ -185,4 +188,14 @@ private void postRequest(final JSONArray args, CallbackContext callbackContext)
callbackContext.error(e.getMessage());
}
}

private void hasActiveSession(CallbackContext callbackContext) {
try {
LISession session = liSessionManager.getSession();
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, session.isValid()));
} catch (Exception e) {
//Should never happen
callbackContext.error(e.getMessage());
}
}
}
1 change: 1 addition & 0 deletions src/ios/LinkedIn.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
- (void) getRequest: (CDVInvokedUrlCommand *) command;
- (void) postRequest: (CDVInvokedUrlCommand *) command;
- (void) openProfile: (CDVInvokedUrlCommand *) command;
- (void) hasActiveSession: (CDVInvokedUrlCommand *) command;
@end
18 changes: 18 additions & 0 deletions src/ios/LinkedIn.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#import <Cordova/CDV.h>
#import "LinkedIn.h"
#import <linkedin-sdk/LISDKSessionManager.h>
#import <linkedin-sdk/LISDKSession.h>
#import <linkedin-sdk/LISDKAPIHelper.h>
#import <linkedin-sdk/LISDKAPIResponse.h>
#import <linkedin-sdk/LISDKAPIError.h>
Expand Down Expand Up @@ -110,4 +111,21 @@ - (void)openProfile:(CDVInvokedUrlCommand*)command
}];
}

- (void)hasActiveSession:(CDVInvokedUrlCommand*)command
{
[self.commandDelegate runInBackground:^{
CDVPluginResult *result;
LISDKSession *session = [[LISDKSessionManager sharedInstance] session];
if(session != nil) {
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsBool:[session isValid]];
} else {
//Should never happen
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsBool:@"Cannot verify if a preceding session is present"];
}
[self.commandDelegate sendPluginResult:result callbackId:command.callbackId];

}];

}

@end
14 changes: 9 additions & 5 deletions www/LinkedIn.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,28 @@ var exec = require('cordova/exec');

module.exports = {

login: function(scopes, promptToInstall, success, error) {
login: function (scopes, promptToInstall, success, error) {
exec(success, error, "LinkedIn", "login", [scopes, promptToInstall]);
},

logout: function() {
logout: function () {
exec(null, null, "LinkedIn", "logout", []);
},

getRequest: function(url, success, error) {
getRequest: function (url, success, error) {
exec(success, error, "LinkedIn", "getRequest", [url]);
},

postRequest: function(url, body, success, error) {
postRequest: function (url, body, success, error) {
exec(success, error, "LinkedIn", "postRequest", [url, body]);
},

openProfile: function(memberId, success, error) {
openProfile: function (memberId, success, error) {
exec(success, error, "LinkedIn", "openProfile", [memberId]);
},

hasActiveSession: function (success, error) {
exec(success, error, "LinkedIn", "hasActiveSession", []);
}

};

0 comments on commit 2e09892

Please sign in to comment.