User Tools

Site Tools


push_notifications:postgresql

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
push_notifications:postgresql [2015/02/23 15:34] – Prova (successo) push in seguito a fire del trigger lettipush_notifications:postgresql [2015/03/03 17:33] (current) letti
Line 70: Line 70:
 <code> <code>
  
-CREATE OR REPLACE FUNCTION honeywell.push_notifications_login(url text, login text, password text)+CREATE OR REPLACE FUNCTION push_notifications_login(url text, login text, password text)
   RETURNS text AS   RETURNS text AS
 $BODY$ $BODY$
Line 89: Line 89:
   LANGUAGE plpythonu VOLATILE   LANGUAGE plpythonu VOLATILE
   COST 100;    COST 100; 
-ALTER FUNCTION honeywell.push_notifications_login(text, text, text)         +ALTER FUNCTION push_notifications_login(text, text, text)         
-  OWNER TO matteo;+  OWNER TO postgres;
  
 </code> </code>
Line 98: Line 98:
 <code> <code>
  
-CREATE OR REPLACE FUNCTION honeywell.push_notifications_notify(channel text, token text, payload text)+CREATE OR REPLACE FUNCTION push_notifications_notify(login_url text, login text, password text, push_url text, channel text, token text, payload text)
   RETURNS text AS   RETURNS text AS
 $BODY$ $BODY$
Line 108: Line 108:
 opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj)) opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
  
-notify_values {{'channel' : channel, 'to_tokens':token,'payload':payload}+login_values = {'login': login,'password' : password
-login_data = urllib.urlencode(notify_values)+login_data = urllib.urlencode(login_values)
  
-notify_resp = opener.open(url,login_data) +login_resp = opener.open(login_url,login_data) 
-return notify_resp.getcode()+ 
 +if login_resp.getcode() == '200': 
 + 
 +    notify_values = {'channel' : channel, 'to_tokens':token,'payload':payload} 
 +    notify_data = urllib.urlencode(notify_values) 
 + 
 +    notify_resp = opener.open(push_url,notify_data) 
 +     
 +    if notify_restp.getcode() == '200': 
 +        return True 
 +else: 
 +    return False
  
 $BODY$ $BODY$
   LANGUAGE plpythonu VOLATILE   LANGUAGE plpythonu VOLATILE
   COST 100;   COST 100;
-ALTER FUNCTION honeywell.push_notifications_notify(text, text, text) +ALTER FUNCTION push_notifications_notify(text, text, text, text, text, text, text) 
-  OWNER TO matteo;+  OWNER TO postgres;
  
 </code> </code>
Line 152: Line 163:
         notify_url := 'https://api.cloud.appcelerator.com/v1/push_notification/notify_tokens.json?key=' || app_key  || '&pretty_json=true';         notify_url := 'https://api.cloud.appcelerator.com/v1/push_notification/notify_tokens.json?key=' || app_key  || '&pretty_json=true';
  
-        EXECUTE format('SELECT push_notifications_login(url := $1, login := ''admin'', password := ''admin'')'+       -- EXECUTE format('SELECT push_notifications_login(url := $1, login := ''admin'', password := ''admin'')'
         ) USING login_url;         ) USING login_url;
          
          
-        EXECUTE format('SELECT push_notifications_notify(url := $1,channel := $2,token := $3,payload := $4);' +        EXECUTE format('SELECT push_notifications_notify(login_url := $1, login := $2, password := $3, push_url := $4, channel := $5, token := $6, payload := $7);' 
-        ) USING notify_url,channel,token,payload;+        ) USING login_url, login, password, notify_url, channel, token, payload;
          
     END;     END;
push_notifications/postgresql.1424705692.txt.gz · Last modified: 2015/02/23 15:34 by letti