Commits

Marcin Kasperski committed d384700

experiments

Comments (0)

Files changed (4)

examples/simple_sample.pl

     sub main {
         my $self = shift;
 
+        $ENV{SPORE_TRACE} = 1;
+
 #        my $realm = "bitbucket.org";
 #        my $keyring = 
 #        my $password = $keyring->get_password($username, $realm);

lib/WebService/BitBucket/Base.pm

 use LWP::UserAgent;
 use URI;
 use Net::HTTP::Spore;
+use Log::Dispatch;
 
 =attr api_uri
 
 has '_client' => (
     is => 'ro',
     required => 1,
+    lazy => 1,
     default => sub {
+        my $self = shift;
+
         #my $where = File::ShareDir::dist_dir('WebService-BitBucket');
         #print File::ShareDir::module_dir('WebService::BitBucket'), "\n";
         my $where = File::ShareDir::module_file(
             'WebService::BitBucket', 'bitbucket-spore.json');
         my $client = Net::HTTP::Spore->new_from_spec($where);
+
         $client->enable('Format::JSON');
+        $client->enable('Redirection', max_redirect=>5);
+
+        #my $log = Log::Dispatch->new();
+        #$log->add(Log::Dispatch::File->new(name=>'fff',
+        #                                   min_level=>'debug',
+        #                                   filename=>'file.log'));
+        my $log = Log::Dispatch->new(
+            outputs => [
+                [ 'Screen', min_level => 'debug' ],
+               ]);
+        $client->enable('LogDispatch', logger => $log);
+
+        if($self->auth_user) {
+            $client->enable('Auth::Basic', 
+                            username=>$self->auth_user,
+                            password=>$self->auth_password);
+        } elsif($self->auth_token) {
+            # Must be very last middleware!
+            $client->enable('Auth::OAuth',
+                            oauth_consumer_key => 'TODO',
+                            oauth_consumer_secret => 'TODO',
+                            oauth_token => 'TODO',
+                            oauth_token_secret => 'TODO');
+        } else {
+            croak "No auth method defined";
+        }
+
+        return $client;
+        
     },
    );
 

share/bitbucket-spore.json

     "version" : "1.0",
     "methods" : {
         "user" : {
+            "authentication"  : true,
             "optional_params" : [],
             "required_params" : [],
             "path" : "/user",
+
+
+# TODO: ->enable('Mock')
+# perldoc Net::HTTP::Spore::Middleware::Mock