Skip to content

Commit

Permalink
added query api, and fixed a bunch of bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
rizen committed Jul 9, 2010
1 parent 806cce4 commit d5ab409
Show file tree
Hide file tree
Showing 8 changed files with 496 additions and 28 deletions.
3 changes: 2 additions & 1 deletion Changes
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
0.0101 July 9, 2010
0.0200 July 9, 2010
- Added the Facebook::Graph::Query API, which allows for powerful searching of Facebook data.
- Fixed a bunch of POD formatting problems.
- Replaced URL with URI everywhere for consistency.

Expand Down
8 changes: 4 additions & 4 deletions dist.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ author = JT Smith <[email protected]>
license = Perl_5
copyright_holder = Plain Black Corporation
copyright_year = 2010
version = 0.0101
version = 0.0200

[@Classic]

[MetaResources]
bugtracker.web = http://github.com/plainblack/Facebook-Graph/issues
repository.url = git://github.com/plainblack/Facebook-Graph.git
repository.web = http://github.com/plainblack/Facebook-Graph
bugtracker.web = http://github.com/rizen/Facebook-Graph/issues
repository.url = git://github.com/rizen/Facebook-Graph.git
repository.web = http://github.com/rizen/Facebook-Graph
repository.type = git

[Prereq]
Expand Down
22 changes: 21 additions & 1 deletion lib/Facebook/Graph.pm
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package Facebook::Graph;
use Moose;
use Facebook::Graph::AccessToken;
use Facebook::Graph::Authorize;
use Facebook::Graph::Query;
with 'Facebook::Graph::Role::Uri';
use LWP::UserAgent;
use JSON;
Expand Down Expand Up @@ -64,6 +65,15 @@ sub fetch {
return JSON->new->decode($content);
}

sub query {
my ($self) = @_;
my %params;
if ($self->has_access_token) {
$params{access_token} = $self->access_token;
}
return Facebook::Graph::Query->new(%params);
}


no Moose;
__PACKAGE__->meta->make_immutable;
Expand All @@ -78,6 +88,16 @@ Facebook::Graph - An interface to the Facebook Graph API.
my $sarah_bownds = $fb->fetch('sarahbownds');
my $perl_page = $fb->fetch('16665510298');
Or better yet:
my $sarah_bownds = $fb->query
->find('sarahbownds')
->include_metadata
->select_fields(qw( id name picture ))
->request
->as_hashref;
=head2 Building A Privileged App
my $fb = Facebook::Graph->new(
Expand Down Expand Up @@ -128,7 +148,7 @@ Basically everything. It has hardly any tests, very little documentation, and ve
See the SYNOPSIS for the time being.
B<NOTE:> The C<fetch> method will likely go away and be replaced by individual object types. I just needed something quick and dirty for the time being to see that it works.
B<NOTE:> The C<fetch> method is quick and dirty. Consider using C<query> (L<Facebook::Graph::Query>) instead.
=head1 PREREQS
Expand Down
22 changes: 11 additions & 11 deletions lib/Facebook/Graph/AccessToken.pm
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,21 @@ has code => (

sub uri_as_string {
my ($self) = @_;
return $self->uri
->path('oauth/access_token')
->query_form(
client_id => $self->app_id,
client_secret => $self->secret,
redirect_uri => $self->postback,
code => $self->code,
)
->as_string;
my $uri = $self->uri;
$uri->path('oauth/access_token');
$uri->query_form(
client_id => $self->app_id,
client_secret => $self->secret,
redirect_uri => $self->postback,
code => $self->code,
);
return $uri->as_string;
}

sub request {
my ($self) = @_;
my $response = LWP::UserAgent->new->get($self->uri_as_string);
return Facebook::Graph::AccessToken::Response->new($response);
return Facebook::Graph::AccessToken::Response->new(response => $response);
}

no Moose;
Expand All @@ -50,7 +50,7 @@ __PACKAGE__->meta->make_immutable;

=head1 NAME
Facebook::Graph::AccessToken - Acquire and access token from Facebook.
Facebook::Graph::AccessToken - Acquire an access token from Facebook.
=head1 METHODS
Expand Down
27 changes: 16 additions & 11 deletions lib/Facebook/Graph/Authorize.pm
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ has postback => (
);

has permissions => (
is => 'rw',
default => sub { [] },
is => 'rw',
lazy => 1,
predicate => 'has_permissions',
default => sub { [] },
);

has display => (
Expand All @@ -37,15 +39,18 @@ sub set_display {

sub uri_as_string {
my ($self) = @_;
return $self->uri
->path('oauth/authorize')
->query_form(
client_id => $self->app_id,
redirect_uri => $self->postback,
scope => join(',', @{$self->permissions}),
display => $self->display,
)
->as_string;
my $uri = $self->uri;
$uri->path('oauth/authorize');
my %query = (
client_id => $self->app_id,
redirect_uri => $self->postback,
display => $self->display,
);
if ($self->has_permissions) {
$query{scope} = join(',', @{$self->permissions});
}
$uri->query_form(%query);
return $uri->as_string;
}

no Moose;
Expand Down
Loading

0 comments on commit d5ab409

Please sign in to comment.