| 1 | package Catmandu::Importer::Zotero; | ||
| 2 | |||
| 3 | 2 | ▶ | use Catmandu::Sane; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 2 | ▶ | use Catmandu::Util qw(:is); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | 2 | ▶ | use WWW::Zotero; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | 2 | ▶ | use Moo; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | |||
| 8 | 2 | with 'Catmandu::Importer'; | |
| 9 | |||
| 10 | 2 | has userID => (is => 'ro'); | |
| 11 | 2 | has groupID => (is => 'ro'); | |
| 12 | 2 | has collectionID => (is => 'ro'); | |
| 13 | 2 | has apiKey => (is => 'ro'); | |
| 14 | |||
| 15 | # From WWW::Zotero | ||
| 16 | 2 | has sort => (is => 'ro'); | |
| 17 | 2 | has direction => (is => 'ro'); | |
| 18 | 2 | has itemKey => (is => 'ro'); | |
| 19 | 2 | has itemType => (is => 'ro'); | |
| 20 | 2 | has q => (is => 'ro'); | |
| 21 | 2 | has qmode => (is => 'ro'); | |
| 22 | 2 | has since => (is => 'ro'); | |
| 23 | 2 | has tag => (is => 'ro'); | |
| 24 | |||
| 25 | 2 | has client => (is => 'lazy'); | |
| 26 | |||
| 27 | sub _build_client { | ||
| 28 | 0 | ▶ | my ($self) = @_; |
|
Subroutine
_build_client: not called CC=1 SCAR=6.9
| |||
| 29 | 0 | WWW::Zotero->new(key => $self->apiKey); | |
| 30 | } | ||
| 31 | |||
| 32 | sub generator { | ||
| 33 | my ($self) = @_; | ||
| 34 | |||
| 35 | my %options = (); | ||
| 36 | |||
| 37 | $options{user} = $self->userID if $self->userID; | ||
| 38 | $options{group} = $self->groupID if $self->groupID; | ||
| 39 | $options{sort} = $self->sort if $self->sort; | ||
| 40 | $options{direction} = $self->direction if $self->direction; | ||
| 41 | $options{itemKey} = $self->itemKey if $self->itemKey; | ||
| 42 | $options{itemType} = $self->itemType if $self->itemType; | ||
| 43 | $options{q} = $self->q if $self->q(); | ||
| 44 | $options{qmode} = $self->qmode if $self->qmode; | ||
| 45 | $options{since} = $self->since if $self->since; | ||
| 46 | $options{tag} = $self->tag if $self->tag; | ||
| 47 | $options{include} = 'data'; | ||
| 48 | |||
| 49 | if ($self->collectionID) { | ||
| 50 | $options{collectionKey} = $self->collectionID; | ||
| 51 | $self->client->listCollectionItems(%options, generator => 1); | ||
| 52 | } else { | ||
| 53 | $self->client->listItems(%options, generator => 1); | ||
| 54 | } | ||
| 55 | } | ||
| 56 | |||
| 57 | 2 | 1; | |
| 58 | |||
| 59 | __END__ | ||
| 60 | |||
| 61 | =head1 NAME | ||
| 62 | |||
| 63 | Catmandu::Importer::Zotero - Import records from Zotero web | ||
| 64 | |||
| 65 | =head1 SYNOPSIS | ||
| 66 | |||
| 67 | # From the command line | ||
| 68 | # From the command line | ||
| 69 | $ catmandu convert Zotero --userID <userID> to JSON | ||
| 70 | $ catmandu convert Zotero --groupID <groupID> to JSON | ||
| 71 | |||
| 72 | # From Perl | ||
| 73 | use Catmandu; | ||
| 74 | |||
| 75 | my $importer = Catmandu->importer('Zotero', userID => '...'); | ||
| 76 | |||
| 77 | $importer->each(sub { | ||
| 78 | my $item = shift; | ||
| 79 | print "%s %s\n", $item->{_id} , $item->{title}->[0]; | ||
| 80 | }); | ||
| 81 | |||
| 82 | =head1 CONFIGURATION | ||
| 83 | |||
| 84 | =over | ||
| 85 | |||
| 86 | =item userID | ||
| 87 | |||
| 88 | User identifier (given at L<https://www.zotero.org/settings/keys>). Required | ||
| 89 | unless C<groupID> is set. | ||
| 90 | |||
| 91 | =item groupID | ||
| 92 | |||
| 93 | Group identifier (numeric part of the RSS library feed of a group) | ||
| 94 | |||
| 95 | =item collectionID | ||
| 96 | |||
| 97 | Collection key (alphanumeric identifier) | ||
| 98 | |||
| 99 | =item apiKey | ||
| 100 | |||
| 101 | Zotero API key for authenticated access | ||
| 102 | |||
| 103 | =item sort | ||
| 104 | |||
| 105 | C<dateAdded>, C<dateModified> (default), C<title>, C<creator>, C<type>, | ||
| 106 | C<date>, C<publisher>, C<publicationTitle>, C<journalAbbreviation>, | ||
| 107 | C<language>, C<accessDate>, C<libraryCatalog>, C<callNumber>, C<rights>, | ||
| 108 | C<addedBy>, or C<numItems> | ||
| 109 | |||
| 110 | =item direction | ||
| 111 | |||
| 112 | C<asc> or C<desc> | ||
| 113 | |||
| 114 | =item itemKey | ||
| 115 | |||
| 116 | A comma-separated list of item keys. Valid only for item requests. Up to | ||
| 117 | 50 items can be specified in a single request. | ||
| 118 | |||
| 119 | =item itemType | ||
| 120 | |||
| 121 | Item type search. See | ||
| 122 | L<https://www.zotero.org/support/dev/web_api/v3/basics#search_syntax> | ||
| 123 | for boolean search syntax. | ||
| 124 | |||
| 125 | =item q | ||
| 126 | |||
| 127 | Quick search to search titles and individual creator fields, or all fields if | ||
| 128 | qmode is set to C<everything>. | ||
| 129 | |||
| 130 | =item qmode | ||
| 131 | |||
| 132 | C<titleCreatorYear> (default) or C<everything> | ||
| 133 | |||
| 134 | =item since | ||
| 135 | |||
| 136 | Return only objects modified after the specified library version. | ||
| 137 | |||
| 138 | =item tag | ||
| 139 | |||
| 140 | Tag search. Supports Boolean search like item type search. | ||
| 141 | |||
| 142 | =back | ||
| 143 | |||
| 144 | =head1 DESCRIPTION | ||
| 145 | |||
| 146 | This L<Catmandu::Importer> imports bibliographic data from | ||
| 147 | L<Zotero|https://www.zotero.org> reference management service. | ||
| 148 | |||
| 149 | =head1 SEE ALSO | ||
| 150 | |||
| 151 | L<WWW::Zotero>, | ||
| 152 | L<Catmandu::Importer>, | ||
| 153 | L<Catmandu::Iterable> | ||
| 154 | |||
| 155 | =cut | ||