Under construction!
Any gem released prior to 1.x may have an unstable API. As the triannon server and this client are in rapid development (as of 2015), expect new gem releases that could break the API.
Triannon Client
A client for the triannon service, see also
Installation into ruby projects
gem 'triannon-client'
Then execute:
bundle
Using the client
Configuration
Edit a .env
file to configure the triannon server address etc.
(see .env_example); or use a configure block, e.g.
require 'triannon-client'
::TriannonClient.configure do |config|
config.debug = true
config.host = 'http://triannon.example.org:8080'
config.user = 'authUser'
config.pass = 'secret'
container = '/annotations/'
end
Get a client instance
tc = TriannonClient::TriannonClient.new
Get a list of annotations
# return an RDF::Graph
graph = tc.get_annotations
anno_uris = tc.annotation_uris(graph)
anno_ids = anno_uris.collect {|uri| tc.annotation_id(uri) }
Get a particular annotation
# the default response is an open annotation in an RDF::Graph
oa_anno = tc.get_annotation(id)
For specific response formats, specify an HTTP Accept
header, e.g.
# explicitly request jsonld with an open annotation or a IIIF context
anno_oa = tc.get_annotation(id, `application/ld+json; profile="http://www.w3.org/ns/oa-context-20130208.json"`)
anno_iiif = tc.get_annotation(id, `application/ld+json; profile="http://iiif.io/api/presentation/2/context.json"`)
# convenience methods to do the above
anno_oa = tc.get_oa_annotation(id)
anno_iiif = tc.get_iiif_annotation(id)
Create an annotation
tc.post_annotation(open_annotation_jsonld)
Delete an annotation
uri = RDF::URI.new("http://your.triannon-server.com/annotations/45/4a/c0/93/454ac093-b37d-4580-bebd-449f8dabddc9")
id = tc.annotation_id(uri) #=> "45%2F4a%2Fc0%2F93%2F454ac093-b37d-4580-bebd-449f8dabddc9"
tc.delete_annotation(id)
Note: the annotation URI contains a pair-tree path (created by a Fedora 4 repository for triannon annotations). The annotation ID is the entire pair-tree path, after a URI escape. The URI escape makes it easier to work with the ID for tc.get_annotation(id) and tc.delete_annotation(id). For more information on object storage using pair-trees, see
Development
Clone and install:
./bin/setup.sh
Run tests:
./bin/test.sh