old_contents: /*
   *  Copyright 2015 TWO SIGMA OPEN SOURCE, LLC
   *
   *  Licensed under the Apache License, Version 2.0 (the "License");
   *  you may not use this file except in compliance with the License.
   *  You may obtain a copy of the License at
   *
   *         http://www.apache.org/licenses/LICENSE-2.0
   *
   *  Unless required by applicable law or agreed to in writing, software
   *  distributed under the License is distributed on an "AS IS" BASIS,
   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *  See the License for the specific language governing permissions and
   *  limitations under the License.
   */
  /**
   * Module bk.publication
   * Publication API wrapper
   */
  (function() {
    'use strict';
    var module = angular.module('bk.publication', ['bk.utils']);
  
    module.factory('bkPublicationApi', function (bkUtils) {
      var baseUrl = 'https://pub.beakernotebook.com';
  
      return {
        createSession: function(params) {
          return bkUtils.httpPostJson(baseUrl + '/user/v1/sessions', params)
        },
        getCurrentUser: function() {
          return bkUtils.httpGetJson(baseUrl + '/user/v1/user')
        },
        createPublication: function(params) {
          return bkUtils.httpPostJson(baseUrl + '/notebook/v1/publications', params);
        },
        updatePublication: function(id, params) {
          return bkUtils.httpPutJson(baseUrl + '/notebook/v1/publications/' + id, params);
        },
        getPublication: function(id) {
          return bkUtils.httpGetJson(baseUrl + '/notebook/v1/publications/' + id);
        },
        deletePublication: function(id) {
          return bkUtils.httpDeleteJson(baseUrl + '/notebook/v1/publications/' + id);
        },
        getCategories: function() {
          return bkUtils.httpGetJson(baseUrl + '/notebook/v1/categories');
        }
      };
    });
  
    module.factory('bkPublicationAuth', function (bkPublicationApi) {
      var currentUser;
  
      return {
        signIn: function(user) {
          var self = this;
          return bkPublicationApi.createSession(user)
          .then(function() {
            return self.initSession();
          });
        },
        initSession: function() {
          return bkPublicationApi.getCurrentUser()
          .then(function(resp) {
            return currentUser = resp.data;
          });
        },
        isSignedIn: function() {
          return !!currentUser;
        }
      };
    });
  })();
  
new_contents: /*
   *  Copyright 2015 TWO SIGMA OPEN SOURCE, LLC
   *
   *  Licensed under the Apache License, Version 2.0 (the "License");
   *  you may not use this file except in compliance with the License.
   *  You may obtain a copy of the License at
   *
   *         http://www.apache.org/licenses/LICENSE-2.0
   *
   *  Unless required by applicable law or agreed to in writing, software
   *  distributed under the License is distributed on an "AS IS" BASIS,
   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *  See the License for the specific language governing permissions and
   *  limitations under the License.
   */
  /**
   * Module bk.publication
   * Publication API wrapper
   */
  (function() {
    'use strict';
    var module = angular.module('bk.publication', ['bk.utils']);
  
    module.factory('bkPublicationApi', function (bkUtils) {
      var baseUrl = 'https://pub.beakernotebook.com';
  
      return {
        createSession: function(params) {
          return bkUtils.httpPostJson(baseUrl + '/user/v1/sessions', params)
        },
        getCurrentUser: function() {
          return bkUtils.httpGetJson(baseUrl + '/user/v1/user')
        },
        createPublication: function(params) {
          return bkUtils.httpPostJson(baseUrl + '/notebook/v1/publications', params);
        },
        updatePublication: function(id, params) {
          return bkUtils.httpPutJson(baseUrl + '/notebook/v1/publications/' + id, params);
        },
        getPublication: function(id) {
          return bkUtils.httpGetJson(baseUrl + '/notebook/v1/publications/' + id);
        },
        deletePublication: function(id) {
          return bkUtils.httpDeleteJson(baseUrl + '/notebook/v1/publications/' + id);
        },
        getCategories: function() {
          return bkUtils.httpGetJson(baseUrl + '/notebook/v1/categories');
        }
      };
    });
  
    module.factory('bkPublicationAuth', function (bkPublicationApi, $localStorage) {
      var currentUser;
  
      return {
        signIn: function(user) {
          var self = this;
          return bkPublicationApi.createSession(user)
          .then(function(response) {
            $localStorage.token = response.token
            return self.initSession();
          });
        },
        initSession: function() {
          return bkPublicationApi.getCurrentUser()
          .then(function(resp) {
            return currentUser = resp.data;
          });
        },
        isSignedIn: function() {
          return !!currentUser;
        }
      };
    });
  })();
  
subject: Save Publication API token when signing in