diff options
author | Artur Malabarba <bruce.connor.am@gmail.com> | 2015-04-19 10:52:56 +0100 |
---|---|---|
committer | Artur Malabarba <bruce.connor.am@gmail.com> | 2015-04-19 10:54:34 +0100 |
commit | 331c257711913027e277941a4b3b815e99d19244 (patch) | |
tree | ddbac589b90f2958d97d280189901afa85108406 | |
parent | 54d226d60a31b4299c65e4399e22aec8b5d31192 (diff) |
Define sx-network-user and sx-network--user-information-alist
-rw-r--r-- | sx-networks.el | 55 |
1 files changed, 29 insertions, 26 deletions
diff --git a/sx-networks.el b/sx-networks.el index eddcf02..8bd9d34 100644 --- a/sx-networks.el +++ b/sx-networks.el @@ -32,6 +32,9 @@ (defvar sx-network--user-information nil "User information for the various sites.") +(defvar sx-network--user-information-alist nil + "User information for the various site parameters.") + (defvar sx-network--user-sites nil "List of sites where user already has an account.") @@ -54,22 +57,34 @@ (defun sx-network--get-associated () "Retrieve cached information for network user. If cache is not available, retrieve current data." - (or (and (setq sx-network--user-information (sx-cache-get 'network-user) - sx-network--user-sites - (sx-network--map-site-url-to-site-api))) - (sx-network--update))) + (unless (setq sx-network--user-information (sx-cache-get 'network-user)) + (sx-network--update)) + (let ((url-par-alist (mapcar (lambda (x) + (cons (cdr (assoc 'site_url x)) + (cdr (assoc 'api_site_parameter + x)))) + (sx-site--get-site-list)))) + (setq sx-network--user-sites nil) + (setq sx-network--user-information-alist nil) + (mapc (lambda (nu) + (let ((parameter (cdr (assoc (cdr (assq 'site_url nu)) + url-par-alist)))) + (push parameter sx-network--user-sites) + (push (cons parameter nu) + sx-network--user-information-alist))) + sx-network--user-information))) (defun sx-network--update () "Update user information. Sets cache and then uses `sx-network--get-associated' to update the variables." - (sx-cache-set 'network-user - (sx-method-call 'me - :submethod 'associated - :keywords '((types . (main_site meta_site))) - :filter sx-network--user-filter - :auth t)) - (sx-network--get-associated)) + (setq sx-network--user-information + (sx-method-call 'me + :submethod 'associated + :keywords '((types . (main_site meta_site))) + :filter sx-network--user-filter + :auth t)) + (sx-cache-set 'network-user sx-network--user-information)) (defun sx-network--initialize () "Ensure network-user cache is available. @@ -78,21 +93,9 @@ Added as hook to initialization." (sx-network--get-associated)) (add-hook 'sx-init--internal-hook #'sx-network--initialize) -(defun sx-network--map-site-url-to-site-api () - "Convert `me/associations' to a set of `api_site_parameter's. -`me/associations' does not return `api_site_parameter' so cannot -be directly used to retrieve content per site. This creates a -list of sites the user is active on." - (let ((sites-info (mapcar (lambda (x) - (cons (cdr (assoc 'site_url x)) - (cdr (assoc 'api_site_parameter - x)))) - (sx-site--get-site-list)))) - (mapcar (lambda (loc) - (let ((u-site (cdr (assoc 'site_url loc)))) - (when (member u-site (mapcar #'car sites-info)) - (cdr (assoc u-site sites-info))))) - sx-network--user-information))) +(defun sx-network-user (site) + "Return an alist containing user information for SITE." + (cdr (assoc site sx-network--user-information-alist))) (provide 'sx-networks) ;;; sx-networks.el ends here |