triannon-client 0.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6311cba677a659f924697ca9eea30c52455b4583
4
+ data.tar.gz: 57c001638b992be5f97d526bda85ddaea20b79c6
5
+ SHA512:
6
+ metadata.gz: cf40229f17bde5ca917b659325540c04cb09ce72da0a80b88c200720833d857291446cd0ab44305963e671d53b9aea45d873cec3f76f54b8c051798a1a96c844
7
+ data.tar.gz: a7c2edbc95b69ca045df19336ef62a7e30c1ff3a6fd4a6a0961c708300143380591ad878c83561c97bd9975ba0d122bcf32e793ad840177529aa1ec6f5d740f4
data/.env_example ADDED
@@ -0,0 +1,17 @@
1
+ # https://github.com/bkeepers/dotenv is used for
2
+ # default configuration options. The values in
3
+ # this file do not replace existing values in
4
+ # the shell ENV.
5
+
6
+ # Uncomment and set values as required. See used settings in
7
+ # lib/*/configuration.rb
8
+
9
+ export DEBUG=false
10
+
11
+ export TRIANNON_LOG_FILE='log/triannon_client.log'
12
+
13
+ # Configure the triannon service
14
+ export TRIANNON_HOST='triannon.example.org'
15
+ export TRIANNON_USER=''
16
+ export TRIANNON_PASS=''
17
+
data/.travis.yml ADDED
@@ -0,0 +1,15 @@
1
+ language: ruby
2
+
3
+ install: ./bin/setup.sh
4
+
5
+ script: ./bin/test.sh
6
+
7
+ notifications:
8
+ email: false
9
+
10
+ rvm:
11
+ - 1.9.3
12
+ - 2.0.0
13
+ - 2.1.5
14
+ - 2.2.0
15
+
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Dependencies are defined in *.gemspec
4
+ gemspec
5
+
data/Gemfile.lock ADDED
@@ -0,0 +1,203 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ triannon-client (0.0.0)
5
+ dotenv
6
+ linkeddata (~> 1.0)
7
+ pry
8
+ pry-doc
9
+ rest-client (~> 1.0)
10
+
11
+ GEM
12
+ remote: https://rubygems.org/
13
+ specs:
14
+ builder (3.2.2)
15
+ celluloid (0.16.0)
16
+ timers (~> 4.0.0)
17
+ coderay (1.1.0)
18
+ coveralls (0.7.12)
19
+ multi_json (~> 1.10)
20
+ rest-client (>= 1.6.8, < 2)
21
+ simplecov (~> 0.9.1)
22
+ term-ansicolor (~> 1.3)
23
+ thor (~> 0.19.1)
24
+ diff-lcs (1.2.5)
25
+ docile (1.1.5)
26
+ domain_name (0.5.23)
27
+ unf (>= 0.0.5, < 1.0.0)
28
+ dotenv (2.0.0)
29
+ ebnf (0.3.7)
30
+ haml (~> 4.0)
31
+ rdf (~> 1.1)
32
+ sxp (~> 0.1, >= 0.1.3)
33
+ equivalent-xml (0.5.1)
34
+ nokogiri (>= 1.4.3)
35
+ ffi (1.9.8)
36
+ formatador (0.2.5)
37
+ guard (2.12.5)
38
+ formatador (>= 0.2.4)
39
+ listen (~> 2.7)
40
+ lumberjack (~> 1.0)
41
+ nenv (~> 0.1)
42
+ notiffany (~> 0.0)
43
+ pry (>= 0.9.12)
44
+ shellany (~> 0.0)
45
+ thor (>= 0.18.1)
46
+ guard-compat (1.2.1)
47
+ guard-ctags-bundler (1.4.0)
48
+ guard (>= 2.0)
49
+ guard-compat (>= 0.1.0)
50
+ haml (4.0.6)
51
+ tilt
52
+ hitimes (1.2.2)
53
+ htmlentities (4.3.3)
54
+ http-cookie (1.0.2)
55
+ domain_name (~> 0.5)
56
+ json-ld (1.1.8)
57
+ rdf (~> 1.1, >= 1.1.7)
58
+ link_header (0.0.8)
59
+ linkeddata (1.1.2)
60
+ equivalent-xml (~> 0.4)
61
+ json-ld (~> 1.1, >= 1.1.7)
62
+ nokogiri (~> 1.6)
63
+ rdf (~> 1.1, >= 1.1.7)
64
+ rdf-aggregate-repo (~> 1.1)
65
+ rdf-isomorphic (~> 1.1)
66
+ rdf-json (~> 1.1)
67
+ rdf-microdata (~> 2.0)
68
+ rdf-n3 (~> 1.1)
69
+ rdf-rdfa (~> 1.1, >= 1.1.5)
70
+ rdf-rdfxml (~> 1.1, >= 1.1.3)
71
+ rdf-reasoner (~> 0.2, >= 0.2.1)
72
+ rdf-trig (~> 1.1, >= 1.1.3)
73
+ rdf-trix (~> 1.1)
74
+ rdf-turtle (~> 1.1, >= 1.1.5)
75
+ sparql (~> 1.1, >= 1.1.4)
76
+ sparql-client (~> 1.1, >= 1.1.3)
77
+ listen (2.9.0)
78
+ celluloid (>= 0.15.2)
79
+ rb-fsevent (>= 0.9.3)
80
+ rb-inotify (>= 0.9)
81
+ lumberjack (1.0.9)
82
+ method_source (0.8.2)
83
+ mime-types (2.4.3)
84
+ mini_portile (0.6.2)
85
+ multi_json (1.11.0)
86
+ nenv (0.2.0)
87
+ net-http-persistent (2.9.4)
88
+ netrc (0.10.3)
89
+ nokogiri (1.6.6.2)
90
+ mini_portile (~> 0.6.0)
91
+ notiffany (0.0.6)
92
+ nenv (~> 0.1)
93
+ shellany (~> 0.0)
94
+ pry (0.10.1)
95
+ coderay (~> 1.1.0)
96
+ method_source (~> 0.8.1)
97
+ slop (~> 3.4)
98
+ pry-doc (0.6.0)
99
+ pry (~> 0.9)
100
+ yard (~> 0.8)
101
+ rake (10.4.2)
102
+ rb-fsevent (0.9.4)
103
+ rb-inotify (0.9.5)
104
+ ffi (>= 0.5.0)
105
+ rdf (1.1.10)
106
+ link_header (~> 0.0, >= 0.0.8)
107
+ rdf-aggregate-repo (1.1.0)
108
+ rdf (>= 1.1)
109
+ rdf-isomorphic (1.1.0)
110
+ rdf (>= 1.1)
111
+ rdf-json (1.1.1)
112
+ rdf (~> 1.1)
113
+ rdf-microdata (2.0)
114
+ htmlentities (~> 4.3)
115
+ nokogiri (~> 1.6)
116
+ rdf (~> 1.1)
117
+ rdf-xsd (~> 1.1)
118
+ rdf-n3 (1.1.2)
119
+ rdf (~> 1.1, >= 1.1.5)
120
+ rdf-rdfa (1.1.5)
121
+ haml (~> 4.0)
122
+ htmlentities (~> 4.3)
123
+ rdf (~> 1.1, >= 1.1.6)
124
+ rdf-aggregate-repo
125
+ rdf-xsd (~> 1.1)
126
+ rdf-rdfxml (1.1.3)
127
+ htmlentities (~> 4.3)
128
+ rdf (~> 1.1, >= 1.1.6)
129
+ rdf-rdfa (~> 1.1, >= 1.1.4.1)
130
+ rdf-xsd (~> 1.1)
131
+ rdf-reasoner (0.2.1)
132
+ rdf (~> 1.1, >= 1.1.4.2)
133
+ rdf-turtle (~> 1.1)
134
+ rdf-xsd (~> 1.1)
135
+ rdf-trig (1.1.3.1)
136
+ ebnf (~> 0.3, >= 0.3.5)
137
+ rdf (~> 1.1, >= 1.1.2.1)
138
+ rdf-turtle (~> 1.1, >= 1.1.3)
139
+ rdf-trix (1.1.0)
140
+ rdf (>= 1.1)
141
+ rdf-turtle (1.1.5)
142
+ ebnf (~> 0.3, >= 0.3.6)
143
+ rdf (~> 1.1, >= 1.1.4)
144
+ rdf-xsd (1.1.3)
145
+ rdf (~> 1.1, >= 1.1.9)
146
+ rest-client (1.8.0)
147
+ http-cookie (>= 1.0.2, < 2.0)
148
+ mime-types (>= 1.16, < 3.0)
149
+ netrc (~> 0.7)
150
+ rspec (3.2.0)
151
+ rspec-core (~> 3.2.0)
152
+ rspec-expectations (~> 3.2.0)
153
+ rspec-mocks (~> 3.2.0)
154
+ rspec-core (3.2.2)
155
+ rspec-support (~> 3.2.0)
156
+ rspec-expectations (3.2.0)
157
+ diff-lcs (>= 1.2.0, < 2.0)
158
+ rspec-support (~> 3.2.0)
159
+ rspec-mocks (3.2.1)
160
+ diff-lcs (>= 1.2.0, < 2.0)
161
+ rspec-support (~> 3.2.0)
162
+ rspec-support (3.2.2)
163
+ shellany (0.0.1)
164
+ simplecov (0.9.2)
165
+ docile (~> 1.1.0)
166
+ multi_json (~> 1.0)
167
+ simplecov-html (~> 0.9.0)
168
+ simplecov-html (0.9.0)
169
+ slop (3.6.0)
170
+ sparql (1.1.4)
171
+ builder (~> 3.0)
172
+ ebnf (~> 0.3, >= 0.3.5)
173
+ rdf (~> 1.1, >= 1.1.4)
174
+ rdf-aggregate-repo (~> 1.1, >= 1.1.0)
175
+ rdf-xsd (~> 1.1)
176
+ sparql-client (~> 1.1)
177
+ sxp (~> 0.1)
178
+ sparql-client (1.1.4)
179
+ net-http-persistent (~> 2.9)
180
+ rdf (~> 1.1)
181
+ sxp (0.1.5)
182
+ term-ansicolor (1.3.0)
183
+ tins (~> 1.0)
184
+ thor (0.19.1)
185
+ tilt (2.0.1)
186
+ timers (4.0.1)
187
+ hitimes
188
+ tins (1.3.5)
189
+ unf (0.1.4)
190
+ unf_ext
191
+ unf_ext (0.0.6)
192
+ yard (0.8.7.6)
193
+
194
+ PLATFORMS
195
+ ruby
196
+
197
+ DEPENDENCIES
198
+ coveralls
199
+ guard
200
+ guard-ctags-bundler
201
+ rake
202
+ rspec
203
+ triannon-client!
data/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "{}"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright {yyyy} {name of copyright owner}
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
202
+
data/README.md ADDED
@@ -0,0 +1,95 @@
1
+ [![Build Status](https://travis-ci.org/sul-dlss/triannon-client.svg?branch=master)](https://travis-ci.org/sul-dlss/triannon-client) [![Coverage Status](https://coveralls.io/repos/sul-dlss/triannon-client/badge.png)](https://coveralls.io/r/sul-dlss/triannon-client) [![Dependency Status](https://gemnasium.com/sul-dlss/triannon-client.svg)](https://gemnasium.com/sul-dlss/triannon-client) [![Gem Version](https://badge.fury.io/rb/triannon-client.svg)](http://badge.fury.io/rb/triannon-client)
2
+
3
+ # Triannon Client
4
+
5
+ A client for the triannon service, see also
6
+ - https://github.com/sul-dlss/triannon
7
+ - https://github.com/sul-dlss/triannon-service
8
+
9
+
10
+ ## Installation into ruby projects
11
+
12
+ ```ruby
13
+ gem 'triannon-client'
14
+ ```
15
+
16
+ Then execute:
17
+
18
+ ```console
19
+ bundle
20
+ ```
21
+
22
+
23
+ ## Using the client
24
+
25
+ ### Configuration
26
+
27
+ Edit a `.env` file to configure the triannon server address etc.
28
+ (see .env_example); or use a configure block, e.g.
29
+
30
+ ```ruby
31
+ require 'triannon-client'
32
+ ::TriannonClient.configure do |config|
33
+ config.debug = true
34
+ config.host = 'http://triannon.example.org:8080'
35
+ config.user = 'authUser'
36
+ config.pass = 'secret'
37
+ end
38
+ ```
39
+
40
+ ### Get a client instance
41
+
42
+ ```ruby
43
+ tc = TriannonClient::TriannonClient.new
44
+ ```
45
+
46
+ ### Get a list of annotations
47
+
48
+ ```ruby
49
+ # return an RDF::Graph
50
+ graph = tc.get_annoations
51
+ ```
52
+
53
+ ### Get a particular annotation
54
+
55
+ ```ruby
56
+ # the default response is an open annotation in an RDF::Graph
57
+ oa_anno = tc.get_annotation(id)
58
+ ```
59
+
60
+ For specific response formats, specify an HTTP `Accept` header, e.g.
61
+
62
+ ```ruby
63
+ # explicitly request jsonld with an open annotation or a IIIF context
64
+ anno_oa = tc.get_annotation(id, `application/ld+json; profile="http://www.w3.org/ns/oa-context-20130208.json"`)
65
+ anno_iiif = tc.get_annotation(id, `application/ld+json; profile="http://iiif.io/api/presentation/2/context.json"`)
66
+ # convenience methods to do the above
67
+ anno_oa = tc.get_oa_annotation(id)
68
+ anno_iiif = tc.get_iiif_annotation(id)
69
+ ```
70
+
71
+ ### Create an annotation
72
+
73
+ ```ruby
74
+ tc.post_annotation(open_annotation_jsonld)
75
+ ```
76
+
77
+ ### Delete an annotation
78
+
79
+ #### TODO
80
+
81
+
82
+ ## Development
83
+
84
+ Clone and install:
85
+
86
+ ```console
87
+ ./bin/setup.sh
88
+ ```
89
+
90
+ Run tests:
91
+
92
+ ```console
93
+ ./bin/test.sh
94
+ ```
95
+
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+ RSpec::Core::RakeTask.new(:spec)
4
+
5
+ desc 'Default: run specs.'
6
+ task :default => :spec
7
+ task :specs => :spec
data/bin/ctags.rb ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+ system "find . -name '*.rb' | ctags -f .tags --languages=Ruby -L -"
3
+
4
+ if File.exist? './Gemfile'
5
+ require 'bundler'
6
+ paths = Bundler.load.specs.map(&:full_gem_path).join(' ')
7
+ system "ctags -R -f .gemtags --languages=Ruby #{paths}"
8
+ end
@@ -0,0 +1,37 @@
1
+ require 'dotenv'
2
+ Dotenv.load
3
+
4
+ require 'pry'
5
+ require 'pry-doc'
6
+
7
+ # require rest client prior to linkeddata, so the latter can use it.
8
+ require 'rest-client'
9
+ require 'linkeddata'
10
+ RestClient.proxy = ENV['http_proxy'] unless ENV['http_proxy'].nil?
11
+ RestClient.proxy = ENV['HTTP_PROXY'] unless ENV['HTTP_PROXY'].nil?
12
+
13
+ require_relative 'triannon-client/configuration'
14
+ require_relative 'triannon-client/triannon-client'
15
+
16
+ module TriannonClient
17
+
18
+ # configuration at the module level, see
19
+ # http://brandonhilkert.com/blog/ruby-gem-configuration-patterns/
20
+
21
+ class << self
22
+ attr_writer :configuration
23
+ end
24
+
25
+ def self.configuration
26
+ @configuration ||= Configuration.new
27
+ end
28
+
29
+ def self.reset
30
+ @configuration = Configuration.new
31
+ end
32
+
33
+ def self.configure
34
+ yield(configuration)
35
+ end
36
+
37
+ end
@@ -0,0 +1,49 @@
1
+
2
+ module TriannonClient
3
+
4
+ class Configuration
5
+
6
+ attr_accessor :debug
7
+ attr_accessor :logger
8
+
9
+ attr_accessor :host
10
+ attr_accessor :user
11
+ attr_accessor :pass
12
+
13
+ def initialize
14
+ @debug = env_boolean('DEBUG')
15
+
16
+ @host = ENV['TRIANNON_HOST'] || 'http://localhost:3000'
17
+ @user = ENV['TRIANNON_USER'] || ''
18
+ @pass = ENV['TRIANNON_PASS'] || ''
19
+
20
+ # logger
21
+ log_file = ENV['TRIANNON_LOG_FILE'] || 'triannon_client.log'
22
+ log_file = File.absolute_path log_file
23
+ @log_file = log_file
24
+ log_path = File.dirname log_file
25
+ unless File.directory? log_path
26
+ # try to create the log directory
27
+ Dir.mkdir log_path rescue nil
28
+ end
29
+ begin
30
+ log_dev = File.new(@log_file, 'w+')
31
+ rescue
32
+ log_dev = $stderr
33
+ @log_file = 'STDERR'
34
+ end
35
+ log_dev.sync = true if @debug # skip IO buffering in debug mode
36
+ @logger = Logger.new(log_dev, 'monthly')
37
+ @logger.level = @debug ? Logger::DEBUG : Logger::INFO
38
+
39
+ end
40
+
41
+ def env_boolean(var)
42
+ # check if an ENV variable is true, use false as default
43
+ ENV[var].to_s.upcase == 'TRUE' rescue false
44
+ end
45
+
46
+ end
47
+
48
+ end
49
+
@@ -0,0 +1,126 @@
1
+
2
+ module TriannonClient
3
+
4
+ class TriannonClient
5
+
6
+ @@config = nil
7
+
8
+ attr_accessor :site
9
+
10
+ def initialize
11
+ # Configure triannon-app service
12
+ @@config ||= ::TriannonClient.configuration
13
+ @site = RestClient::Resource.new(
14
+ @@config.host,
15
+ :user => @@config.user,
16
+ :password => @@config.pass,
17
+ :open_timeout => 5, #seconds
18
+ :read_timeout => 20, #seconds
19
+ )
20
+ end
21
+
22
+ # @param oa [JSON-LD] a json-ld object with an open annotation context
23
+ # @return response [RestClient::Response|nil]
24
+ def post_annotation(oa)
25
+ post_data = {
26
+ "commit" => "Create Annotation",
27
+ "annotation" => {"data" => oa}
28
+ }
29
+ response = nil
30
+ tries = 0
31
+ begin
32
+ tries += 1
33
+ response = @site["/annotations/"].post post_data, :content_type => :json
34
+ rescue => e
35
+ sleep 1*tries
36
+ retry if tries < 3
37
+ binding.pry if @@config.debug
38
+ @@config.logger.error("Failed to POST annotation: #{e.message}")
39
+ end
40
+ return response
41
+ end
42
+
43
+ # Get a list of annotations
44
+ # @param content_type [String] HTTP accept header value for content type negotiation
45
+ # @response [RDF::Graph|RestClient::Response] RDF::Graph when content_type is not specified
46
+ def get_annotations(content_type=nil)
47
+ if content_type.nil?
48
+ get("#{@site.url}/annotations")
49
+ else
50
+ get("/annotations", content_type)
51
+ end
52
+ end
53
+
54
+ # Get an annotation (with a default annotation context)
55
+ # @param id [String] String representation of an annotation URI
56
+ # @param content_type [String] HTTP accept header value for content type negotiation
57
+ # @response [RDF::Graph|RestClient::Response] RDF::Graph when content_type is not specified
58
+ def get_annotation(id, content_type=nil)
59
+ if content_type.nil?
60
+ get("#{@site.url}/annotations/#{id}")
61
+ else
62
+ get("/annotations/#{id}", content_type)
63
+ end
64
+ end
65
+
66
+ # Get an annotation with a IIIF context
67
+ # @param id [String] String representation of an annotation URI
68
+ # @param content_type [String] HTTP accept header value for content type negotiation
69
+ # @response [RDF::Graph|RestClient::Response] RDF::Graph when content_type is not specified
70
+ def get_iiif_annotation(id, content_type=nil)
71
+ if content_type.nil?
72
+ get("#{@site.url}/annotations/iiif/#{id}")
73
+ else
74
+ get("/annotations/iiif/#{id}", content_type)
75
+ end
76
+ end
77
+
78
+ # Get an annotation with an open annotation context
79
+ # @param id [String] String representation of an annotation URI
80
+ # @param content_type [String] HTTP accept header value for content type negotiation
81
+ # @response [RDF::Graph|RestClient::Response] RDF::Graph when content_type is not specified
82
+ def get_oa_annotation(id, content_type=nil)
83
+ if content_type.nil?
84
+ get("#{@site.url}/annotations/oa/#{id}")
85
+ else
86
+ get("/annotations/oa/#{id}", content_type)
87
+ end
88
+ end
89
+
90
+
91
+ private
92
+
93
+ # GET annotations and annotation
94
+ #
95
+ # use HTTP Accept header with mime type to indicate desired
96
+ # format ** default: jsonld ** also supports turtle, rdfxml, html
97
+ # ** see https://github.com/sul-dlss/triannon/blob/master/app/controllers/triannon/annotations_controller.rb #show method for mime formats accepted
98
+ #
99
+ # JSON-LD context
100
+ #
101
+ # You can request IIIF or OA context for jsonld. You can use either of
102
+ # these methods (with the correct HTTP Accept header):
103
+ #
104
+ # GET: http://(host)/annotations/iiif/(anno_id)
105
+ # GET: http://(host)/annotations/(anno_id)?jsonld_context=iiif
106
+ #
107
+ # GET: http://(host)/annotations/oa/(anno_id)
108
+ # GET: http://(host)/annotations/(anno_id)?jsonld_context=oa
109
+ #
110
+ # Note that OA (Open Annotation) is the default context if none is specified.
111
+
112
+ def get(uri, content_type=nil)
113
+ if content_type.nil?
114
+ # try to get an RDF graph, let RDF.rb do content negotiation
115
+ RDF::Graph.load(uri)
116
+ else
117
+ # content_type options should include: :html, :xml, :rdf, :json
118
+ content_type = content_type.to_sym
119
+ @site[uri].get({:accept => content_type})
120
+ end
121
+ end
122
+
123
+ end
124
+
125
+ end
126
+
data/log/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ # Ignore everything in this directory
2
+ *
3
+ # Except this file
4
+ !.gitignore
@@ -0,0 +1,72 @@
1
+ require "spec_helper"
2
+
3
+ module TriannonClient
4
+
5
+ describe Configuration do
6
+
7
+ describe '#debug' do
8
+ it 'default value is false' do
9
+ ENV['DEBUG'] = nil
10
+ config = Configuration.new
11
+ expect(config.debug).to be_falsey
12
+ end
13
+ end
14
+
15
+ describe '#debug=' do
16
+ it 'can set value' do
17
+ config = Configuration.new
18
+ config.debug = true
19
+ expect(config.debug).to be_truthy
20
+ end
21
+ end
22
+
23
+ describe '#host' do
24
+ it 'default value is http://localhost:3000' do
25
+ ENV['TRIANNON_HOST'] = nil
26
+ config = Configuration.new
27
+ expect(config.host).to eql('http://localhost:3000')
28
+ end
29
+ end
30
+
31
+ describe '#host=' do
32
+ it 'can set value' do
33
+ config = Configuration.new
34
+ config.host = 'triannon.example.org'
35
+ expect(config.host).to eql('triannon.example.org')
36
+ end
37
+ end
38
+
39
+ describe '#user' do
40
+ it 'default value is an empty string' do
41
+ ENV['TRIANNON_USER'] = nil
42
+ config = Configuration.new
43
+ expect(config.user.empty?).to be_truthy
44
+ end
45
+ end
46
+
47
+ describe '#user=' do
48
+ it 'can set value' do
49
+ config = Configuration.new
50
+ config.user = 'fred'
51
+ expect(config.user).to eql('fred')
52
+ end
53
+ end
54
+
55
+ describe '#pass' do
56
+ it 'default value is an empty string' do
57
+ ENV['TRIANNON_PASS'] = nil
58
+ config = Configuration.new
59
+ expect(config.pass.empty?).to be_truthy
60
+ end
61
+ end
62
+
63
+ describe '#pass=' do
64
+ it 'can set value' do
65
+ config = Configuration.new
66
+ config.pass = 'secret'
67
+ expect(config.pass).to eql('secret')
68
+ end
69
+ end
70
+
71
+ end
72
+ end
@@ -0,0 +1,38 @@
1
+ require 'spec_helper'
2
+
3
+ # ::TriannonClient::TriannonClient class specs
4
+
5
+ describe TriannonClient do
6
+
7
+ describe "#get_annotations" do
8
+ it 'should get a list of open annotations' do
9
+ #TODO
10
+ end
11
+ end
12
+
13
+ describe "#get_annotation" do
14
+ it 'should get an open annotation by URI' do
15
+ #TODO
16
+ end
17
+ end
18
+
19
+ describe "#get_iiif_annotation" do
20
+ it 'should get an open annotation by URI, with IIIF context' do
21
+ #TODO
22
+ end
23
+ end
24
+
25
+ describe "#get_oa_annotation" do
26
+ it 'should get an open annotation by URI, with OA context' do
27
+ #TODO
28
+ end
29
+ end
30
+
31
+ describe "#post_annotation" do
32
+ it 'should POST an open annotation' do
33
+ #TODO
34
+ end
35
+ end
36
+
37
+ end
38
+
@@ -0,0 +1,47 @@
1
+ require 'spec_helper'
2
+
3
+ # ::TriannonClient module specs
4
+
5
+ describe ::TriannonClient do
6
+
7
+ describe ".configuration" do
8
+ it "should be a configuration object" do
9
+ expect(described_class.configuration).to be_a_kind_of ::TriannonClient::Configuration
10
+ end
11
+ end
12
+
13
+ describe "#configure" do
14
+ before :each do
15
+ ::TriannonClient.configure do |config|
16
+ config.debug = true
17
+ end
18
+ end
19
+ it "returns a hash of options" do
20
+ config = ::TriannonClient.configuration
21
+ expect(config).to be_instance_of ::TriannonClient::Configuration
22
+ expect(config.debug).to be_truthy
23
+ end
24
+ after :each do
25
+ ::TriannonClient.reset
26
+ end
27
+ end
28
+
29
+ describe ".reset" do
30
+ before :each do
31
+ ::TriannonClient.configure do |config|
32
+ config.debug = true
33
+ end
34
+ end
35
+ it "resets the configuration" do
36
+ ::TriannonClient.reset
37
+ config = ::TriannonClient.configuration
38
+ expect(config).to be_instance_of ::TriannonClient::Configuration
39
+ expect(config.debug).to be_falsey
40
+ end
41
+ after :each do
42
+ ::TriannonClient.reset
43
+ end
44
+ end
45
+
46
+ end
47
+
@@ -0,0 +1,9 @@
1
+ require 'coveralls'
2
+ Coveralls.wear!
3
+
4
+ require 'triannon-client'
5
+ require 'rspec'
6
+ RSpec.configure do |config|
7
+
8
+ end
9
+
@@ -0,0 +1,43 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = 'triannon-client'
5
+ s.version = '0.0.0'
6
+ s.licenses = ['Apache-2.0']
7
+ s.platform = Gem::Platform::RUBY
8
+
9
+ s.authors = ['Darren Weber',]
10
+ s.email = ['darren.weber@stanford.edu']
11
+
12
+ s.homepage = 'https://github.com/sul-dlss/triannon-client'
13
+ s.summary = 'A client for RESTful transactions with a triannon annotation server'
14
+ s.description = 'A client for RESTful transactions with a triannon annotation server'
15
+
16
+ s.required_rubygems_version = '>= 1.3.6'
17
+
18
+ s.extra_rdoc_files = ['README.md', 'LICENSE']
19
+
20
+ # Use ENV for config
21
+ s.add_dependency 'dotenv'
22
+ # HTTP and RDF clients
23
+ s.add_dependency 'rest-client', '~> 1.0'
24
+ s.add_dependency 'linkeddata', '~> 1.0'
25
+ # Use pry for console and debugging
26
+ s.add_dependency 'pry'
27
+ s.add_dependency 'pry-doc'
28
+
29
+ s.add_development_dependency 'coveralls'
30
+ s.add_development_dependency 'guard'
31
+ s.add_development_dependency 'guard-ctags-bundler'
32
+ s.add_development_dependency 'rake'
33
+ s.add_development_dependency 'rspec'
34
+
35
+ s.files = `git ls-files`.split($/)
36
+ dev_files = %w(.gitignore bin/console bin/setup.sh bin/test.sh)
37
+ dev_files.each {|f| s.files.delete f }
38
+
39
+ s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
40
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
41
+
42
+ end
43
+
metadata ADDED
@@ -0,0 +1,209 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: triannon-client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Darren Weber
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-03-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: dotenv
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rest-client
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: linkeddata
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry-doc
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: coveralls
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: guard
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: guard-ctags-bundler
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rake
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: rspec
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ description: A client for RESTful transactions with a triannon annotation server
154
+ email:
155
+ - darren.weber@stanford.edu
156
+ executables:
157
+ - ctags.rb
158
+ extensions: []
159
+ extra_rdoc_files:
160
+ - README.md
161
+ - LICENSE
162
+ files:
163
+ - ".env_example"
164
+ - ".travis.yml"
165
+ - Gemfile
166
+ - Gemfile.lock
167
+ - LICENSE
168
+ - README.md
169
+ - Rakefile
170
+ - bin/ctags.rb
171
+ - lib/triannon-client.rb
172
+ - lib/triannon-client/configuration.rb
173
+ - lib/triannon-client/triannon-client.rb
174
+ - log/.gitignore
175
+ - spec/lib/triannon-client/configuration_spec.rb
176
+ - spec/lib/triannon-client/triannon-client_spec.rb
177
+ - spec/lib/triannon-client_spec.rb
178
+ - spec/spec_helper.rb
179
+ - triannon-client.gemspec
180
+ homepage: https://github.com/sul-dlss/triannon-client
181
+ licenses:
182
+ - Apache-2.0
183
+ metadata: {}
184
+ post_install_message:
185
+ rdoc_options: []
186
+ require_paths:
187
+ - lib
188
+ required_ruby_version: !ruby/object:Gem::Requirement
189
+ requirements:
190
+ - - ">="
191
+ - !ruby/object:Gem::Version
192
+ version: '0'
193
+ required_rubygems_version: !ruby/object:Gem::Requirement
194
+ requirements:
195
+ - - ">="
196
+ - !ruby/object:Gem::Version
197
+ version: 1.3.6
198
+ requirements: []
199
+ rubyforge_project:
200
+ rubygems_version: 2.4.5
201
+ signing_key:
202
+ specification_version: 4
203
+ summary: A client for RESTful transactions with a triannon annotation server
204
+ test_files:
205
+ - spec/lib/triannon-client/configuration_spec.rb
206
+ - spec/lib/triannon-client/triannon-client_spec.rb
207
+ - spec/lib/triannon-client_spec.rb
208
+ - spec/spec_helper.rb
209
+ has_rdoc: