Skip to content

Commit

Permalink
Merge pull request #6 from rubenCodeforges/bugfix/prod-build-warning-#4
Browse files Browse the repository at this point in the history
Fixes issue #3 and #4
  • Loading branch information
rubenCodeforges authored Jul 14, 2017
2 parents 5470810 + 3f453b2 commit fa55a43
Show file tree
Hide file tree
Showing 10 changed files with 95 additions and 68 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,5 @@ testem.log
#System Files
.DS_Store
Thumbs.db
/compiled
*.metadata.json
4 changes: 3 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
node_modules
src
.idea
.idea
examples
compiled
31 changes: 22 additions & 9 deletions README.MD
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
### Angular 2 Google api module (ng-gapi)
### Angular 4 Google api module (ng-gapi)

This module will add the google api to your project.
It wraps the Gapi in to a service layer allowing to work with Gapi
in a Angular 2+ project.
in a Angular 4+ project.

#### Latest change

- Requires now Typescript version 2.3 or higher
- Requires Angular4 or higher

#### Installation

Expand All @@ -15,16 +20,22 @@ npm install ng-gapi
To use the `ng-gapi` simply add `GoogleApiModule` to your module imports
and set the configuration
```typescript
let gapiConfig = {
clientId: "CLIENT_ID",
discoveryDocs: ["https://analyticsreporting.googleapis.com/$discovery/rest?version=v4"],
scope: [
"https://www.googleapis.com/auth/analytics.readonly",
"https://www.googleapis.com/auth/analytics"
].join(" ")
};

@NgModule({
imports: [
...
GoogleApiModule.setConfig(
{
clientId: "your client id",
discoveryDocs: ["url to discovery docs", "another url"],
scope: "space separated scopes"
}
),
GoogleApiModule.forRoot({
provide: NG_GAPI_CONFIG,
useValue: gapiConfig
}),
...
]
})
Expand All @@ -48,6 +59,8 @@ export class FooService {
}
```

Also check the example folder with a google api reports module

#### GoogleAuthService
The module has a GoogleAuth service which allows you to work with
the google auth
Expand Down
22 changes: 14 additions & 8 deletions examples/gapiReporting/GapiReportingModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,24 @@ import {GapiUserService} from "./services/GapiUserService";
import {BrowserModule} from "@angular/platform-browser";
import {FormsModule} from "@angular/forms";
import {GapiReportingModel} from "./services/GapiReportingModel";
import {NG_GAPI_CONFIG} from "../../src/GoogleApiService";

let gapiConfig = {
clientId: "CLIENT_ID",
discoveryDocs: ["https://analyticsreporting.googleapis.com/$discovery/rest?version=v4"],
scope: [
"https://www.googleapis.com/auth/analytics.readonly",
"https://www.googleapis.com/auth/analytics"
].join(" ")
};

@NgModule({
imports: [
BrowserModule,
FormsModule,
GoogleApiModule.setConfig({
clientId: "CLIENT_ID",
discoveryDocs: ["https://analyticsreporting.googleapis.com/$discovery/rest?version=v4"],
scope: [
"https://www.googleapis.com/auth/analytics.readonly",
"https://www.googleapis.com/auth/analytics"
].join(" ")
GoogleApiModule.forRoot({
provide: NG_GAPI_CONFIG,
useValue: gapiConfig
})
],
declarations: [
Expand All @@ -33,4 +39,4 @@ import {GapiReportingModel} from "./services/GapiReportingModel";
]
})
export class GapiReportingModule {
}
}
19 changes: 12 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
{
"name": "ng-gapi",
"version": "0.0.40",
"description": "Angular 2 Google api module",
"version": "0.0.40-3",
"description": "Angular 4 Google api module ng-gapi",
"main": "./lib/index.js",
"typings": "./lib/index",
"typings": "./lib/index.d.ts",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "echo \"Error: no test specified\" && exit 1",
"tsc": "ngc"
},
"repository": {
"type": "git",
Expand All @@ -31,13 +32,17 @@
},
"homepage": "https://github.com/rubenCodeforges/angular2-google-api#readme",
"dependencies": {
"@types/gapi": "0.0.31",
"@types/gapi.auth2": "0.0.35"
"@types/gapi": "0.0.33",
"@types/gapi.auth2": "0.0.40"
},
"devDependencies": {
"@angular/compiler": "^4.2.6",
"@angular/compiler-cli": "^4.2.6",
"@angular/core": "^4.1.1",
"@angular/platform-server": "^4.2.6",
"@types/node": "7.0.10",
"rxjs": "^5.3.1",
"typescript": "^2.2.2",
"typescript": "^2.4.1",
"zone.js": "^0.8.10"
}
}
21 changes: 5 additions & 16 deletions src/GoogleApiModule.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,15 @@
import {GoogleApiService} from "./GoogleApiService";
import {ModuleWithProviders, NgModule} from "@angular/core";
import {ModuleWithProviders, NgModule, Provider} from "@angular/core";
import {GoogleAuthService} from "./GoogleAuthService";
import {GapiInitConfigs} from "./config/GoogleApiConfig";

@NgModule()
export class GoogleApiModule {
static setConfig(apiConfig: GapiInitConfigs): ModuleWithProviders {
static forRoot(gapiConfigProvider: Provider): ModuleWithProviders {
return {
ngModule: GoogleApiModule,
providers: [
{
provide: GoogleApiService,
useFactory: () => GoogleApiService.factory(apiConfig),
},
{
provide: GoogleAuthService,
useFactory: GoogleAuthService.factory,
deps: [
GoogleApiService
]
}
gapiConfigProvider,
GoogleAuthService,
]
}
}
}
}
14 changes: 7 additions & 7 deletions src/GoogleApiService.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import {Observable} from "rxjs";
import {Injectable} from "@angular/core";
import {GoogleApiConfig, GapiInitConfigs} from "./config/GoogleApiConfig";
import {Inject, Injectable, InjectionToken} from "@angular/core";
import {GapiInitConfigs, GoogleApiConfig} from "./config/GoogleApiConfig";


export let NG_GAPI_CONFIG: InjectionToken<GapiInitConfigs> =
new InjectionToken<GapiInitConfigs>("ng-gapi.config");

@Injectable()
export class GoogleApiService {
private readonly gapiUrl: string = 'https://apis.google.com/js/platform.js';
private isLoaded: boolean = false;
private config: GoogleApiConfig;

public static factory(configs: GapiInitConfigs) {
return new GoogleApiService(configs);
}

constructor(config: GapiInitConfigs) {
constructor(@Inject(NG_GAPI_CONFIG) config: GapiInitConfigs) {
this.config = new GoogleApiConfig(config);
this.loadGapi();
}
Expand Down
8 changes: 1 addition & 7 deletions src/GoogleAuthService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {Observable} from "rxjs";
import {GoogleApiService} from "./GoogleApiService";
import GoogleAuth = gapi.auth2.GoogleAuth;


@Injectable()
export class GoogleAuthService {
private GoogleAuth: GoogleAuth = undefined;
Expand Down Expand Up @@ -31,9 +30,4 @@ export class GoogleAuthService {
});
});
}

public static factory(googleApi: GoogleApiService) {
return new GoogleAuthService(googleApi)
}

}
}
12 changes: 6 additions & 6 deletions src/config/GoogleApiConfig.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
export interface GapiInitConfigs {
clientId: string,
discoveryDocs: string[],
scope: string
}

export class GoogleApiConfig {
protected CLIENT_ID: string;
protected DISCOVERY_DOCS: string[];
Expand All @@ -17,9 +23,3 @@ export class GoogleApiConfig {
}
}
}

export interface GapiInitConfigs {
clientId: string,
discoveryDocs: string[],
scope: string
}
30 changes: 23 additions & 7 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,41 @@
{
"compilerOptions": {
"target": "es5",
"noImplicitAny": true,
"module": "es2015",
"moduleResolution": "node",
"sourceMap": true,
"target": "es5",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"declaration": true,
"moduleResolution": "node",
"noUnusedLocals": true,
"types": [
"node",
"gapi",
"gapi.auth2"
],
"typeRoots": [
"./node_modules/@types"
],
"lib": [
"es2015",
"dom"
],
"outDir": "lib/",
"noImplicitAny": true,
"suppressImplicitAnyIndexErrors": true
"outDir": "lib/"
},
"files": [
"./src/index.ts",
"./src/GoogleApiModule.ts",
"./src/GoogleApiService.ts",
"./src/GoogleAuthService.ts",
"./src/config/GoogleApiConfig.ts"
],
"exclude": [
"node_modules"
"node_modules",
"examples"
],
"angularCompilerOptions": {
"strictMetadataEmit": true,
"genDir": "compiled",
"skipTemplateCodegen": true
}
}

0 comments on commit fa55a43

Please sign in to comment.