Skip to content
Browse files

renames Roles, simplifies save_access_token examples

  • Loading branch information...
1 parent 646c175 commit 040ab19fb97ebc717a1694bd8c8af42d20494264 @spazm committed
View
14 Changes
@@ -1 +1,15 @@
+Revision history for Facebook::Graph::Cmdline
+
Changes:
+{{$NEXT}}
+ * renames roles to better match naming scheme in Facebook::Graph
+ role/HTTPtoken => Cmdline/Role/HTTPAccessToken
+ role/save_token => Cmdline/Role/SaveAccessToken
+ * uses access_token() from parent Facebook::Graph rather than a parallel
+ token(). Augments access_token to add lazybuild.
+ * improves examples
+ * adds an app id and secret to the example/facebook.yml
+
+0.123460 2012-12-10
+ * release for la.pm.org dec 11 meeting.
+ * initial functionality
View
1 examples/facebook.yml
@@ -1,4 +1,5 @@
---
+access_token:
app_id: 240872146043538
# Permissions required to be associated with Facebook access token
permissions:
View
6 examples/show_group_event_information.pl
@@ -19,11 +19,7 @@
my $fb = Facebook::Graph::Cmdline->new_with_config(
configfile => 'facebook.yml' );
-unless ( $fb->verify_token() )
-{
- my $token = $fb->token();
- $fb->save_token();
-}
+$fb->save_access_token;
my $lapm_group_id = '119158178096277';
my $events = $fb->fetch("$lapm_group_id/events");
View
6 examples/show_group_events.pl
@@ -19,11 +19,7 @@
my $fb = Facebook::Graph::Cmdline->new_with_config(
configfile => 'facebook.yml' );
-unless ( $fb->verify_token() )
-{
- my $token = $fb->token();
- $fb->save_token();
-}
+$fb->save_token();
my $lapm_group_id = '119158178096277';
my $events = $fb->fetch("$lapm_group_id/events");
View
6 examples/show_group_information.pl
@@ -18,11 +18,7 @@
my $fb = Facebook::Graph::Cmdline->new_with_config(
configfile => 'facebook.yml' );
-unless ( $fb->verify_token() )
-{
- my $token = $fb->token();
- $fb->save_token();
-}
+$fb->save_token();
my $lapm_group_id = '119158178096277';
print Dumper $fb->fetch($lapm_group_id);
View
4 lib/Facebook/Graph/Cmdline.pm
@@ -6,7 +6,7 @@ use Any::Moose;
use v5.10;
extends 'Facebook::Graph';
-with 'Facebook::Graph::role::HTTPtoken';
+with 'Facebook::Graph::Cmdline::Role::HTTPAccessToken';
#Is there a better way to do MooseX vs MouseX 'with' loading?
#can import with "use Any::Moose 'X::SimpleConfig'" but that doesn't
@@ -22,7 +22,7 @@ else
with 'MouseX::Getopt';
}
# requires provided by ::SimpleConfig
-with 'Facebook::Graph::role::save_token';
+with 'Facebook::Graph::Cmdline::Role::SaveAccessToken';
no Any::Moose;
__PACKAGE__->meta->make_immutable;
View
25 lib/Facebook/Graph/role/HTTPtoken.pm → ...ook/Graph/Cmdline/Role/HTTPAccessToken.pm
@@ -1,4 +1,4 @@
-package Facebook::Graph::role::HTTPtoken;
+package Facebook::Graph::Cmdline::Role::HTTPAccessToken;
#ABSTRACT: Embeds an HTTP::Daemon to implement OAuth callback for Facebook Authorization of Commandline Facebook apps.
@@ -14,7 +14,8 @@ requires qw(
request_access_token
);
-has +postback => ( is => 'ro', required => 1 );
+has +postback => ( is => 'ro', required => 1 );
+has +access_token => ( is => 'rw', lazy_build => 1 );
use HTTP::Daemon 6.00;
use URI;
@@ -28,10 +29,10 @@ has code => (
is => 'rw',
lazy_build => 1,
);
-has token => (
- is => 'rw',
- lazy_build => 1,
-);
+#has token => (
+# is => 'rw',
+# lazy_build => 1,
+#);
has permissions => (
is => 'ro',
default => sub { [] }
@@ -88,25 +89,25 @@ sub _build_code
$code;
}
-sub _build_token
+sub _build_access_token
{
my $self = shift;
return $self->request_access_token( $self->code )->token;
}
-sub verify_token
+sub verify_access_token
{
my $self = shift;
- return 0 unless $self->has_token();
+ return 0 unless $self->has_access_token();
say "verifying token"; ## DEBUG
- $self->access_token( $self->token );
+ #$self->access_token( $self->token );
my $resp;
eval { $resp = $self->fetch('me') };
if ($@)
{
- say "Bad access token, deleting"; ## INFO
- $self->clear_token;
+ say "Bad access_token, deleting"; ## INFO
+ $self->clear_access_token;
return 0;
}
return 1;
View
18 lib/Facebook/Graph/role/save_token.pm → ...ook/Graph/Cmdline/Role/SaveAccessToken.pm
@@ -1,16 +1,17 @@
-package Facebook::Graph::role::save_token;
+package Facebook::Graph::Cmdline::Role::SaveAccessToken;
-#ABSTRACT: Provides a save_token method to save token value to YAML config file.
+#ABSTRACT: Provides a save_access_token method to save token value to YAML config file.
use v5.10;
use Any::Moose 'Role';
use YAML::Any;
-requires qw( get_config_from_file configfile token );
+requires qw( get_config_from_file configfile access_token );
+
# MooseX::SimpleConfig or MouseX::SimpleConfig will provide
# both get_config_from_file and configfile
-=method save_token
+=method save_access_token
Updates token value in configfile and saves as YAML if modified.
@@ -18,19 +19,20 @@ If configfile is not defined, the token is printed to STDOUT for manual saving.
=cut
-sub save_token
+sub save_access_token
{
my $self = shift;
if ( !$self->configfile )
{
- say "please save token: " . $self->token;
+ say "please save token: " . $self->access_token;
return 1;
}
my $config = $self->get_config_from_file( $self->configfile );
- if ( !exists $config->{token} or $self->token ne $config->{token} )
+ if ( !exists $config->{access_token}
+ or $self->access_token ne $config->{access_token} )
{
- $config->{token} = $self->token;
+ $config->{access_token} = $self->access_token;
YAML::Any::DumpFile( $self->configfile, $config );
}
}

0 comments on commit 040ab19

Please sign in to comment.
Something went wrong with that request. Please try again.