Skip to content
This repository has been archived by the owner on Feb 19, 2022. It is now read-only.

Commit

Permalink
example v1.0.0-beta.1
Browse files Browse the repository at this point in the history
  • Loading branch information
maximepvrt committed Jan 24, 2016
1 parent ce98a31 commit d18b1b8
Show file tree
Hide file tree
Showing 50 changed files with 40,794 additions and 44 deletions.
41 changes: 25 additions & 16 deletions app/app.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
var app = angular.module('angular-google-api-example', [

'ngCookies',
'ui.router',
'angular-google-gapi',

'angular-google-api-example.router',
'angular-google-api-example.controller',
'angular-google-api-example.controller'

]);

app.run(['GAuth', 'GApi', 'GData', '$state', '$rootScope', '$window',
function(GAuth, GApi, GData, $state, $rootScope, $window) {
app.run(['GAuth', 'GApi', 'GData', '$state', '$rootScope', '$window', '$cookies',
function(GAuth, GApi, GData, $state, $rootScope, $window, $cookies) {

$rootScope.gdata = GData;

Expand All @@ -21,25 +21,34 @@ app.run(['GAuth', 'GApi', 'GData', '$state', '$rootScope', '$window',
BASE = 'https://cloud-endpoints-gae.appspot.com/_ah/api';
}

BASE = 'https://cloud-endpoints-gae.appspot.com/_ah/api';
BASE = 'https://cloud-endpoints-gae.appspot.com/_ah/api';

GApi.load('myContactApi', 'v1', BASE);
GApi.load('calendar', 'v3');
GAuth.setClient(CLIENT);
GAuth.setScope('https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/calendar.readonly');
GAuth.checkAuth().then(
function () {
if($state.includes('login'))
$state.go('home');
},
function() {
$state.go('login');
}
);

var currentUser = $cookies.get('userId');
if(currentUser) {
GData.setUserId(currentUser);
GAuth.checkAuth().then(
function () {
if($state.includes('login'))
$state.go('home');
},
function() {
$state.go('login');
}
);
} else {
$state.go('login');
}



$rootScope.logout = function() {
GAuth.logout().then(
function () {
GAuth.logout().then(function () {
$cookies.remove('userId');
$state.go('login');
});
};
Expand Down
1 change: 0 additions & 1 deletion app/controller.home.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ controller.controller('angular-google-api-example.controller.home', ['$scope', '

GApi.executeAuth('myContactApi', 'contact.all').then(function(resp) {
$scope.contacts = resp.items;
console.log(resp.items);
});

$scope.remove = function(contact){
Expand Down
23 changes: 18 additions & 5 deletions app/controller.login.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,28 @@
var controller = angular.module('angular-google-api-example.controller.login', []);

controller.controller('angular-google-api-example.controller.login', ['$scope', 'GAuth', 'GData', '$state',
function clientList($scope, GAuth, GData, $state) {
controller.controller('angular-google-api-example.controller.login', ['$scope', 'GAuth', 'GData', '$state', '$cookies',
function clientList($scope, GAuth, GData, $state, $cookies) {
if(GData.isLogin()){
$state.go('home');
}

var ifLogin = function() {
$cookies.put('userId', GData.getUserId());
$state.go('home');
};

$scope.doLogin = function() {
GAuth.login().then(function(){
$state.go('home');
});
GAuth.checkAuth().then(
function () {
ifLogin();
},
function() {
GAuth.login().then(function(){
ifLogin();
});
}
);

};
}
])
2 changes: 0 additions & 2 deletions app/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ var router = angular.module('angular-google-api-example.router', []);
router
.config(['$urlRouterProvider',
function($urlRouterProvider) {

$urlRouterProvider.otherwise("/login");

}]);

router
Expand Down
14 changes: 14 additions & 0 deletions bower.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "angular-google-gapi-example",
"version": "1.0.0-SNAPSHOT",
"homepage": "https://maximepvrt.github.io/angular-google-gapi",
"authors": [
"maximepvrt <[email protected]>"
],
"description": "Example of angular-google-gapi",
"main": "dist/angular-google-gapi.min.js",
"dependencies": {
"angular-google-gapi": "~v1.0.0-beta.1",
"angular-ui-router": "~0.2.15"
}
}
40 changes: 40 additions & 0 deletions bower_components/angular-google-gapi/.bower.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"name": "angular-google-gapi",
"version": "1.0.0-beta.1",
"homepage": "https://maximepvrt.github.io/angular-google-gapi",
"authors": [
"maximepvrt <[email protected]>"
],
"description": "An AngularJS module for use all Google Apis and your Google Cloud Endpoints (Google App Engine) with OAuth. This module use Google APIs Client Library for JavaScript, available for all GApis.",
"main": "dist/angular-google-gapi.min.js",
"keywords": [
"google apis",
"google api",
"google app engine",
"gae",
"google cloud endpoints",
"angular.js",
"angular"
],
"license": "MIT",
"ignore": [
"**/.*",
"node_modules",
"bower_components"
],
"dependencies": {
"angular": "~1.x"
},
"devDependencies": {
"angular-mocks": "~1.x"
},
"_release": "1.0.0-beta.1",
"_resolution": {
"type": "version",
"tag": "v1.0.0-beta.1",
"commit": "d48abfae73ad72a1f420c4f82ca2f4bda75f5b86"
},
"_source": "git://github.com/maximepvrt/angular-google-gapi.git",
"_target": "~v1.0.0-beta.1",
"_originalSource": "angular-google-gapi"
}
207 changes: 207 additions & 0 deletions bower_components/angular-google-gapi/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,207 @@
Angular Google GApi
=======================

An AngularJS module for use all Google Apis and your Google Cloud Endpoints (Google App Engine) with OAuth.
This module use [Google APIs Client Library for JavaScript](https://developers.google.com/api-client-library/javascript/), available for all GApis.

## Example

An example is executed here : http://maximepvrt.github.io/angular-google-gapi/

The code is available here : https://github.com/maximepvrt/angular-google-gapi/tree/gh-pages

## Requirements

- [Angular.js](http://angularjs.org)

## Installation
### Add library
This module is available as bower package, install it with this command:

```bash
bower install angular-google-gapi
```

and it's available too as npm package, install it with this command:

```bash
npm install angular-google-gapi
```

or you may download the [latest release](https://github.com/maximepvrt/angular-google-gapi/releases)

```html
<script type="text/javascript" src="/angular-google-gapi/dist/angular-google-gapi.min.js"></script>
```
### Add dependency

```javascript
var app = angular.module('myModule', ['angular-google-gapi']);
```

## Configuration
### without Google Auth

add run in root module

```javascript
app.run(['GApi', 'GAuth',
function(GApi, GAuth) {
var BASE = 'https://myGoogleAppEngine.appspot.com/_ah/api';
GApi.load('myApiName','v1',BASE).then(function(resp) {
console.log('api: ' + resp.api + ', version: ' + resp.version + ' loaded');
}, function(resp) {
console.log('an error occured during loading api: ' + resp.api + ', resp.version: ' + version);
});
}
]);
```
### with Google Auth

add run in root module

```javascript
app.run(['GAuth', 'GApi', 'GData', '$state', '$rootScope',
function(GAuth, GApi, Gdata, $state, $rootScope) {

$rootScope.gdata = GData;

var CLIENT = 'yourGoogleAuthAPIKey';
var BASE = 'https://myGoogleAppEngine.appspot.com/_ah/api';

GApi.load('myApiName','v1',BASE);
GApi.load('calendar','v3'); // for google api (https://developers.google.com/apis-explorer/)

GAuth.setClient(CLIENT);
GAuth.setScope("https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/calendar.readonly"); // default scope is only https://www.googleapis.com/auth/userinfo.email

GAuth.checkAuth().then(
function (user) {
console.log(user.name + 'is login')
$state.go('webapp.home'); // an example of action if it's possible to
// authenticate user at startup of the application
},
function() {
$state.go('login'); // an example of action if it's impossible to
// authenticate user at startup of the application
}
);

}
]);
```

### GApi.load Error handling
+
+```javascript
+GApi.load('myApiName','v1',BASE)
+ .catch(function(api, version) {
+ console.log('an error occured during loading api: ' + api + ', version: ' + version);
+ });
+```
+

## Use

### Execute your api without params

```javascript
app.controller('myController', ['$scope', 'GApi',
function myController($scope, GApi) {
GApi.execute('youApi', 'you.api.method.name').then( function(resp) {
$scope.value = resp;
}, function() {
console.log("error :(");
});
}
]);
```

### Execute your api with params

```javascript
app.controller('myController', ['$scope', 'GApi',
function myController($scope, GApi) {
GApi.execute('youApi', 'you.api.method.name', {parm1: value}).then( function(resp) {
$scope.value = resp;
}, function() {
console.log("error :(");
});
}
]);
```

### Execute your api without params with Google Auth

```javascript
app.controller('myController', ['$scope', 'GApi',
function myController($scope, GApi) {
GApi.executeAuth('youApi', 'you.api.method.name').then( function(resp) {
$scope.value = resp;
}, function() {
console.log("error :(");
});
}
]);
```

### Execute your api with params with Google Auth

```javascript
app.controller('myController', ['$scope', 'GApi',
function myController($scope, GApi) {
GApi.executeAuth('youApi', 'you.api.method.name', {parm1: value}).then( function(resp) {
$scope.value = resp;
}, function() {
console.log("error :(");
});
}
]);
```

### Signup with google

```javascript
app.controller('myController', ['$scope', 'GAuth', '$state',
function myController($scope, GAuth, $state) {

$scope.doSingup = function() {
GAuth.login().then(function(user){
console.log(user.name + 'is login')
$state.go('webapp.home'); // action after the user have validated that
// your application can access their Google account.
}, function() {
console.log('login fail');
});
};
}
]);
```

### Get user info

Get user info after login is very simple.

```javascript
app.controller('myController', ['$rootScope',
function myController($rootScope) {
console.log($rootScope.gdata.getUser().name)
}
]);
```

```html
<h1>{{gdata.getUser().name}}</h1>
```
User object :
- user.email
- user.picture (url)
- user.id (Google id)
- user.name (Google account name or email if don't exist)
- user.link (link to Google+ page)

## Development

Gulp is used to minify angular-google-gapi.js (using Uglify). Execute 'npm install' (requires Node and NPM) to install the required packages.

Run "gulp" to generate a minified version (angular-google-gapi.min.js). Note that this requires gulp to be installed globally (via 'npm install -g gulp').
Loading

0 comments on commit d18b1b8

Please sign in to comment.