annotot 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: be4df7aa9f2057db9fca11f7d9d502aca19f0e5f
4
- data.tar.gz: f61ed7cc230a9baa013a802d28a0a303cafcc565
3
+ metadata.gz: 8ef48cc5249aff0db0503072365d000d5d8eae6d
4
+ data.tar.gz: b902d44435a13a32aafaadfdc2fcf135e684a06e
5
5
  SHA512:
6
- metadata.gz: a8d2afb622d7478d7572a5d51c7da7812a33d2ce53218b33c975f9ca535a6e8d1e1144a87e35a64cf0ec5c7540675f5485506e95f3fcae54802952e18cfedc0b
7
- data.tar.gz: c394334b580a956cada38ca7848a51f14b6780eaa566e5d09b5b3b0c81be948121986bd0aff73c96c6c62081df5141e0e52bfb445768b0bf5a64f70dd1f9dde3
6
+ metadata.gz: 916eec33063d224db4c79bd581df0057237d92f0f5de20c0cdd4c73dc19371ded452af0e303e939ff81a814980f59772b69219c92b1423c4c737e80a4f194857
7
+ data.tar.gz: 855ec55e830d8d5483f6871577be98a2b5fa442a759106e8a8e40fddaefd9bf7b56677f9c3c1869eccb3a35dc44651597d4142a90ef348c2d6f8c1630b2f8f49
data/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
 
4
4
  Need to persist annotations quick and easily? Annotot, the original mini annotation API is for you. Don't annotate, annotot instead.
5
5
 
6
- h/t @efahy for the inspiration and name
6
+ h/t [@eefahy](https://github.com/eefahy) for the inspiration and name
7
7
 
8
8
  ![](annotot.png)
9
9
 
@@ -30,6 +30,76 @@ annotationEndpoint: {
30
30
 
31
31
  If you want to configure Annotot to receive annotations from external sources make sure that you enable CORs in the Rails application. This can be done using [rack-cors](https://github.com/cyu/rack-cors).
32
32
 
33
+ ## API
34
+
35
+ Annotot by default mounts itself at `/`. Though [this can be changed](http://guides.rubyonrails.org/engines.html#mounting-the-engine). All API endpoints are relative to its mount location.
36
+
37
+ | Path / Url | HTTP Verb | Path | Controller#Action |
38
+ | --- | --- | --- | --- |
39
+ | [annotations_path](#annotationspath) | GET | /annotations(.:format) | annotot/annotations#index {:format=>:json} |
40
+ | | POST | /annotations(.:format) | annotot/annotations#create {:format=>:json} |
41
+ | [lists_annotations_path](#listsannotationspath) | GET | /annotations/lists(.:format) | annotot/annotations#lists {:format=>:json} |
42
+ | [annotation_path](#annotationpath) | PATCH | /annotations/:id(.:format) | annotot/annotations#update {:format=>:json} |
43
+ | | PUT | /annotations/:id(.:format) | annotot/annotations#update {:format=>:json}
44
+ | | DELETE | /annotations/:id(.:format) | annotot/annotations#destroy {:format=>:json}
45
+
46
+ ---
47
+
48
+ ### annotations_path
49
+ `GET` - Return annotations for a given canvas
50
+
51
+ Parameters:
52
+
53
+ | Name | Required? | Description |
54
+ | --- | --- | --- |
55
+ | uri | yes | Canvas uri for which to return annotations
56
+
57
+ `POST` - Create a new annotation
58
+
59
+ Parameters:
60
+
61
+ | Name | Required? | Description |
62
+ | --- | --- | --- |
63
+ | annotation | yes | object containing creation parameters
64
+ | annotation.uuid | no | uuid for annotation
65
+ | annotation.data | no | annotation body data as string
66
+ | annotation.canvas | no | canvas to place the annotation on
67
+
68
+ ---
69
+
70
+ ### lists_annotations_path
71
+ `GET` - Return an AnnotationList of annotations for a given canvas
72
+
73
+ Parameters:
74
+
75
+ | Name | Required? | Description |
76
+ | --- | --- | --- |
77
+ | uri | yes | Canvas uri for which to return annotations
78
+
79
+ ---
80
+
81
+ ### annotation_path
82
+ `PATCH`, `PUT` - Update an annotation
83
+
84
+ Parameters:
85
+
86
+ | Name | Required? | Description |
87
+ | --- | --- | --- |
88
+ | id | yes | Canvas uri or Rails ActiveRecord id for annotation to update
89
+ | annotation | yes | object containing creation parameters
90
+ | annotation.uuid | no | uuid for annotation
91
+ | annotation.data | no | annotation body data as string
92
+ | annotation.canvas | no | canvas to place the annotation on
93
+
94
+ `DELETE` - Delete an annotation
95
+
96
+ Parameters:
97
+
98
+ | Name | Required? | Description |
99
+ | --- | --- | --- |
100
+ | id | yes | Canvas uri or Rails ActiveRecord id for annotation to delete
101
+
102
+
33
103
  ## Installation
34
104
  Add this line to your application's Gemfile:
35
105
 
@@ -65,7 +65,7 @@
65
65
  deleteAnnotation: function(annotationID, successCallback, errorCallback) {
66
66
  var _this = this;
67
67
  jQuery.ajax({
68
- url: _this.endpoint + '/' + annotationID,
68
+ url: _this.endpoint + '/' + encodeURIComponent(annotationID),
69
69
  type: 'DELETE',
70
70
  dataType: 'json',
71
71
  headers: {
@@ -93,7 +93,7 @@
93
93
  var annotationID = annotation.annotation['uuid'];
94
94
 
95
95
  jQuery.ajax({
96
- url: _this.endpoint + '/' + annotationID,
96
+ url: _this.endpoint + '/' + encodeURIComponent(annotationID),
97
97
  type: 'PATCH',
98
98
  dataType: 'json',
99
99
  headers: {
@@ -50,7 +50,7 @@ module Annotot
50
50
  private
51
51
 
52
52
  def set_annotation
53
- @annotation = Annotation.find_by(id: params[:id]) || Annotation.find_by(uuid: params[:id])
53
+ @annotation = Annotation.find_by(id: CGI.unescape(params[:id])) || Annotation.find_by(uuid: CGI.unescape(params[:id]))
54
54
  raise ActiveRecord::RecordNotFound unless @annotation.present?
55
55
  end
56
56
 
@@ -59,7 +59,7 @@ module Annotot
59
59
  end
60
60
 
61
61
  def annotation_search_params
62
- params.require(:uri)
62
+ CGI.unescape(params.require(:uri))
63
63
  end
64
64
  end
65
65
  end
@@ -1,3 +1,3 @@
1
1
  module Annotot
2
- VERSION = '0.2.1'
2
+ VERSION = '0.3.0'
3
3
  end
@@ -5,5 +5,10 @@ module Annotot
5
5
  def add_routes
6
6
  route "mount Annotot::Engine => '/'"
7
7
  end
8
+
9
+ def run_annotot_migrations
10
+ rake 'annotot:install:migrations'
11
+ rake 'db:migrate'
12
+ end
8
13
  end
9
14
  end
@@ -1,4 +1,59 @@
1
- # desc "Explaining what the task does"
2
- # task :annotot do
3
- # # Task goes here
4
- # end
1
+ require 'json'
2
+ require 'pathname'
3
+
4
+ namespace :annotot do
5
+ desc 'Import annotation list from path'
6
+ task :import_file, [:url_path] => :environment do |_t, args|
7
+ path = Pathname.new(args.url_path)
8
+ puts "Importing annotations from #{path}"
9
+ anno_list = JSON.parse(File.read(path))
10
+ puts "#{anno_list['resources'].length} resources found"
11
+ touch_count = 0
12
+ anno_list['resources'].map do |resource|
13
+ uuid = resource['@id']
14
+ selector = resource['on'].first['selector']
15
+ canvas = resource['on'].first['full']
16
+
17
+ ##
18
+ # Annotation appears to be Mirador 2.6.0 compatible
19
+ if resource['on'].first['@type'] == 'oa:SpecificResource' && selector['@type'] == 'oa:Choice'
20
+ if selector['default']['@type'] == 'oa:FragmentSelector' && selector['item']['@type'] == 'oa:SvgSelector'
21
+ touch_count += 1
22
+ end
23
+ end
24
+
25
+ ##
26
+ # Annotation needs to be updated to a single fragment selector
27
+ if resource['on'].first['@type'] == 'oa:SpecificResource' && selector['@type'] == 'oa:FragmentSelector'
28
+ new_on = "#{canvas}##{selector['value']}"
29
+ resource['on'] = new_on
30
+ touch_count += 1
31
+ end
32
+
33
+ ##
34
+ # Annotation only has an SvgSelector and in an non-compliant format
35
+ if selector['@type'] == 'oa:SvgSelector'
36
+ item = selector.deep_dup
37
+ # Fix missing quotes in SVG
38
+ item['value'] = item['value'].gsub('xmlns=http://www.w3.org/2000/svg', 'xmlns="http://www.w3.org/2000/svg"')
39
+ selector['@type'] = 'oa:Choice'
40
+ selector['default'] = {
41
+ '@type' => 'oa:FragmentSelector',
42
+ 'value' => 'xywh=0,0,0,0'
43
+ }
44
+ selector.delete('value')
45
+ selector['item'] = item
46
+ resource['on'].first['selector'] = selector.deep_dup
47
+ touch_count += 1
48
+ end
49
+
50
+ anno_json = resource.to_json
51
+ anno = Annotot::Annotation.find_or_create_by(uuid: uuid)
52
+ anno.update!(
53
+ canvas: canvas,
54
+ data: anno_json
55
+ )
56
+ end
57
+ puts "Updated #{touch_count} annotations"
58
+ end
59
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: annotot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jack Reed