0.5.1 • Published 10 years ago

angular-fidem v0.5.1

Weekly downloads
3
License
MIT
Repository
github
Last release
10 years ago

Angular Fidem

Build Status

Angular service to interact with Fidem API.

Install

Using bower

bower install angular-fidem

Usage

angular.module('app', ['fidem'])
.config(function (fidemProvider) {
  // Define API endpoint and API key.
  fidemProvider
  .setApiEndpoint('http://services.fidemapps.com')
  .setApiKey('yourApiKey');
})
.controller('AppCtrl', function (fidem) {
  // Log an action.
  fidem.log({
    type: 'viewShow',
    data: {
      id: 'show1',
      name: 'The Big Show'
    }
  });
});

Interceptors

Using interceptors, it's possible to modify data of action synchronously or asynchronously. It's the same behaviour as Angular $http service interceptors.

angular.module('app', ['fidem'])
.config(function (fidemProvider) {
  // Add a synchronous interceptor.
  fidemProvider.interceptors.push(function (action, $injector) {
    // Inject $window using angular injector.
    var $window = $injector.get('$window');

    // Add member_id to action.
    action.member_id = $window.user ? $window.user.fidem_member_id : null;

    // Return action.
    return action;
  });

  // Add an asynchronous interceptor.
  fidemProvider.interceptors.push(function (action, $injector) {
    // Inject $http using angular injector.
    var $http = $injector.get('$http');

    // Make an asynchronous request using $http.
    // Also returns the promise.
    return $http.get('/user/' + action.user_id)
    .then(function (result) {
      // Update action with member_id.
      action.member_id = result.data.member_id;
      // Return action to create a new promise with the action as result.
      return action;
    });
  });
})

Interceptors takes two arguments, the first is the action, and the second is the Angular $injector.

They must returns the action or a promise with the action as result.

License

MIT

0.5.1

10 years ago

0.4.0

10 years ago

0.3.0

10 years ago

0.2.6

10 years ago

0.2.3

10 years ago

0.2.2

10 years ago

0.2.1

10 years ago

0.2.0

10 years ago

0.1.4

11 years ago