Guest User

Untitled

a guest
Apr 25th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. package Catalyst::Model::Facebook;
  2.  
  3. use Moose;
  4. use WWW::Facebook::API;
  5.  
  6. extends 'Catalyst::Model';
  7.  
  8. with 'Catalyst::Component::InstancePerContext';
  9.  
  10. has 'appid' => (
  11. is => 'rw',
  12. isa => 'Str',
  13. required => 1
  14. );
  15.  
  16. has 'api_key' => (
  17. is => 'rw',
  18. isa => 'Str',
  19. required => 1
  20. );
  21.  
  22. has 'secret' => (
  23. is => 'rw',
  24. isa => 'Str',
  25. required => 1
  26. );
  27.  
  28. sub build_per_context_instance {
  29. my ( $self, $c ) = @_;
  30. my $client = WWW::Facebook::API->new(
  31. api_key => $self->api_key,
  32. app_id => $self->appid,
  33. desktop => 0,
  34. secret => $self->secret
  35. );
  36.  
  37. my $params = $c->req->params;
  38. my $fb_params = $client->canvas->get_fb_params( $c->req );
  39.  
  40. if ( $params->{'auth_token'} ) {
  41. $client->auth->get_session( $params->{'auth_token'} );
  42. }
  43.  
  44. if ( $fb_params->{session_key} ) {
  45. $client->session_key( $fb_params->{session_key} );
  46. }
  47.  
  48. return $client;
  49. }
  50.  
  51. no Moose;
  52. __PACKAGE__->meta->make_immutable;
Add Comment
Please, Sign In to add comment