nolij_web 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +24 -5
- data/lib/nolij_web/connection.rb +1 -0
- data/lib/nolij_web/handler.rb +53 -2
- data/lib/nolij_web/version.rb +1 -1
- data/nolij_web.gemspec +2 -2
- data/test/nolij_web/handler_test.rb +67 -0
- data/test/nolij_web/test_stubs/document_metadata.xml +9 -0
- metadata +5 -3
data/README.rdoc
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
= NolijWeb
|
2
2
|
|
3
|
-
Talk to the Nolij Web API.
|
3
|
+
Talk to the Nolij Web API. This gem contains a subset of available API methods for the Nolij Web API. Document submission/printing(retrieval) are the main focus. Methods for folder listings, work flow request, and generated urls for the viewer are provided.
|
4
4
|
|
5
5
|
The raw connection can be used to execute other types of requests.
|
6
6
|
|
@@ -20,26 +20,45 @@ Or install it yourself as:
|
|
20
20
|
|
21
21
|
== Basic Usage
|
22
22
|
|
23
|
-
You should be able to use the handler for basic requests.
|
23
|
+
You should be able to use the handler for basic requests. Handler method options are based on the options from the Nolij Web API documentation. Underscores have been added to the option names.
|
24
|
+
|
24
25
|
require 'nolij_web'
|
25
26
|
|
26
27
|
handler = NolijWeb::Handler.new(config_hash_or_path_to_config_yaml)
|
27
28
|
|
28
|
-
handler.folder_info({:folder_id => 1111111})
|
29
|
+
handler.folder_info({:folder_id => '1111111'})
|
29
30
|
|
30
|
-
Configuration
|
31
|
+
=== Configuration
|
32
|
+
Configuration can be passed as an assigned hash
|
31
33
|
config = {
|
32
34
|
:username => 'username',
|
33
35
|
:password => 'password',
|
34
36
|
:base_url => 'https://somedomain.com/NolijWeb'
|
35
37
|
}
|
36
38
|
|
39
|
+
Configuration can be read from a YAML file by passing the file path. The file should contain a hash structure:
|
40
|
+
---
|
41
|
+
:username: 'username'
|
42
|
+
:password: 'password'
|
43
|
+
:base_url: 'https://somedomain.com/NolijWeb'
|
44
|
+
|
37
45
|
== Passing a block to NolijWeb::Handler methods
|
38
46
|
You may pass a custom block to handler methods. Please note that your block should return the response for successful request. Some of the methods rely on parsing XML responses from the server.
|
39
47
|
|
40
48
|
== Using the Connection Directly
|
41
49
|
|
42
|
-
You can use the handler's connection directly. See NolijWeb::Connection for info.
|
50
|
+
You can use the handler's connection directly. An execute method has been provided to handle opening and closing of sessions. See NolijWeb::Connection for more info.
|
51
|
+
conn = NolijWeb::Connection.new(config_hash_or_path_to_config_yaml)
|
52
|
+
conn.execute() {
|
53
|
+
@folder_info = conn.get_custom_connection([conn.base_url, 'handler', 'api', 'docs', '1_1'].join('/'), conn.headers)
|
54
|
+
@doc_meta = conn.get_custom_connection([conn.base_url, 'handler', 'api', 'docs', '1_1', 123, 'documentmeta'].join('/'), conn.headers)
|
55
|
+
}
|
56
|
+
|
57
|
+
You can also manually open and close connections if necessary:
|
58
|
+
conn = NolijWeb::Connection.new(config_hash_or_path_to_config_yaml)
|
59
|
+
conn.establish_connection
|
60
|
+
... do some stuff with custom connection methods.
|
61
|
+
conn.close_connection
|
43
62
|
|
44
63
|
== Contributing
|
45
64
|
|
data/lib/nolij_web/connection.rb
CHANGED
data/lib/nolij_web/handler.rb
CHANGED
@@ -14,7 +14,7 @@ module NolijWeb
|
|
14
14
|
@connection = Connection.new(@config)
|
15
15
|
end
|
16
16
|
|
17
|
-
# Folder contents
|
17
|
+
# Folder contents as Nokogiri XML
|
18
18
|
# required options: :folder_id
|
19
19
|
# additional options: :user_code, :user_id, :sort, :offset, :limit, :wfma_code
|
20
20
|
def folder_info(options = {}, &block)
|
@@ -31,6 +31,7 @@ module NolijWeb
|
|
31
31
|
folder = Nokogiri.XML(response)
|
32
32
|
end
|
33
33
|
|
34
|
+
# Folder contents as array
|
34
35
|
# Returns an array of hashes with the file info for each file in the folder
|
35
36
|
# See #folder_info for options
|
36
37
|
def folder_contents(options = {}, &block)
|
@@ -83,7 +84,7 @@ module NolijWeb
|
|
83
84
|
end
|
84
85
|
|
85
86
|
# Print one or more documents to a single pdf
|
86
|
-
# required options:
|
87
|
+
# required options: :document_id - can be a number or an array of numbers
|
87
88
|
# additional options: :user_code, :document_id, :user_id
|
88
89
|
def print_document(options = {}, &block)
|
89
90
|
doc_ids = options.delete(:document_id)
|
@@ -98,6 +99,26 @@ module NolijWeb
|
|
98
99
|
@connection.get relative_path, headers.merge(:params => query_params), &block
|
99
100
|
end
|
100
101
|
|
102
|
+
# Return a jpeg of a page of a document
|
103
|
+
# required options: :document_id, :folder_id
|
104
|
+
# additional options: :user_code, :user_id, :rotation, :wpixels, :hpixels, :redact, :annot, :wfma_code, :page
|
105
|
+
# :page will default to 1 if no page is provided.
|
106
|
+
def retrieve_document_image(options = {}, &block)
|
107
|
+
folder_id = options[:folder_id]
|
108
|
+
document_id = options[:document_id].to_i
|
109
|
+
page = options[:page].to_i
|
110
|
+
page = page == 0 ? 1 : page
|
111
|
+
raise AttributeMissingError, 'Folder ID is required to retrieve a document.' unless folder_id.is_a?(String) && ! folder_id.empty?
|
112
|
+
raise AttributeMissingError, 'Document ID is required to retrieve a document.' unless document_id > 0
|
113
|
+
|
114
|
+
allowed_query_params_keys = [:user_code, :user_id, :rotation, :wpixels, :hpixels, :redact, :annot, :wfma_code]
|
115
|
+
query_params = format_query_params(options, allowed_query_params_keys)
|
116
|
+
headers = options[:headers] || {}
|
117
|
+
relative_path = [@@doc_handler_path, folder_id, document_id, 'page', page].join('/')
|
118
|
+
|
119
|
+
@connection.get relative_path, headers.merge(:params => query_params), &block
|
120
|
+
end
|
121
|
+
|
101
122
|
# Delete a document
|
102
123
|
# required options: :document_id, :folder_id
|
103
124
|
# additional options: :user_code, :user_id, :wfma_code
|
@@ -115,6 +136,36 @@ module NolijWeb
|
|
115
136
|
@connection.delete relative_path, headers.merge(:params => query_params), &block
|
116
137
|
end
|
117
138
|
|
139
|
+
# Retrieve metadata for a document as XML
|
140
|
+
# required options: :document_id, :folder_id
|
141
|
+
# additional options: :user_code, :user_id, :start, :end, :wfma_code
|
142
|
+
def document_metadata_xml(options = {}, &block)
|
143
|
+
folder_id = options[:folder_id]
|
144
|
+
document_id = options[:document_id].to_i
|
145
|
+
raise AttributeMissingError, 'Folder ID is required to retrieve a document.' unless folder_id.is_a?(String) && ! folder_id.empty?
|
146
|
+
raise AttributeMissingError, 'Document ID is required to retrieve a document.' unless document_id > 0
|
147
|
+
|
148
|
+
allowed_query_params_keys = [:user_code, :user_id, :start, :end, :wfma_code]
|
149
|
+
query_params = format_query_params(options, allowed_query_params_keys)
|
150
|
+
headers = options[:headers] || {}
|
151
|
+
relative_path = [@@doc_handler_path, folder_id, document_id, 'documentmeta'].join('/')
|
152
|
+
|
153
|
+
response = @connection.get relative_path, headers.merge(:params => query_params), &block
|
154
|
+
doc = Nokogiri.XML(response)
|
155
|
+
end
|
156
|
+
|
157
|
+
# Retrieve metadata for a document as a hash
|
158
|
+
# see #document_metadata_xml for options
|
159
|
+
def document_metadata(options = {}, &block)
|
160
|
+
doc = document_metadata_xml(options, &block)
|
161
|
+
node = doc.xpath('/documentmeta').first
|
162
|
+
doc_metadata = node.attributes.inject({}){|n, (k,v)| n[k] = v.value; n}
|
163
|
+
doc_metadata['pages'] = node.xpath('//pagemeta').collect{|p|
|
164
|
+
p.attributes.inject({}){|n, (k,v)| n[k] = v.value; n}
|
165
|
+
}
|
166
|
+
return doc_metadata
|
167
|
+
end
|
168
|
+
|
118
169
|
# URL or path to verify that user is authenticated to Nolijweb in their browser.
|
119
170
|
# If the user is logged in redirect them to :redir path.
|
120
171
|
# If not, redirect to login and return them to the URL provided once they've authenticated.
|
data/lib/nolij_web/version.rb
CHANGED
data/nolij_web.gemspec
CHANGED
@@ -8,9 +8,9 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.version = NolijWeb::Version::VERSION
|
9
9
|
spec.authors = ["Shannon Henderson"]
|
10
10
|
spec.email = ["shenders@reed.edu"]
|
11
|
-
spec.description = %q{A Ruby wrapper for the
|
11
|
+
spec.description = %q{A Ruby wrapper for the Nolij Web API}
|
12
12
|
spec.summary = %q{Interact with Nolijweb's REST API}
|
13
|
-
spec.homepage = ""
|
13
|
+
spec.homepage = "https://github.com/reed-college/nolij_web/"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
16
|
spec.files = `git ls-files`.split($/)
|
@@ -111,6 +111,73 @@ describe NolijWeb::Handler do
|
|
111
111
|
end
|
112
112
|
end
|
113
113
|
|
114
|
+
|
115
|
+
describe '#retrieve_document_image' do
|
116
|
+
before do
|
117
|
+
@document_id = '12345'
|
118
|
+
@folder_id = '111_2'
|
119
|
+
@stubbed_request = stub_request(:get, /\/handler\/api\/docs\/#{@folder_id}\/#{@document_id}\/page\/1/).to_return(:status => 200)
|
120
|
+
end
|
121
|
+
|
122
|
+
it "should raise missing attribute if no document id supplied" do
|
123
|
+
err = lambda{@handler.retrieve_document_image(:folder_id => '1243')}.must_raise(NolijWeb::AttributeMissingError)
|
124
|
+
err.to_s.must_match /document ID is required/i
|
125
|
+
end
|
126
|
+
|
127
|
+
it "should raise missing attribute if no folder id supplied" do
|
128
|
+
err = lambda{@handler.retrieve_document_image(:document_id => '123')}.must_raise(NolijWeb::AttributeMissingError)
|
129
|
+
err.to_s.must_match /folder ID is required/i
|
130
|
+
end
|
131
|
+
|
132
|
+
it "should get document image" do
|
133
|
+
@handler.retrieve_document_image(:document_id => @document_id, :folder_id => @folder_id, :page => 1)
|
134
|
+
assert_requested @stubbed_request
|
135
|
+
end
|
136
|
+
|
137
|
+
it "should set page to 1 when no page" do
|
138
|
+
@handler.retrieve_document_image(:document_id => @document_id, :folder_id => @folder_id)
|
139
|
+
assert_requested @stubbed_request
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
describe "document_metadata methods" do
|
144
|
+
before do
|
145
|
+
@folder_id = '1_2'
|
146
|
+
@document_id = '1111'
|
147
|
+
response = File.new(File.join(File.expand_path(File.dirname(__FILE__)), 'test_stubs', 'document_metadata.xml'))
|
148
|
+
@stubbed_request = stub_request(:get, /\/handler\/api\/docs\/#{@folder_id}\/#{@document_id}\/documentmeta/).to_return(:status => 200, :body => response)
|
149
|
+
end
|
150
|
+
|
151
|
+
describe '#document_metadata_xml' do
|
152
|
+
it "should raise missing attribute if no folder id is supplied" do
|
153
|
+
err = lambda{@handler.document_metadata_xml(:document_id => @document_id)}.must_raise(NolijWeb::AttributeMissingError)
|
154
|
+
err.to_s.must_match /Folder ID is required/i
|
155
|
+
end
|
156
|
+
|
157
|
+
it "should raise missing attribute if no document_id is supplied" do
|
158
|
+
err = lambda{@handler.document_metadata_xml(:folder_id => @folder_id)}.must_raise(NolijWeb::AttributeMissingError)
|
159
|
+
err.to_s.must_match /document ID is required/i
|
160
|
+
end
|
161
|
+
|
162
|
+
it "should get stubbed url" do
|
163
|
+
document_metadata = @handler.document_metadata_xml(:folder_id => @folder_id, :document_id => @document_id)
|
164
|
+
assert_requested @stubbed_request
|
165
|
+
end
|
166
|
+
|
167
|
+
it "should return nokogiri xml document" do
|
168
|
+
document_metadata = @handler.document_metadata_xml(:folder_id => @folder_id, :document_id => @document_id)
|
169
|
+
document_metadata.must_be_kind_of(Nokogiri::XML::Document)
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
describe '#document_metadata' do
|
174
|
+
it "should return nokogiri a hash" do
|
175
|
+
document_metadata = @handler.document_metadata(:folder_id => @folder_id, :document_id => @document_id)
|
176
|
+
document_metadata.must_be_kind_of(Hash)
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
114
181
|
describe '#viewer_url' do
|
115
182
|
it "should raise missing attribute if no document id supplied" do
|
116
183
|
err = lambda{@handler.viewer_url}.must_raise(NolijWeb::AttributeMissingError)
|
@@ -0,0 +1,9 @@
|
|
1
|
+
<?xml version="1.0"?>
|
2
|
+
<documentmeta documentid="1111" folderid="1_2" docname="AAPP Application" subfolder="Previous Apps" datecreated="2014-02-26 23:25:54.0 UTC" createdby="JOES" startpage="1" endpage="6" totalpagecount="6" filesize="1408598">
|
3
|
+
<pagemeta page="1" rotationquads="0" height="6600" width="5120" hasannotations="false"/>
|
4
|
+
<pagemeta page="2" rotationquads="0" height="6600" width="5120" hasannotations="false"/>
|
5
|
+
<pagemeta page="3" rotationquads="0" height="6600" width="5120" hasannotations="false"/>
|
6
|
+
<pagemeta page="4" rotationquads="0" height="6600" width="5120" hasannotations="true"/>
|
7
|
+
<pagemeta page="5" rotationquads="0" height="6600" width="5120" hasannotations="false"/>
|
8
|
+
<pagemeta page="6" rotationquads="0" height="6600" width="5120" hasannotations="false"/>
|
9
|
+
</documentmeta>
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nolij_web
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -107,7 +107,7 @@ dependencies:
|
|
107
107
|
- - ~>
|
108
108
|
- !ruby/object:Gem::Version
|
109
109
|
version: '1.13'
|
110
|
-
description: A Ruby wrapper for the
|
110
|
+
description: A Ruby wrapper for the Nolij Web API
|
111
111
|
email:
|
112
112
|
- shenders@reed.edu
|
113
113
|
executables: []
|
@@ -135,6 +135,7 @@ files:
|
|
135
135
|
- test/nolij_web/connection_test.rb
|
136
136
|
- test/nolij_web/handler_test.rb
|
137
137
|
- test/nolij_web/test_stubs/bad_nolij_config.yml
|
138
|
+
- test/nolij_web/test_stubs/document_metadata.xml
|
138
139
|
- test/nolij_web/test_stubs/document_submitted_success.xml
|
139
140
|
- test/nolij_web/test_stubs/folder_info.xml
|
140
141
|
- test/nolij_web/test_stubs/nolij_config.yml
|
@@ -142,7 +143,7 @@ files:
|
|
142
143
|
- test/nolij_web/test_stubs/version_info.xml
|
143
144
|
- test/nolij_web/version_test.rb
|
144
145
|
- test/test_helper.rb
|
145
|
-
homepage:
|
146
|
+
homepage: https://github.com/reed-college/nolij_web/
|
146
147
|
licenses:
|
147
148
|
- MIT
|
148
149
|
post_install_message:
|
@@ -178,6 +179,7 @@ test_files:
|
|
178
179
|
- test/nolij_web/connection_test.rb
|
179
180
|
- test/nolij_web/handler_test.rb
|
180
181
|
- test/nolij_web/test_stubs/bad_nolij_config.yml
|
182
|
+
- test/nolij_web/test_stubs/document_metadata.xml
|
181
183
|
- test/nolij_web/test_stubs/document_submitted_success.xml
|
182
184
|
- test/nolij_web/test_stubs/folder_info.xml
|
183
185
|
- test/nolij_web/test_stubs/nolij_config.yml
|