angular-linkedin-sdk

0.2.0 • Public • Published

angular-linkedin-sdk

An Angular (Angular 2 & Angular 4) wrapper for LinkedIn official Javascript SDK. To know more about the official documentation please visit here.

All features of the original Javascript SDK are available through the service LinkedInService. The IN.Event.on(..) and IN.Event.onOnce(...) handler registration methods aren't exposed from original API, because you should subscribe to the isInitialized$ and isUserAuthenticated$ observables instead.

This library is published in an early state. The exposed interfaces might still be subject to change. Please don't expect a stable interface before version 0.2.x

NPM NPM

Build Status codecov dependencies Status devDependencies Status peerDependencies Status Build Status Build Status

Demo

To try the out the demo project clone the repository and run

$ npm install

Edit the demo/src/app/app.module.ts and paste you own LinkedIn API key

{ provide'apiKey', useValue'YOUR_API_KEY' },

followed by

$ npm run-script demo

Install

$ npm install angular-linkedin-sdk

ES2015 / UMD

If your project is based on Angular CLI / WebPack everything will work as expected.

SystemJS / UMD support is not yet available, but planned for version 0.2.x

Angular Universal

Server side rendering is not supported, since the original LinkedIn Javascript SDK is using JSONP and can't run outside browser environments.

We are working on browser-agnostic support for the library. As mentioned it's not up to us to support server side rendering but in future release we will avoid initialization on non-browser platforms to make the library invisible. It might cause crashes in Angular Universal environments because of DOCUMENT and window object usage. You can specify whether to run in browser or server in the providers as seen in the Usage example.

Usage

In the Angular AppModule:

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
 
// Import the library
import { LinkedInSdkModule } from 'angular-linkedin-sdk';
 
@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
 
    // Specify your library as an import
    LinkedInSdkModule
  ],
  providers: [
    // Inject apiKey and, optionally, authorize to integrate with LinkedIN official API
    { provide: 'apiKey', useValue: 'YOUR_API_KEY' },
    { provide: 'authorize', useValue: 'true/false' }, // OPTIONAL by default: false
    { provide: 'isServer', useValue: 'true/false' }  // OPTIONAL by default: false
  ],
  bootstrap: [AppComponent]
})
export class AppModule { }

LinkedInService

import {
    LinkedInService
} from 'angular-linkedin-sdk';
 
export class AppComponent implements OnInit {
    public isUserAuthenticated;
    public constructor(private _linkedInService: LinkedInService) {
    }
}    

API

isInitialized

An observable that emits true and completes when library has finished loading.

Example

public subscribeToisInitialized(){
    this._linkedInService.isInitialized$.subscribe({
    next: (state) => {
      // state will always return true when API finishes loading
    },
    complete: () => {
      // Completed
    }
  });
}

isUserAuthenticated

An observable that has an initial value of undefined. It emits a boolean value when the library has finished loading and when a login or logout is performed.

Example

ngOnInit() {
  // Subscribe to any values the observable will emit about logged in state
  this._linkedInService.isUserAuthenticated$.subscribe({
    next: (state) => {
      this.isUserAuthenticated = state;
    }
  });
}

getSdkIN

Gets the IN variable from the LinkedIN SDK. Allows access to variables from the SDK that are or are not documented officially.

Example

public getApiKeyFromSdkIN() {
    // Retrieve the API key used in the library through the SDK IN variable
    this.apiKey = this._linkedInService.getSdkIN().ENV.auth.api_key;
  }

login

Returns an observable that emits true and completes when authenticated. Waits for the library to finish loading. isUserAuthenticated$ also emits an updated value.

Example

public subscribeToLogin(){
  this._linkedInService.login().subscribe({
    next: (state) => {
      // state will always return true when login completed 
    },
    complete: () => {
      // Completed
    }
  });
}

logout

Returns an observable that emits with no value and completes when logout is finished. Waits for the library to finish loading. isUserAuthenticated$ also emits an updated value.

Example

public subscribeToLogout(){
  this._linkedInService.logout().subscribe({
    next: () => {
      // does not emit a value 
    },
    complete: () => {
      // Completed
    }
  });
}

raw

Enables authenticated calls to the LinkedIn REST API using the generic call wrapper. The original fluent API is fully encapsulated.

Parameters

  • url The API URL to invoke: should not include https://api.linkedin.com/v1.

Example

public rawApiCall(){
    const url = '/people/~?format=json';
    this._linkedInService.raw(url)
      .asObservable()
        .subscribe({
          next: (data) => {
            console.log(data);
          },
          error: (err) => {
            console.log(err);
          },
          complete: () => {
            console.log('RAW API call completed');
          }
        });
}

refresh

Refreshes a member token for an additional 30 minutes. Repeated continual use of the refresh() function to keep a member indefinitely logged in can result in your application being disabled. Use this call sparingly.

Example

public refresh() {
    this._linkedInService.refresh().subscribe({
      next: (value) => {
        console.log(`Refresh result: ${value}`);
      },
      complete: () => {
        console.log('Refresh call completed');
      }
    });
  }

Contribution

We are always looking for quality contributions and will be happy to accept your Pull Requests. For now, please make sure your PR has accompanying tests and all the tests are passing.

We will setup a CI system for the build very soon.

License

MIT © Evodeck Software

Evodeck Software

Package Sidebar

Install

npm i angular-linkedin-sdk

Weekly Downloads

36

Version

0.2.0

License

MIT

Unpacked Size

89.2 kB

Total Files

43

Last publish

Collaborators

  • rutejacinto
  • sirwalt