Андрей (andy) wrote in changelog,
Андрей
andy
changelog

[fotobilder] r1464: LJSUP-11926 (ensure that fotobilder API ...

Committer: ailyin
LJSUP-11926 (ensure that fotobilder API works with the new photo hosting)
A   trunk/lib/FB/Protocol/Fotki/GetSecGroups.pm
Added: trunk/lib/FB/Protocol/Fotki/GetSecGroups.pm
===================================================================
--- trunk/lib/FB/Protocol/Fotki/GetSecGroups.pm	                        (rev 0)
+++ trunk/lib/FB/Protocol/Fotki/GetSecGroups.pm	2012-04-24 12:42:38 UTC (rev 1464)
@@ -0,0 +1,85 @@
+package FB::Protocol::Fotki::GetSecGroups;
+use strict;
+use warnings;
+
+sub handler {
+    my $resp = shift or return undef;
+    my $req  = $resp->{req};
+    my $vars = $req->{vars};
+    my $u = $resp->{u};
+
+    my $err = sub {
+        $resp->add_method_error(GetSecGroups => @_);
+        return undef;
+    };
+
+    my $ret = { SecGroup => [] };
+
+    my $lj_userid = FB::get_domain_userid($u);
+    my $lj_user = LJ::load_userid($lj_userid);
+    my %protocol_resp;
+    LJ::do_request(
+        {
+            'mode' => 'getfriends',
+            'user' => $lj_user->username, 
+            'ver'  => $LJ::PROTOCOL_VER,
+            'includegroups' => 1,
+        },
+        \%protocol_resp,
+        { 'u' => $lj_user, 'noauth' => 1 }
+    );
+
+    foreach my $groupnum ( 1 .. 30 ) {
+        next unless exists $protocol_resp{"frgrp_${groupnum}_name"};
+
+        my $grpret = {
+            'id'           => $groupnum,
+            'Name'         => [ $protocol_resp{"frgrp_${groupnum}_name"} ],
+            'GroupMembers' => { },
+        };
+
+        my $members = [];
+
+        foreach my $friendnum ( 1 .. $protocol_resp{'friend_count'} ) {
+            my $mask = $protocol_resp{"friend_${friendnum}_groupmask"} || 1;
+            next unless $mask & ( 1 << $groupnum );
+
+            my $username = $protocol_resp{"friend_${friendnum}_user"};
+            push @$members, {
+                'id'   => LJ::get_userid($username),
+                'user' => $username,
+            };
+        }
+
+        $grpret->{'GroupMembers'}->{'GroupMember'} = $members if @$members;
+        push @{ $ret->{'SecGroup'} }, $grpret;
+    }
+
+    do {
+        my $grpret = {
+            'id'           => 254,
+            'Name'         => [ 'All Friends' ],
+            'GroupMembers' => { },
+        };
+
+        my $members = [];
+
+        foreach my $friendnum ( 1 .. $protocol_resp{'friend_count'} ) {
+            my $username = $protocol_resp{"friend_${friendnum}_user"};
+            push @$members, {
+                'id'   => LJ::get_userid($username),
+                'user' => $username,
+            };
+        }
+
+        $grpret->{'GroupMembers'}->{'GroupMember'} = $members if @$members;
+        push @{ $ret->{'SecGroup'} }, $grpret;
+    };
+
+    # register return value with parent Request
+    $resp->add_method_vars( 'GetSecGroups' => $ret );
+
+    return 1;
+}
+
+1;

Tags: ailyin, andy, fotobilder, pm
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments