Grafoscopio/src/Pubiblio/ZoteroLibrary.class.st

114 lines
3.1 KiB
Smalltalk

"
I allow to query zotero libraries, given the groupID or the userID that the libraries belong to.
"
Class {
#name : #ZoteroLibrary,
#superclass : #Object,
#instVars : [
'groupID',
'userID'
],
#category : #Pubiblio
}
{ #category : #utility }
ZoteroLibrary >> collectionsURL [
"I provide the common part of the collections URL for the Zotero API"
^ self groupURL, '/collections/'
]
{ #category : #utility }
ZoteroLibrary >> emptyValuesWarning [
self inform: 'WARNING! groupID or userID should be non-emtpy. Please fill them to get available collections'.
^ self
]
{ #category : #querying }
ZoteroLibrary >> generalInfo [
"I return the last 25 the public collections for a particular group or user"
^ NeoJSONReader fromString: (ZnEasy get: self groupURL) contents.
]
{ #category : #accessing }
ZoteroLibrary >> groupID [
^ groupID
]
{ #category : #accessing }
ZoteroLibrary >> groupID: aString [
groupID := aString
]
{ #category : #utility }
ZoteroLibrary >> groupURL [
"I provide the common part of the group URL for the Zotero API"
groupID ifNotNil: [ ^ ZoteroAPI baseURL,'groups/',groupID,'/' ].
userID
ifNotNil: [ ^ ZoteroAPI baseURL,'groups/',userID,'/' ]
ifNil: [ self emptyValuesWarning ]
]
{ #category : #querying }
ZoteroLibrary >> lastCollections [
"I return all the public collections for a particular group or user"
^ NeoJSONReader fromString: (ZnEasy get: self collectionsURL) contents
]
{ #category : #querying }
ZoteroLibrary >> lastItems [
"I return the last 25 items of the public collections for a particular group or user"
^ NeoJSONReader fromString: (ZnEasy get: self groupURL,'items') contents
]
{ #category : #querying }
ZoteroLibrary >> subcollection: keyString [
"I give the general info for a subcollection, given is alphanumeric key"
^ NeoJSONReader fromString: (ZnEasy get: (self subcollectionURL:keyString)) contents.
]
{ #category : #querying }
ZoteroLibrary >> subcollectionAsBibTeX: keyString [
"I give all the items for a subcollection, given is alphanumeric key, excluding notes and attachments, exported as bibtex"
^ (ZnEasy get: (self subcollectionURL: keyString,'/items?itemType=-note || attachment &format=bibtex')) contents utf8Decoded.
]
{ #category : #querying }
ZoteroLibrary >> subcollectionLastItems: keyString [
"I give the last 25 items for a subcollection, given is alphanumeric key, including notes, attachments"
^ NeoJSONReader fromString: (ZnEasy get: (self subcollectionURL: keyString,'/items')) contents.
]
{ #category : #querying }
ZoteroLibrary >> subcollectionLastParentItems: keyString [
"I give all the items for a subcollection, given is alphanumeric key, excluding notes and attachments"
^ NeoJSONReader fromString: (ZnEasy get: (self subcollectionURL:keyString,'/items?itemType=-note || attachment')) contents.
]
{ #category : #utility }
ZoteroLibrary >> subcollectionURL: keyString [
"I provide the common part of the subcollection URL for the Zotero API, given its key string"
^ self collectionsURL,keyString
]
{ #category : #accessing }
ZoteroLibrary >> userID [
^ userID
]
{ #category : #accessing }
ZoteroLibrary >> userID: aString [
userID := aString
]