Commits

Marcin Kasperski committed 8423d65

random works

Comments (0)

Files changed (5)

     },
     requires => {
         'perl' => 5.006,
+        'Net::Spore' => '0.5',
+    },
+
+    # For File::ShareDir
+    share_dir => {
+        dist => [ 'examples' ],
+        module => {
+            'WebService::BitBucket' => 'share',
+        },
     },
 
     create_makefile_pl => 'traditional',

examples/simple_sample.pl

+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use WebService::BitBucket;
+
+

lib/WebService/BitBucket.pm

 package WebService::BitBucket;
 
-use 5.006;
-use strict;
-use warnings;
+use Moose; # TODO → Moo
+extends 'WebService::Bitbucket::Base';
+
 
 # TODO: Net::HTTP::Spore
 # http://search.cpan.org/~franckc/Net-HTTP-Spore-0.05/
 
 =head1 NAME
 
-WebService::BitBucket - The great new WebService::BitBucket!
+WebService::BitBucket - BitBucket client module
 
 =head1 VERSION
 
 
 our $VERSION = '0.01';
 
+=head1 DESCRIPTION
+
+L<WebService::BitBucket> wraps 
+L<BitBucket API|https://confluence.atlassian.com/display/BITBUCKET/Using+the+Bitbucket+REST+APIs>, providing means to access BitBucket
+functionality from perl scripts.
+
+Module is also bound with a few utility scripts.
 
 =head1 SYNOPSIS
 
-Quick summary of what the module does.
-
-Perhaps a little code snippet.
-
     use WebService::BitBucket;
 
-    my $foo = WebService::BitBucket->new();
+    my $bb = WebService::BitBucket->new();
     ...
 
-=head1 EXPORT
-
-A list of functions that can be exported.  You can delete this section
-if you don't export anything, such as for a purely object-oriented module.
-
-=head1 SUBROUTINES/METHODS
-
-=head2 function1
-
-=cut
-
-sub function1 {
-}
-
-=head2 function2
-
-=cut
-
-sub function2 {
-}
+# TODO
 
 =head1 AUTHOR
 

lib/WebService/BitBucket/Base.pm

+package WebService::BitBucket::Base;
+use Moo;
+
+use File::ShareDir;
+use Path::Class;
+
+=head1 DESCRIPTION
+
+Common part of most utility classes. Not used by itself,
+provides attributes and methods which are always needed.
+
+=cut
+
+use Carp qw(croak);
+use JSON::Any;
+use HTTP::Headers;
+use HTTP::Request;
+use LWP::UserAgent;
+use URI;
+
+=attr api_uri
+
+API endpoint. Usually not modified except test scenarios.
+
+=cut
+
+has 'api_uri' => (
+    default => sub { URI->new('https://api.bitbucket.org/1.0') },
+    is      => 'rw',
+    trigger => sub {
+        my ($self, $url) = @_;
+        $self->{api_uri} = URI->new("$url");
+    },
+  );
+
+
+=attr auth_token
+
+OAuth authorization token. If specified, is used to sign
+requests.
+
+TODO
+
+=cut
+
+has 'auth_token' => (
+    clearer   => 'clear_token',
+    predicate => 'has_token',
+    is        => 'rw',
+    isa       => 'Str',
+    required  => 0,
+);
+
+=attr auth_user
+
+Username used for authorization (if auth_token is not given).
+
+=cut
+
+has 'auth_user' => (
+    is => 'rw',
+    isa => 'Str',
+    required => 0
+   );
+
+=attr auth_password
+
+Password used for authorization (if auth_token is not given).
+
+=cut
+
+has 'auth_password' => (
+    is => 'rw',
+    isa => 'Str',
+    required => 0
+   );
+
+has '_client' => (
+    is => 'ro',
+    required => 1,
+    default => sub {
+        #my $where = File::ShareDir::dist_dir('WebService-BitBucket');
+        #my $where = dir(
+        #    File::ShareDir::module_dir('WebService::BitBucket'));
+        my $where = File::ShareDir::module_file(
+            'WebService::BitBucket', 'share/BitBucketSpore.json');
+        my $client = Net::HTTP::Spore->new_from_spec($where);
+        $client->enable('Format::JSON');
+    },
+   );
+
+1;

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"
+            }
+    }
+}