Commits

Marcin Kasperski  committed f0bd43c

Work in progress. share file is now properly found

  • Participants
  • Parent commits 8423d65

Comments (0)

Files changed (6)

     },
     requires => {
         'perl' => 5.006,
-        'Net::Spore' => '0.5',
+        'Net::HTTP::Spore' => '0.05',
+        'File::ShareDir' => 0,
     },
 
     # For File::ShareDir

File examples/simple_sample.pl

 #!/usr/bin/perl
 
-use strict;
-use warnings;
+use FindBin;
+use lib "$FindBin::Bin/../blib/lib";
 
-use WebService::BitBucket;
+{
+    package RunMe;
+    use Moose;
+    with 'MooseX::Getopt';
 
+    use WebService::BitBucket;
+    use Passwd::Keyring::Auto;
+    use Term::ReadKey;
 
+    has 'user' => (is=>'ro', isa=>'Str', required=>1);
+
+    has '_password' => (is=>'ro', isa=>'Str', required=>1, 
+                        lazy_build => 1);
+    has '_keyring' =>  (
+        is=>'ro', isa=>'Object', required=>1, lazy=>1,
+        default => sub { 
+            return get_keyring(app=>"Bitbucket sample",
+                               group=>"Samples");
+        });
+
+
+    my $REALM = "bitbucket.org";
+    sub _build__password {
+        my $self = shift;
+
+        my $password = $self->_keyring->get_password(
+            $self->user, $REALM);
+        unless($password) {
+            ReadMode 'noecho';
+            print "Please enter password for ", $self->user, " on $REALM\n";
+            do {
+                print "Password: ";
+                $password = ReadLine 0; chomp($password);
+                ReadMode 'normal';
+                print "\n";
+            } until $password;
+        }
+
+        $self->_keyring->set_password($self->user, $password, $REALM);
+
+        return $password;
+    }
+
+    sub main {
+        my $self = shift;
+
+#        my $realm = "bitbucket.org";
+#        my $keyring = 
+#        my $password = $keyring->get_password($username, $realm);
+#        unless($password) {
+#            $keyring->set_password($username, $password, $realm);
+        my $bitbucket = WebService::BitBucket->new(
+            auth_user => $self->user,
+            auth_password => $self->_password);
+    }
+
+        
+}
+
+my $run = RunMe->new_with_options();
+$run->main();

File lib/WebService/BitBucket.pm

 package WebService::BitBucket;
 
 use Moose; # TODO → Moo
-extends 'WebService::Bitbucket::Base';
+extends 'WebService::BitBucket::Base';
 
 
 # TODO: Net::HTTP::Spore

File lib/WebService/BitBucket/Base.pm

     default => sub {
         #my $where = File::ShareDir::dist_dir('WebService-BitBucket');
         #my $where = dir(
-        #    File::ShareDir::module_dir('WebService::BitBucket'));
+        print File::ShareDir::module_dir('WebService::BitBucket'), "\n";
         my $where = File::ShareDir::module_file(
-            'WebService::BitBucket', 'share/BitBucketSpore.json');
+            'WebService::BitBucket', 'bitbucket-spore.json');
         my $client = Net::HTTP::Spore->new_from_spec($where);
         $client->enable('Format::JSON');
     },

File lib/WebService/BitBucket/BitBucketSpore.json

-// https://confluence.atlassian.com/display/BITBUCKET/Using+the+Bitbucket+REST+APIs 
-{
-    "base_url" : "http://api.bitbucket.org/1.0",
-    "version" : "1.0",
-    "methods" : {
-        "public_timeline" : {
-            "optional_params" : [
-                "trim_user",
-                "include_entities"
-            ],
-            "required_params" : [
-                "format"
-            ],
-            "path" : "/statuses/public_timeline.:format",
-            "method" : "GET"
-            }
-    }
-}

File share/bitbucket-spore.json

+// https://confluence.atlassian.com/display/BITBUCKET/Using+the+Bitbucket+REST+APIs 
+{
+    "base_url" : "http://api.bitbucket.org/1.0",
+    "version" : "1.0",
+    "methods" : {
+        "public_timeline" : {
+            "optional_params" : [
+                "trim_user",
+                "include_entities"
+            ],
+            "required_params" : [
+                "format"
+            ],
+            "path" : "/statuses/public_timeline.:format",
+            "method" : "GET"
+            }
+    }
+}