Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 135 lines (118 sloc) 3.796 kB
2a3fd51 sample code for fetching yahoo profile data asynchronously using stor…
erik authored
1 <?php
2
b3da6db added link to license in all code files
erik authored
3 /*
4 * Copyright: (c) 2009, Yahoo! Inc. All rights reserved.
5 * License: code licensed under the BSD License. See [license.markdown](http://github.com/ydn/async_profile_fetch/blob/master/license.markdown)
6 */
7
2a3fd51 sample code for fetching yahoo profile data asynchronously using stor…
erik authored
8 require '../../yosdk/yahoo-yos-social-php-1fe1b43/lib/YahooSessionStore.inc';
9
bd10af7 now using sqlite instead of flat file for storage because it's a bit …
erik authored
10 class SqliteStorage
11 {
12 function __construct()
13 {
14 //the directory containing this file must be writable for this to work
15 if ($this->db = new SQLiteDatabase('sqlite')) {
16
17 //if there's no 'storage' table, create one
18 $q = @$this->db->query('SELECT value FROM storage WHERE key = 1');
19 if ($q === false) {
20 $sql = "CREATE TABLE storage (key text, value text, PRIMARY KEY (key)); INSERT INTO storage VALUES (1,1)";
21 $this->db->queryExec($sql);
22 }
23 } else {
24 die($err);
25 }
26 }
27
28 function insert($key, $value)
29 {
30 $sql = "INSERT INTO storage (key, value) values ('$key', '$value')";
31 $this->db->queryExec($sql);
32 }
33
34 function select($key)
35 {
36 $sql = "SELECT value FROM storage WHERE key = '$key'";
37 $result = $this->db->query($sql);
38 return $result = $result->fetchSingle();
39 }
40
41 function delete($key)
42 {
43 $sql = "DELETE FROM storage WHERE key = '$key'";
44 $this->db->queryExec($sql);
45 }
46 }
47
2a3fd51 sample code for fetching yahoo profile data asynchronously using stor…
erik authored
48 class CustomSessionStore implements YahooSessionStore {
49
bd10af7 now using sqlite instead of flat file for storage because it's a bit …
erik authored
50 function __construct($guid=NULL){
2a3fd51 sample code for fetching yahoo profile data asynchronously using stor…
erik authored
51 $this->guid = $guid;
52 $this->storage = $storage;
bd10af7 now using sqlite instead of flat file for storage because it's a bit …
erik authored
53 $this->storage = new SqliteStorage;
2a3fd51 sample code for fetching yahoo profile data asynchronously using stor…
erik authored
54 }
55
56 /**
57 * Indicates if the session store has a request token.
58 *
59 * @return True if a request token is present, false otherwise.
60 */
61 function hasRequestToken() {
62 $token = $this->fetchRequestToken();
63 return $token ? true : false;
64 }
65
66 /**
67 * Indicates if the session store has an access token.
68 *
69 * @return True if an access token is present, false otherwise.
70 */
71 function hasAccessToken() {
72 $token = $this->fetchAccessToken();
73 return $token ? true : false;
74 }
75
76 /**
77 * Stores the given request token in the session store.
78 *
79 * @param $token A PHP stdclass object containing the components of
80 * the OAuth request token.
81 * @return True on success, false otherwise.
82 */
83 function storeRequestToken($token){
bd10af7 now using sqlite instead of flat file for storage because it's a bit …
erik authored
84 $this->storage->insert($token->key, serialize($token));
2a3fd51 sample code for fetching yahoo profile data asynchronously using stor…
erik authored
85 return true;
86 }
87
88 /**
89 * Fetches and returns the request token from the session store.
90 *
91 * @return The request token.
92 */
93 function fetchRequestToken($oauth_token=NULL){
bd10af7 now using sqlite instead of flat file for storage because it's a bit …
erik authored
94 return unserialize($this->storage->select($oauth_token));
2a3fd51 sample code for fetching yahoo profile data asynchronously using stor…
erik authored
95 }
96
97 /**
98 * Clears the request token from the session store.
99 *
100 * @return True on success, false otherwise.
101 */
102 function clearRequestToken(){
bd10af7 now using sqlite instead of flat file for storage because it's a bit …
erik authored
103 $this->storage->delete($oauth_token);
2a3fd51 sample code for fetching yahoo profile data asynchronously using stor…
erik authored
104 }
105
106 /**
107 * Stores the given access token in the session store.
108 *
109 * @param $token A PHP stdclass object containing the components of
110 * the OAuth access token.
111 * @return True on success, false otherwise.
112 */
113 function storeAccessToken($token){
bd10af7 now using sqlite instead of flat file for storage because it's a bit …
erik authored
114 $this->storage->insert($token->guid, serialize($token));
2a3fd51 sample code for fetching yahoo profile data asynchronously using stor…
erik authored
115 return true;
116 }
117
118 /**
119 * Fetches and returns the access token from the session store.
120 *
121 * @return The access token.
122 */
123 function fetchAccessToken(){
bd10af7 now using sqlite instead of flat file for storage because it's a bit …
erik authored
124 return unserialize($this->storage->select($this->guid));
2a3fd51 sample code for fetching yahoo profile data asynchronously using stor…
erik authored
125 }
126
127 /**
128 * Clears the access token from the session store.
129 *
130 * @return True on success, false otherwise.
131 */
132 function clearAccessToken(){
bd10af7 now using sqlite instead of flat file for storage because it's a bit …
erik authored
133 $this->storage->delete($this->guid);
2a3fd51 sample code for fetching yahoo profile data asynchronously using stor…
erik authored
134 }
135 }
Something went wrong with that request. Please try again.