3 // The API state is static so that any instance can use login-dependent API
14 this.inherited(arguments);
15 if (blerg.API.apiInitialized) {
16 if (blerg.API.loggedIn) {
17 setTimeout(function() {
18 this.bubble('onLoginSuccessful', {username: blerg.API.username});
24 if (enyo.getCookie('auth') && enyo.getCookie('username')) {
25 blerg.API.loggedIn = true;
26 blerg.API.username = enyo.getCookie('username');
27 // Defer the signal until everything's initialized
28 setTimeout(function() {
29 this.bubble('onLoginSuccessful', {username: blerg.API.username});
33 blerg.API.apiInitialized = true;
35 login: function(username, password) {
36 var req = new enyo.Ajax({
37 url: baseURL + '/login',
40 req.response(function(inSender, inResponse) {
41 if (inResponse.status == 'success') {
42 blerg.API.loggedIn = true;
43 blerg.API.username = username;
44 enyo.setCookie('username', username);
45 this.bubble('onLoginSuccessful', {username: username});
47 enyo.setCookie('username', '', {"Max-Age": 0});
48 this.bubble('onLoginFailed');
57 var req = new enyo.Ajax({
58 url: baseURL + '/logout',
61 req.response(function(inSender, inResponse) {
62 blerg.API.loggedIn = false;
63 enyo.setCookie('auth', '', {"Max-Age": 0});
64 this.bubble('onLogoutSuccessful');
67 username: blerg.API.username
69 enyo.setCookie('username', '', {"Max-Age": 0});
71 requestFeedStatus: function() {
72 if (!blerg.API.loggedIn)
73 throw new Error('Cannot request feed status when not logged in');
76 loadUserRecords: function(username, from ,to) {
78 if (from != undefined && to != undefined) {
79 url = baseURL + '/get/' + username + '/' + from + '-' + to;
81 url = baseURL + '/get/' + username;
84 var req = new enyo.Ajax({
87 req.response(function(inSender, inResponse) {
88 this.bubble('onItemsLoaded', {
94 getSubscriptionStatus: function(username) {
95 var req = new enyo.Ajax({
96 url: baseURL + '/feedinfo/' + username,
99 req.response(function(inSender, inResponse) {
100 this.bubble('onSubscriptionStatus', {
102 subscribed: inResponse.subscribed
106 username: blerg.API.username
109 subscribe: function(username) {
110 var req = new enyo.Ajax({
111 url: baseURL + '/subscribe/' + username,
114 req.response(function(inSender, inResponse) {
115 this.bubble('onSubscriptionStatus', {
117 subscribed: inResponse.status == "success"
121 username: blerg.API.username
124 unsubscribe: function(username) {
125 var req = new enyo.Ajax({
126 url: baseURL + '/unsubscribe/' + username,
129 req.response(function(inSender, inResponse) {
130 this.bubble('onSubscriptionStatus', {
132 subscribed: inResponse.status != "success"
136 username: blerg.API.username