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 loadUserRecords: function(username, from ,to) {
73 if (from != undefined && to != undefined) {
74 url = baseURL + '/get/' + username + '/' + from + '-' + to;
76 url = baseURL + '/get/' + username;
79 var req = new enyo.Ajax({
82 req.response(function(inSender, inResponse) {
83 this.bubble('onItemsLoaded', {
93 loadTagRecords: function(type, tag) {
97 // Apache eats the hash, even encoded. Probably a security
99 url = baseURL + '/tag/H' + tag;
102 url = baseURL + '/tag/%40' + tag;
105 throw new Error("Invalid tag type: " + type);
108 var req = new enyo.Ajax({
111 req.response(function(inSender, inResponse) {
112 this.bubble('onItemsLoaded', {
121 getFeedInfo: function() {
122 if (!blerg.API.loggedIn)
123 throw new Error('Cannot request feed status when not logged in');
125 var req = new enyo.Ajax({
126 url: baseURL + '/feedinfo',
129 req.response(function(inSender, inResponse) {
130 this.bubble('onFeedInfo', inResponse);
133 username: blerg.API.username
136 loadFeed: function() {
137 if (!blerg.API.loggedIn)
138 throw new Error('Cannot request feed status when not logged in');
140 var req = new enyo.Ajax({
141 url: baseURL + '/feed',
144 req.response(function(inSender, inResponse) {
145 this.bubble('onItemsLoaded', {
151 username: blerg.API.username
154 getSubscriptionStatus: function(username) {
155 var req = new enyo.Ajax({
156 url: baseURL + '/feedinfo/' + username,
159 req.response(function(inSender, inResponse) {
160 this.bubble('onSubscriptionStatus', {
162 subscribed: inResponse.subscribed
166 username: blerg.API.username
169 subscribe: function(username) {
170 var req = new enyo.Ajax({
171 url: baseURL + '/subscribe/' + username,
174 req.response(function(inSender, inResponse) {
175 this.bubble('onSubscriptionStatus', {
177 subscribed: inResponse.status == "success"
181 username: blerg.API.username
184 unsubscribe: function(username) {
185 var req = new enyo.Ajax({
186 url: baseURL + '/unsubscribe/' + username,
189 req.response(function(inSender, inResponse) {
190 this.bubble('onSubscriptionStatus', {
192 subscribed: inResponse.status != "success"
196 username: blerg.API.username