sunnyman's (sunnyman) wrote in changelog,
sunnyman's
sunnyman
changelog

[fotobilder] r1453: LJSUP-10497: temp commit

Committer: vtroitsky
LJSUP-10497: temp commit
U   trunk/lib/FB/Protocol/Response.pm
Modified: trunk/lib/FB/Protocol/Response.pm
===================================================================
--- trunk/lib/FB/Protocol/Response.pm	2011-11-25 09:43:29 UTC (rev 1452)
+++ trunk/lib/FB/Protocol/Response.pm	2011-11-25 15:40:17 UTC (rev 1453)
@@ -6,12 +6,13 @@
 
 BEGIN {
     use fields qw(req vars u methods);
-    use vars qw(%VALID_METHODS %ERR_MAP);
+    use vars qw(%VALID_METHODS %VALID_METHODS_v2 %ERR_MAP);
 
     use Carp;
     use XML::Simple ();
 
     # methods
+
     %VALID_METHODS = map { $_ => 1 } qw(
                                         CreateGals
                                         GetChallenge
@@ -26,6 +27,12 @@
                                         UploadPic
                                         );
 
+    %VALID_METHODS_v2 = map { $_ => 1 } qw(
+                                        GetGals
+                                        CreateGals
+                                        UploadPic
+                                        );
+
     %ERR_MAP = (
                 # User Errors (1xx)
                 100 => "User error",
@@ -144,21 +151,39 @@
     # validate authentication for this request
     $self->validate_auth or return undef;
 
+    my $ver = ($vars->{Version} eq 'fotki' ? 2 : 1);
+
     # run individual methods
-    $self->run_method($_) foreach @{$self->{methods}};
+    $self->run_method($_, $ver) foreach @{$self->{methods}};
 
     return 1;
 }
 
+sub valid_method {
+    my FB::Protocol::Response $self = shift;
+    my $meth = shift;
+    my $ver = shift;
+    $ver ||= 1;
+    if ($ver == 2) {
+        return undef unless $VALID_METHODS_v2{$meth} || $VALID_METHODS{$meth};
+    } else { # first
+        return undef unless $VALID_METHODS{$meth};
+    }
+}
+
 sub run_method {
     my FB::Protocol::Response $self = shift;
     my $meth = shift;
+    my $ver = shift;
+    $ver ||= 1;
 
     # valid method?
-    return undef unless $VALID_METHODS{$meth};
+    return undef unless $self->valid_method($meth, $ver);
+   
+    # module available?
+    my $mod = ($ver == 2 && $VALID_METHODS_v2{$meth} ? 'FB::Protocol::Fotki::' : 'FB::Protocol::');
 
-    # module available?
-    eval "use FB::Protocol::$meth";
+    eval "use ${mod}${meth}";
     if ($@) {
         $self->add_error(500 => [$_ => $@]);
         return undef;
@@ -166,7 +191,8 @@
 
     # need strict refs off for the remainder of this scope
     no strict 'refs';
-    return "FB::Protocol::${meth}::handler"->($self);
+    
+    return "${mod}${meth}::handler"->($self);
 }
 
 sub get_xml {

Tags: fotobilder, pm, sunnyman, vtroitsky
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