| 1 | package Catalyst::Model::EVDB; | ||
| 2 | |||
| 3 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 1 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | 1 | ▶ | use base qw/Catalyst::Model EVDB::API/; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | use NEXT; | ||
| 7 | |||
| 8 | our $VERSION = '0.08'; | ||
| 9 | |||
| 10 | =head1 NAME | ||
| 11 | |||
| 12 | Catalyst::Model::EVDB - EVDB model class for Catalyst | ||
| 13 | |||
| 14 | =head1 SYNOPSIS | ||
| 15 | |||
| 16 | # Use the Catalyst helper | ||
| 17 | script/myapp_create.pl model EVDB EVDB xxxxxxxxxxxxxxxx | ||
| 18 | |||
| 19 | # lib/MyApp/Model/EVDB.pm | ||
| 20 | package MyApp::Model::EVDB; | ||
| 21 | |||
| 22 | use base qw/Catalyst::Model::EVDB/; | ||
| 23 | |||
| 24 | __PACKAGE__->config( | ||
| 25 | app_key => 'xxxxxxxxxxxxxxxx', | ||
| 26 | ); | ||
| 27 | |||
| 28 | 1; | ||
| 29 | |||
| 30 | # In a controller action | ||
| 31 | my %args = ( | ||
| 32 | location => 'Gainesville, FL', | ||
| 33 | keywords => 'tag:music', | ||
| 34 | ); | ||
| 35 | |||
| 36 | my $evdb = $c->model('EVDB'); | ||
| 37 | my $results = $evdb->call('events/search', \%args) | ||
| 38 | or die 'Error searching for events: ' . $evdb->errstr; | ||
| 39 | |||
| 40 | =head1 DESCRIPTION | ||
| 41 | |||
| 42 | This is the L<EVDB::API> model class for L<Catalyst>. L<EVDB::API> is | ||
| 43 | a Perl interface to EVDB, the Events and Venues Database. | ||
| 44 | |||
| 45 | Please note that EVDB API methods require an application key. | ||
| 46 | |||
| 47 | For more information on EVDB, or to obtain an application key, see | ||
| 48 | L<http://api.evdb.com/>. | ||
| 49 | |||
| 50 | =head1 METHODS | ||
| 51 | |||
| 52 | =head2 new | ||
| 53 | |||
| 54 | Create a new EVDB model component, using C<app_key> as specified in | ||
| 55 | your configuration. | ||
| 56 | |||
| 57 | =cut | ||
| 58 | |||
| 59 | sub new { | ||
| 60 | my ($class, $c, $config) = @_; | ||
| 61 | |||
| 62 | # From Catalyst::Model::Gedcom | ||
| 63 | my $self = $class->EVDB::API::new(%{ $class->NEXT::new($c, $config) }); | ||
| 64 | $self->config($config); | ||
| 65 | |||
| 66 | return $self; | ||
| 67 | } | ||
| 68 | |||
| 69 | =head2 errstr | ||
| 70 | |||
| 71 | Return the EVDB API error message. | ||
| 72 | |||
| 73 | =cut | ||
| 74 | |||
| 75 | sub errstr { | ||
| 76 | my ($self) = @_; | ||
| 77 | |||
| 78 | return $EVDB::API::errstr; | ||
| 79 | } | ||
| 80 | |||
| 81 | =head2 login | ||
| 82 | |||
| 83 | Login using the specified username and password. For example: | ||
| 84 | |||
| 85 | # In a controller action (don't forget validation!) | ||
| 86 | my $username = $c->req->param('username'); | ||
| 87 | my $password = $c->req->param('password'); | ||
| 88 | |||
| 89 | my $evdb = $c->model('EVDB'); | ||
| 90 | $evdb->login(username => $username, password => $password) | ||
| 91 | or die 'Error logging in: ' . $evdb->errstr; | ||
| 92 | |||
| 93 | Alternatively, you can set a username and password in the | ||
| 94 | configuration for your model class. They will be used when this | ||
| 95 | method is called without arguments. For example: | ||
| 96 | |||
| 97 | # In your model class | ||
| 98 | __PACKAGE__->config( | ||
| 99 | app_key => 'xxxxxxxxxxxxxxxx', | ||
| 100 | username => 'danieltwc', | ||
| 101 | password => 'secret', | ||
| 102 | ); | ||
| 103 | |||
| 104 | # In a controller action | ||
| 105 | my $evdb = $c->model('EVDB'); | ||
| 106 | $evdb->login or die 'Error logging in: ' . $evdb->errstr; | ||
| 107 | |||
| 108 | # Call an EVDB method which requires authentication | ||
| 109 | my %args = ( | ||
| 110 | title => 'Lamb', | ||
| 111 | start_time => '2006-03-18T21:00:00', | ||
| 112 | tags => 'music', | ||
| 113 | venue_id => 'V0-001-000160549-4', | ||
| 114 | ); | ||
| 115 | |||
| 116 | my $response = $evdb->call('events/new', \%args); | ||
| 117 | |||
| 118 | This method also supports passwords which have already been hashed | ||
| 119 | using MD5. Use the C<password_md5> key instead of C<password> when | ||
| 120 | calling the method or in your configuration. | ||
| 121 | |||
| 122 | =cut | ||
| 123 | |||
| 124 | sub login { | ||
| 125 | my ($self, %args) = @_; | ||
| 126 | |||
| 127 | $args{user} ||= $args{username} || $self->config->{username} || $self->config->{user}; | ||
| 128 | $args{password} ||= $self->config->{password}; | ||
| 129 | $args{password_md5} ||= $self->config->{password_md5}; | ||
| 130 | |||
| 131 | return $self->NEXT::login(%args); | ||
| 132 | } | ||
| 133 | |||
| 134 | =head1 SEE ALSO | ||
| 135 | |||
| 136 | =over 4 | ||
| 137 | |||
| 138 | =item * L<Catalyst::Helper::Model::EVDB> | ||
| 139 | |||
| 140 | =item * L<Catalyst> | ||
| 141 | |||
| 142 | =item * L<EVDB::API> | ||
| 143 | |||
| 144 | =back | ||
| 145 | |||
| 146 | =head1 AUTHOR | ||
| 147 | |||
| 148 | Daniel Westermann-Clark E<lt>danieltwc@cpan.orgE<gt> | ||
| 149 | |||
| 150 | =head1 ACKNOWLEDGMENTS | ||
| 151 | |||
| 152 | =over 4 | ||
| 153 | |||
| 154 | =item * Brian Cassidy, for clever C<new> code | ||
| 155 | |||
| 156 | =back | ||
| 157 | |||
| 158 | =head1 LICENSE | ||
| 159 | |||
| 160 | This library is free software; you can redistribute it and/or modify | ||
| 161 | it under the same terms as Perl itself. | ||
| 162 | |||
| 163 | =cut | ||
| 164 | |||
| 165 | 1; | ||