gi_cat_driver 0.2.4 → 0.2.5
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.
- data/README.md +2 -0
- data/lib/gi_cat_driver.rb +43 -2
- data/lib/gi_cat_driver/version.rb +1 -1
- data/spec/gi_cat_driver_spec.rb +55 -7
- metadata +2 -2
data/README.md
CHANGED
@@ -43,6 +43,8 @@ Annotated source code documentation is available at http://nsidc.github.com/gi_c
|
|
43
43
|
Rubydoc API documentation is available at http://rubydoc.info/gems/gi_cat_driver/
|
44
44
|
|
45
45
|
## Version History
|
46
|
+
* 0.2.5
|
47
|
+
* Added new methods to enable and disable published profilers (GI-Cat interfaces) for a profile
|
46
48
|
* 0.2.4
|
47
49
|
* Added new methods to create and delete accessors (GI-Cat resources) for a profile
|
48
50
|
* 0.2.3
|
data/lib/gi_cat_driver.rb
CHANGED
@@ -16,6 +16,7 @@ module GiCatDriver
|
|
16
16
|
class GiCat
|
17
17
|
|
18
18
|
ATOM_NAMESPACE = { "atom" => "http://www.w3.org/2005/Atom" }
|
19
|
+
OPENSEARCH_NAMESPACE = { "opensearch" => "http://a9.com/-/spec/opensearch/1.1/" }
|
19
20
|
RELEVANCE_NAMESPACE = { "relevance" => "http://a9.com/-/opensearch/extensions/relevance/1.0/" }
|
20
21
|
attr_accessor :base_url
|
21
22
|
|
@@ -105,13 +106,25 @@ module GiCatDriver
|
|
105
106
|
set_lucene_enabled false
|
106
107
|
end
|
107
108
|
|
109
|
+
# Perform an ESIP OpenSearch query using a search term against GI-Cat and returns a Nokogiri XML document
|
110
|
+
def query_esip_opensearch( search_term )
|
111
|
+
query_string = EsipOpensearchQueryBuilder::get_query_string({ :st => search_term })
|
112
|
+
|
113
|
+
begin
|
114
|
+
file = open("#{@base_url}/services/opensearchesip#{query_string}")
|
115
|
+
rescue => e
|
116
|
+
raise "Failed to query GI-Cat ESIP OpenSearch interface."
|
117
|
+
end
|
118
|
+
|
119
|
+
return Nokogiri::XML(file)
|
120
|
+
end
|
121
|
+
|
108
122
|
# Find out whether Lucene indexing is turned on for the current profile
|
109
123
|
# It is desirable to use REST to query GI-Cat for the value of this setting but GI-Cat does not yet support this.
|
110
124
|
# Instead, run a query and check that a 'relevance:score' element is present.
|
111
125
|
# Returns true if Lucene is turned on
|
112
126
|
def is_lucene_enabled?
|
113
|
-
|
114
|
-
results = Nokogiri::XML(open("#{@base_url}/services/opensearchesip#{query_string}"))
|
127
|
+
results = query_esip_opensearch("arctic%20alaskan%20shrubs")
|
115
128
|
|
116
129
|
result_scores = results.xpath('//atom:feed/atom:entry/relevance:score', ATOM_NAMESPACE.merge(RELEVANCE_NAMESPACE))
|
117
130
|
result_scores.map { |score| score.text }
|
@@ -119,6 +132,11 @@ module GiCatDriver
|
|
119
132
|
return result_scores.count > 0
|
120
133
|
end
|
121
134
|
|
135
|
+
# Parse the totalResults element in an OpenSearch ESIP XML document
|
136
|
+
def get_total_results( xml_doc )
|
137
|
+
return xml_doc.xpath('//atom:feed/opensearch:totalResults', ATOM_NAMESPACE.merge(OPENSEARCH_NAMESPACE)).text.to_i
|
138
|
+
end
|
139
|
+
|
122
140
|
# Harvest all resource in the active profile
|
123
141
|
# The default timeout is 1500 seconds (25 minutes)
|
124
142
|
def harvest_all_resources_for_active_configuration timeout=1500
|
@@ -159,6 +177,29 @@ module GiCatDriver
|
|
159
177
|
end
|
160
178
|
end
|
161
179
|
|
180
|
+
# Publish an interface to access GI-Cat data for the given profile name
|
181
|
+
# The interface_configuration is a hash that defines a 'profiler' and 'path'
|
182
|
+
def publish_interface( profile_name, interface_configuration )
|
183
|
+
profile_id = find_profile_id(profile_name)
|
184
|
+
|
185
|
+
response = Faraday.post do |req|
|
186
|
+
req.url "#{@base_url}/services/conf/brokerConfigurations/#{profile_id}/profilers/"
|
187
|
+
req.headers = AUTHORIZATION_HEADERS.merge({:enctype=>'multipart/form-data', :content_type=>'application/x-www-form-urlencoded'})
|
188
|
+
req.body = interface_configuration
|
189
|
+
end
|
190
|
+
|
191
|
+
return response.body
|
192
|
+
end
|
193
|
+
|
194
|
+
def unpublish_interface( profile_name, interface_name )
|
195
|
+
profile_id = find_profile_id(profile_name)
|
196
|
+
|
197
|
+
Faraday.get do |req|
|
198
|
+
req.url "#{@base_url}/services/conf/brokerConfigurations/#{profile_id}/profilers/#{interface_name}", { :delete => 'true', :random => generate_random_number }
|
199
|
+
req.headers = AUTHORIZATION_HEADERS.merge({:enctype=>'multipart/form-data', :content_type=>'application/x-www-form-urlencoded'})
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
162
203
|
#### Private Methods
|
163
204
|
|
164
205
|
private
|
data/spec/gi_cat_driver_spec.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
require 'gi_cat_driver'
|
3
2
|
require 'webmock/rspec'
|
3
|
+
require 'gi_cat_driver'
|
4
4
|
|
5
5
|
describe GiCatDriver do
|
6
6
|
before(:all) do
|
@@ -170,12 +170,7 @@ describe GiCatDriver do
|
|
170
170
|
}, :query => {:opts => "active"})
|
171
171
|
.to_return(:status => 200, :body => "", :headers => {})
|
172
172
|
|
173
|
-
|
174
|
-
stub_request(:get, query_url)
|
175
|
-
.with(:headers => {
|
176
|
-
'Accept'=>'*/*',
|
177
|
-
'User-Agent'=>'Ruby'
|
178
|
-
}).to_return(:status => 200, :body => File.new("spec/fixtures/opensearchesip_lucene_enabled.xml"), :headers => {})
|
173
|
+
@gi_cat.stub(:open).and_return File.new("spec/fixtures/opensearchesip_lucene_enabled.xml")
|
179
174
|
|
180
175
|
@gi_cat.enable_lucene
|
181
176
|
|
@@ -274,6 +269,59 @@ describe GiCatDriver do
|
|
274
269
|
end
|
275
270
|
end
|
276
271
|
|
272
|
+
describe "profiler (published interface) configurations" do
|
273
|
+
it "publishes the opensearch esip interface" do
|
274
|
+
profile_name = "some_profile"
|
275
|
+
interface_config = {:profiler => "OPENSEARCH-ESIP", :path => "opensearchesip?"}
|
276
|
+
|
277
|
+
active_conf_url = "http://admin:pass@www.somecompany.com/services/conf/brokerConfigurations"
|
278
|
+
stub_request(:get,active_conf_url)
|
279
|
+
.with(:headers => {
|
280
|
+
'Accept'=>'application/xml',
|
281
|
+
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
|
282
|
+
'User-Agent'=>'Ruby',
|
283
|
+
'Content-Type'=>'*/*'
|
284
|
+
}, :query => {:nameRepository => "gicat"})
|
285
|
+
.to_return(:status => 200, :body => File.new("spec/fixtures/brokerConfigurations.xml"), :headers => {})
|
286
|
+
|
287
|
+
stub_request(:post, "http://admin:pass@www.somecompany.com/services/conf/brokerConfigurations/1/profilers/").
|
288
|
+
with(:body => {"path"=>"opensearchesip?", "profiler"=>"OPENSEARCH-ESIP"},
|
289
|
+
:headers => {'Accept'=>'application/xml', 'Content-Type'=>'application/x-www-form-urlencoded', 'Enctype'=>'multipart/form-data', 'User-Agent'=>'Ruby'}).
|
290
|
+
to_return(:status => 200, :body => "save", :headers => {})
|
291
|
+
|
292
|
+
@gi_cat.stub(:open).and_return File.new("spec/fixtures/opensearchesip_lucene_enabled.xml")
|
293
|
+
|
294
|
+
response = @gi_cat.publish_interface(profile_name, interface_config)
|
295
|
+
response.should eql("save")
|
296
|
+
result_xml = @gi_cat.query_esip_opensearch("arctic%20alaskan%20shrubs")
|
297
|
+
@gi_cat.get_total_results(result_xml).should be > 0
|
298
|
+
end
|
299
|
+
|
300
|
+
it "unpublishes the opensearch esip interface" do
|
301
|
+
profile_name = "some_profile"
|
302
|
+
interface_name = "OPENSEARCH-ESIP"
|
303
|
+
|
304
|
+
active_conf_url = "http://admin:pass@www.somecompany.com/services/conf/brokerConfigurations"
|
305
|
+
stub_request(:get,active_conf_url)
|
306
|
+
.with(:headers => {
|
307
|
+
'Accept'=>'application/xml',
|
308
|
+
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
|
309
|
+
'User-Agent'=>'Ruby',
|
310
|
+
'Content-Type'=>'*/*'
|
311
|
+
}, :query => {:nameRepository => "gicat"})
|
312
|
+
.to_return(:status => 200, :body => File.new("spec/fixtures/brokerConfigurations.xml"), :headers => {})
|
313
|
+
|
314
|
+
@gi_cat.stub(:generate_random_number).and_return("1")
|
315
|
+
|
316
|
+
stub_request(:get, "http://admin:pass@www.somecompany.com/services/conf/brokerConfigurations/1/profilers/OPENSEARCH-ESIP?delete=true&random=1").
|
317
|
+
with(:headers => {'Accept'=>'application/xml', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Type'=>'application/x-www-form-urlencoded', 'Enctype'=>'multipart/form-data', 'User-Agent'=>'Ruby'}).
|
318
|
+
to_return(:status => 200, :body => "", :headers => {})
|
319
|
+
|
320
|
+
@gi_cat.unpublish_interface profile_name, interface_name
|
321
|
+
lambda {@gi_cat.query_esip_opensearch "arctic%20alaskan%20shrubs"}.should raise_error(RuntimeError)
|
322
|
+
end
|
323
|
+
end
|
324
|
+
|
277
325
|
describe "accessor (xml feed resource) configurations" do
|
278
326
|
it "creates a new feed resource for a profile" do
|
279
327
|
profile_name = 'some_profile'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gi_cat_driver
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2013-04-
|
13
|
+
date: 2013-04-22 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: faraday
|