File: ods_upstream.sql

package info (click to toggle)
virtuoso-opensource 7.2.5.1%2Bdfsg1-0.3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 285,240 kB
  • sloc: ansic: 641,220; sql: 490,413; xml: 269,570; java: 83,893; javascript: 79,900; cpp: 36,927; sh: 31,653; cs: 25,702; php: 12,690; yacc: 10,227; lex: 7,601; makefile: 7,129; jsp: 4,523; awk: 1,697; perl: 1,013; ruby: 1,003; python: 326
file content (180 lines) | stat: -rw-r--r-- 6,639 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
--set ignore_params=on;

use ODS;

create procedure ODS.ODS_API.get_oauth_tok (in app varchar)
{
  declare uid int;
  return (select a_key from OAUTH..APP_REG where a_name = app and a_owner = 0);
}
;

create procedure ODS.ODS_API.oauth_allowed (in uri varchar) __SOAP_HTTP 'text/plain'
{
  if (uri like 'http://twitter.com/%' or uri like 'http://www.linkedin.com/in/%')
    return 1;
  return 0;
}
;

create procedure ODS.ODS_API.oauth_connect (in uri varchar) __SOAP_HTTP 'text/plain'
{
  if (uri like 'http://twitter.com/%') 
    return ODS.ODS_API.oauth_connect_twitter (uri);
  else if (uri like 'http://www.linkedin.com/in/%')
    return ODS.ODS_API.oauth_connect_linkedin (uri);
  else 
    return '';  
}
;

create procedure ODS.ODS_API.oauth_connect_twitter (in uri varchar) __SOAP_HTTP 'text/plain'
{
  declare tok, res, url, sid, oauth_tok, ret_url, screen_name, tmp, params any;
  params := http_param ();
  sid := {?'sid'};
  screen_name := null;
  tok := ODS.ODS_API.get_oauth_tok ('Twitter API');
  if ({?'login'} is not null)
    {
      sid := md5 (datestring (now ()));
      ret_url := sprintf ('http://%{WSHost}s%s?sid=%U&uri=%U', http_path(), sid, uri);
      url := OAUTH..sign_request ('GET', 'http://twitter.com/oauth/request_token', sprintf ('oauth_callback=%U', ret_url), tok, null, 1); 
      res := http_get (url);
      -- dbg_obj_print (res);
      sid := OAUTH..parse_response (sid, tok, res);

      OAUTH..set_session_data (sid, params);
      oauth_tok := OAUTH..get_auth_token (sid);
      url := sprintf ('http://twitter.com/oauth/authenticate?oauth_token=%U', oauth_tok);
      --http_status_set (302);
      --http_header (sprintf ('Location: %s\r\n', url)); 
      return url;
    }
  else if ({?'oauth_verifier'} is not null)
    {
      declare header, auth any;
      -- dbg_obj_print (params);
      url := OAUTH..sign_request ('GET', 'http://twitter.com/oauth/access_token', 
		sprintf ('oauth_token=%U&oauth_verifier=%U', {?'oauth_token'}, {?'oauth_verifier'}), 
			tok, sid, 1);
      -- dbg_obj_print (url);
      res := http_get (url);
      -- dbg_obj_print (res);
      sid := OAUTH..parse_response (sid, tok, res);
      tmp := split_and_decode (res, 0);
      screen_name := get_keyword ('screen_name', tmp);  

      -- auth := OAUTH..signed_request_header ('GET', 'http://api.twitter.com/1/users/lookup.xml', sprintf ('screen_name=%U', screen_name), tok, '', sid, 0);
      -- url := sprintf ('http://api.twitter.com/1/users/lookup.xml?screen_name=%U', screen_name);
      -- dbg_obj_print_vars (url, auth);
      -- res := http_get (url, header, 'GET', auth);
      -- dbg_printf ('%s', res);
      update DB.DBA.WA_USER_OL_ACCOUNTS set WUO_OAUTH_SID = sid where WUO_URL = uri;
      commit work;
      http_header ('Content-Type: text/html\r\n');
      http ('<script type="text/javascript">');      
      http ('  window.opener.location.reload();');
      http ('  window.opener.focus ();');
      http ('  window.close ();');
      http ('</script>');
      return'';
    }
  return null;
}
;

create procedure ODS.ODS_API.oauth_connect_linkedin (in uri varchar) __SOAP_HTTP 'text/plain'
{
  declare tok, res, url, sid, oauth_tok, ret_url, screen_name, tmp, params, profile_url any;
  params := http_param ();
  sid := {?'sid'};
  profile_url := null;
  tok := ODS.ODS_API.get_oauth_tok ('LinkedIn API');
  if ({?'login'} is not null)
    {
      sid := md5 (datestring (now ()));
      ret_url := sprintf ('http://%{WSHost}s%s?sid=%U&uri=%U', http_path(), sid, uri);
      url := OAUTH..sign_request ('GET', 'https://api.linkedin.com/uas/oauth/requestToken', sprintf ('oauth_callback=%U', ret_url), tok, null, 1); 
      res := http_get (url);
      -- dbg_obj_print_vars (url, res);
      sid := OAUTH..parse_response (sid, tok, res);

      OAUTH..set_session_data (sid, params);
      oauth_tok := OAUTH..get_auth_token (sid);
      url := sprintf ('https://www.linkedin.com/uas/oauth/authenticate?oauth_token=%U', oauth_tok);
      return url;
    }
  else if ({?'oauth_verifier'} is not null)
    {
      declare header, auth any;
      -- dbg_obj_print (params);
      url := OAUTH..sign_request ('GET', 'https://api.linkedin.com/uas/oauth/accessToken', 
		sprintf ('oauth_token=%U&oauth_verifier=%U', {?'oauth_token'}, {?'oauth_verifier'}), 
			tok, sid, 1);
      -- dbg_obj_print (url);
      res := http_get (url);
      -- dbg_obj_print (res);
      sid := OAUTH..parse_response (sid, tok, res);

      url := OAUTH..sign_request ('GET', 'https://api.linkedin.com/v1/people/~:(id,first-name,last-name,industry,public-profile-url,date-of-birth)', '', tok, sid, 1);
      -- dbg_obj_print_vars (url);
      res := http_get (url);
      -- dbg_printf ('%s', res);
      update DB.DBA.WA_USER_OL_ACCOUNTS set WUO_OAUTH_SID = sid where WUO_URL = uri;
      commit work;
      http_header ('Content-Type: text/html\r\n');
      http ('<script type="text/javascript">');      
      http ('  window.opener.location.reload();');
      http ('  window.opener.focus ();');
      http ('  window.close ();');
      http ('</script>');
      return'';
    }
  return null;
}
;

create procedure ODS.ODS_API.oauth_disconnect (in uri varchar) __SOAP_HTTP 'text/plain'
{
  for select WUO_OAUTH_SID from DB.DBA.WA_USER_OL_ACCOUNTS where WUO_URL = uri do
    {
      OAUTH..session_terminate (WUO_OAUTH_SID);
    }
  update DB.DBA.WA_USER_OL_ACCOUNTS set WUO_OAUTH_SID = null where WUO_URL = uri;
  return null;
}
;

create procedure ODS.ODS_API.twitter_status_update (in txt varchar, in sid varchar)
{
  declare url, auth, header, res, tok, pars varchar;
  txt := "LEFT" (txt, 140);
  url := 'http://api.twitter.com/1/statuses/update.xml';
  pars := sprintf ('status=%U&trim_user=1', txt);
  tok := ODS.ODS_API.get_oauth_tok ('Twitter API');
  auth := OAUTH..signed_request_header ('POST', url, pars, tok, '', sid, 0);
  res := http_get (url, header, 'POST', auth, pars);
  -- dbg_obj_print_vars (header);
  return res;
}
;

create procedure ODS.ODS_API.twitter_status_delete (in id varchar, in sid varchar)
{
  declare url, auth, header, res, tok, pars varchar;
  url := sprintf ('http://api.twitter.com/1/statuses/destroy/%s.xml', id);
  pars := sprintf ('trim_user=1');
  tok := ODS.ODS_API.get_oauth_tok ('Twitter API');
  auth := OAUTH..signed_request_header ('POST', url, pars, tok, '', sid, 0);
  res := http_get (url, header, 'POST', auth, pars);
  -- dbg_obj_print_vars (header);
  return res;
}
;

grant execute on ODS.ODS_API.oauth_allowed to ODS_API;
grant execute on ODS.ODS_API.oauth_connect to ODS_API;
grant execute on ODS.ODS_API.oauth_disconnect to ODS_API;

use DB;