gi_cat_driver 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -1
- data/LICENSE.txt +4 -1
- data/README.md +22 -2
- data/gi_cat_driver.gemspec +4 -4
- data/lib/gi_cat_driver.rb +23 -15
- data/lib/{esip_opensearch_query_builder.rb → gi_cat_driver/esip_opensearch_query_builder.rb} +0 -0
- data/lib/gi_cat_driver/version.rb +1 -1
- data/spec/gi_cat_driver_spec.rb +30 -35
- metadata +22 -53
data/Gemfile
CHANGED
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -18,12 +18,22 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
## Usage
|
20
20
|
|
21
|
-
|
21
|
+
Assuming you have a GI-Cat application running at http://www.company.com/api/gi-cat/
|
22
|
+
and an administrative login of username='admin', password='password' create a new GiCat
|
23
|
+
to start using the gem.
|
22
24
|
|
23
25
|
```ruby
|
24
26
|
gi_cat = GiCatDriver::GiCat.new('http://www.company.com/api/gi-cat', 'admin', 'password')
|
25
27
|
```
|
26
|
-
|
28
|
+
Note you must provide a URL to a running GI-Cat instance as well as the administrator username and password.
|
29
|
+
|
30
|
+
## API Documentation
|
31
|
+
|
32
|
+
Main API methods are
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
GiCatDriver
|
36
|
+
```
|
27
37
|
|
28
38
|
## Contributing
|
29
39
|
|
@@ -32,3 +42,13 @@ Please note you must provide a URL to a running GI-Cat instance as well as the a
|
|
32
42
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
33
43
|
4. Push to the branch (`git push origin my-new-feature`)
|
34
44
|
5. Create new Pull Request
|
45
|
+
|
46
|
+
## License
|
47
|
+
|
48
|
+
GI-Cat Driver is licensed under the MIT license. See [LICENSE.txt][license].
|
49
|
+
|
50
|
+
[license]: https://raw.github.com/nsidc/gi_cat_driver/master/LICENSE.txt
|
51
|
+
|
52
|
+
## Credit
|
53
|
+
|
54
|
+
This software was developed by the National Snow and Ice Data Center, sponsored by the National Science Foundation grant number OPP-10-16048.
|
data/gi_cat_driver.gemspec
CHANGED
@@ -18,10 +18,10 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
spec.add_dependency "rest-client"
|
22
|
-
spec.add_dependency "nokogiri"
|
21
|
+
spec.add_dependency "rest-client", "~> 1.6.7"
|
22
|
+
spec.add_dependency "nokogiri", "~> 1.5.6"
|
23
23
|
|
24
24
|
spec.add_development_dependency "bundler", "~> 1.3"
|
25
|
-
spec.add_development_dependency "rake"
|
26
|
-
spec.add_development_dependency "rspec"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0.3"
|
26
|
+
spec.add_development_dependency "rspec", "~> 2.13.0"
|
27
27
|
end
|
data/lib/gi_cat_driver.rb
CHANGED
@@ -1,27 +1,24 @@
|
|
1
1
|
require "gi_cat_driver/version"
|
2
|
-
require "esip_opensearch_query_builder"
|
2
|
+
require "gi_cat_driver/esip_opensearch_query_builder"
|
3
3
|
require "open-uri"
|
4
4
|
require "rest-client"
|
5
5
|
require "base64"
|
6
6
|
require 'nokogiri'
|
7
7
|
|
8
|
+
# The GI-Cat Driver
|
8
9
|
module GiCatDriver
|
9
10
|
class GiCat
|
10
11
|
|
11
12
|
ATOM_NAMESPACE = { "atom" => "http://www.w3.org/2005/Atom" }
|
12
13
|
RELEVANCE_NAMESPACE = { "relevance" => "http://a9.com/-/opensearch/extensions/relevance/1.0/" }
|
13
|
-
|
14
|
+
attr_accessor :base_url
|
15
|
+
|
14
16
|
def initialize( url, username, password )
|
15
|
-
|
16
|
-
|
17
|
+
self.base_url = url.sub(/\/+$/, '')
|
17
18
|
@admin_username = username
|
18
19
|
@admin_password = password
|
19
20
|
end
|
20
21
|
|
21
|
-
def base_url
|
22
|
-
@base_url
|
23
|
-
end
|
24
|
-
|
25
22
|
def basic_auth_string
|
26
23
|
"Basic " + Base64.encode64("#{@admin_username}:#{@admin_password}").rstrip
|
27
24
|
end
|
@@ -33,12 +30,15 @@ module GiCatDriver
|
|
33
30
|
}
|
34
31
|
end
|
35
32
|
|
33
|
+
# Check whether the URL is accessible
|
36
34
|
def is_running?
|
37
|
-
open(
|
35
|
+
open(self.base_url).status[0] == "200"
|
38
36
|
end
|
39
37
|
|
38
|
+
# Retrieve the ID for a profile given the name
|
39
|
+
# Returns an integer ID reference to the profile
|
40
40
|
def find_profile_id( profile_name )
|
41
|
-
get_profiles_request = "#{
|
41
|
+
get_profiles_request = "#{self.base_url}/services/conf/brokerConfigurations?nameRepository=gicat"
|
42
42
|
modified_headers = standard_headers.merge({
|
43
43
|
:content_type => "*/*",
|
44
44
|
:Accept => 'application/xml'
|
@@ -55,38 +55,46 @@ module GiCatDriver
|
|
55
55
|
return configs.css("brokerConfiguration[name=#{profile_name}]")
|
56
56
|
end
|
57
57
|
|
58
|
+
# Enable a profile with the specified name
|
58
59
|
def enable_profile( profile_name )
|
59
60
|
profile_id = find_profile_id(profile_name)
|
60
61
|
raise "The specified profile could not be found." if profile_id.nil?
|
61
|
-
activate_profile_request = "#{
|
62
|
+
activate_profile_request = "#{self.base_url}/services/conf/brokerConfigurations/#{profile_id}?opts=active"
|
62
63
|
|
63
64
|
RestClient.get(activate_profile_request, standard_headers)
|
64
65
|
end
|
65
66
|
|
67
|
+
# Retrieve the ID for the active profile
|
68
|
+
# Returns an integer ID reference to the active profile
|
66
69
|
def get_active_profile_id
|
67
|
-
active_profile_request = "#{
|
70
|
+
active_profile_request = "#{self.base_url}/services/conf/giconf/configuration"
|
68
71
|
|
69
72
|
return RestClient.get(active_profile_request, standard_headers)
|
70
73
|
end
|
71
74
|
|
75
|
+
# Enable Lucene indexes for GI-Cat search results
|
72
76
|
def enable_lucene
|
73
77
|
set_lucene_enabled true
|
74
78
|
end
|
75
79
|
|
76
80
|
def set_lucene_enabled( enabled )
|
77
|
-
enable_lucene_request = "#{
|
81
|
+
enable_lucene_request = "#{self.base_url}/services/conf/brokerConfigurations/#{get_active_profile_id}/luceneEnabled"
|
78
82
|
RestClient.put(enable_lucene_request,
|
79
83
|
enabled.to_s,
|
80
84
|
standard_headers)
|
81
85
|
|
82
|
-
activate_profile_request = "#{
|
86
|
+
activate_profile_request = "#{self.base_url}/services/conf/brokerConfigurations/#{get_active_profile_id}?opts=active"
|
83
87
|
RestClient.get(activate_profile_request,
|
84
88
|
standard_headers)
|
85
89
|
end
|
86
90
|
|
91
|
+
# Find out whether Lucene indexing is turned on for the current profile
|
92
|
+
# It is desirable to use REST to query GI-Cat for the value of this setting but GI-Cat does not yet support this.
|
93
|
+
# Instead, run a query and check that a 'relevance:score' element is present.
|
94
|
+
# Returns true if Lucene is turned on
|
87
95
|
def is_lucene_enabled?
|
88
96
|
query_string = EsipOpensearchQueryBuilder::get_query_string({ :st => "snow" })
|
89
|
-
results = Nokogiri::XML(open("#{
|
97
|
+
results = Nokogiri::XML(open("#{self.base_url}/services/opensearchesip#{query_string}"))
|
90
98
|
|
91
99
|
result_scores = results.xpath('//atom:feed/atom:entry/relevance:score', ATOM_NAMESPACE.merge(RELEVANCE_NAMESPACE))
|
92
100
|
result_scores.map { |score| score.text }
|
data/lib/{esip_opensearch_query_builder.rb → gi_cat_driver/esip_opensearch_query_builder.rb}
RENAMED
File without changes
|
data/spec/gi_cat_driver_spec.rb
CHANGED
@@ -3,21 +3,16 @@ require 'gi_cat_driver'
|
|
3
3
|
|
4
4
|
describe GiCatDriver do
|
5
5
|
before(:each) do
|
6
|
-
@base_url =
|
6
|
+
@base_url = "http://www.somecompany.com/"
|
7
7
|
@gi_cat = GiCatDriver::GiCat.new(@base_url, "admin", "abcd123$")
|
8
8
|
end
|
9
9
|
|
10
|
-
it "Initializes with a base url that points to an instance of GI-Cat" do
|
11
|
-
expected = @base_url.sub(/\/+$/, '')
|
12
|
-
@gi_cat.base_url.should eq(expected)
|
13
|
-
end
|
14
|
-
|
15
10
|
describe "Standard requests" do
|
16
|
-
it "Is able to send requests to GI-Cat" do
|
17
|
-
|
18
|
-
end
|
11
|
+
#it "Is able to send requests to GI-Cat" do
|
12
|
+
#@gi_cat.is_running?.should be_true
|
13
|
+
#end
|
19
14
|
|
20
|
-
|
15
|
+
it "Sends requests with basic header information" do
|
21
16
|
@gi_cat.standard_headers[:content_type].should eq "application/xml"
|
22
17
|
end
|
23
18
|
|
@@ -26,29 +21,29 @@ describe GiCatDriver do
|
|
26
21
|
end
|
27
22
|
end
|
28
23
|
|
29
|
-
describe "Profile management" do
|
30
|
-
it "Retrieves a profile id given the name" do
|
31
|
-
|
32
|
-
end
|
33
|
-
|
34
|
-
it "Throws an error if the profile cannot be found" do
|
35
|
-
|
36
|
-
end
|
37
|
-
|
38
|
-
it "Enables a profile given the name" do
|
39
|
-
|
40
|
-
|
41
|
-
end
|
42
|
-
|
43
|
-
it "Does not enable a profile if the profile cannot be found" do
|
44
|
-
expect { @gi_cat.enable_profile("notaprofile") }.to raise_error("The specified profile could not be found.")
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
describe "Lucene Indexing" do
|
49
|
-
it "Enables Lucene for the active profile" do
|
50
|
-
|
51
|
-
|
52
|
-
end
|
53
|
-
end
|
24
|
+
#describe "Profile management" do
|
25
|
+
#it "Retrieves a profile id given the name" do
|
26
|
+
#@gi_cat.find_profile_id("NORWEGIAN_CISL_NSIDC_EOL").should eq "1"
|
27
|
+
#end
|
28
|
+
|
29
|
+
#it "Throws an error if the profile cannot be found" do
|
30
|
+
#@gi_cat.find_profile_id("notaprofile").should be_nil
|
31
|
+
#end
|
32
|
+
|
33
|
+
#it "Enables a profile given the name" do
|
34
|
+
#@gi_cat.enable_profile("NORWEGIAN_CISL_NSIDC_EOL")
|
35
|
+
#@gi_cat.get_active_profile_id.should eq "1"
|
36
|
+
#end
|
37
|
+
|
38
|
+
#it "Does not enable a profile if the profile cannot be found" do
|
39
|
+
#expect { @gi_cat.enable_profile("notaprofile") }.to raise_error("The specified profile could not be found.")
|
40
|
+
#end
|
41
|
+
#end
|
42
|
+
|
43
|
+
#describe "Lucene Indexing" do
|
44
|
+
#it "Enables Lucene for the active profile" do
|
45
|
+
#@gi_cat.enable_lucene
|
46
|
+
#@gi_cat.is_lucene_enabled?.should be_true
|
47
|
+
#end
|
48
|
+
#end
|
54
49
|
end
|
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.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,43 +9,33 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-03-
|
12
|
+
date: 2013-03-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rest-client
|
16
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirement: &70146178028220 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
|
-
- -
|
19
|
+
- - ~>
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version:
|
21
|
+
version: 1.6.7
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
25
|
-
none: false
|
26
|
-
requirements:
|
27
|
-
- - ! '>='
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: '0'
|
24
|
+
version_requirements: *70146178028220
|
30
25
|
- !ruby/object:Gem::Dependency
|
31
26
|
name: nokogiri
|
32
|
-
requirement: !ruby/object:Gem::Requirement
|
27
|
+
requirement: &70146178027640 !ruby/object:Gem::Requirement
|
33
28
|
none: false
|
34
29
|
requirements:
|
35
|
-
- -
|
30
|
+
- - ~>
|
36
31
|
- !ruby/object:Gem::Version
|
37
|
-
version:
|
32
|
+
version: 1.5.6
|
38
33
|
type: :runtime
|
39
34
|
prerelease: false
|
40
|
-
version_requirements:
|
41
|
-
none: false
|
42
|
-
requirements:
|
43
|
-
- - ! '>='
|
44
|
-
- !ruby/object:Gem::Version
|
45
|
-
version: '0'
|
35
|
+
version_requirements: *70146178027640
|
46
36
|
- !ruby/object:Gem::Dependency
|
47
37
|
name: bundler
|
48
|
-
requirement: !ruby/object:Gem::Requirement
|
38
|
+
requirement: &70146178027140 !ruby/object:Gem::Requirement
|
49
39
|
none: false
|
50
40
|
requirements:
|
51
41
|
- - ~>
|
@@ -53,44 +43,29 @@ dependencies:
|
|
53
43
|
version: '1.3'
|
54
44
|
type: :development
|
55
45
|
prerelease: false
|
56
|
-
version_requirements:
|
57
|
-
none: false
|
58
|
-
requirements:
|
59
|
-
- - ~>
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '1.3'
|
46
|
+
version_requirements: *70146178027140
|
62
47
|
- !ruby/object:Gem::Dependency
|
63
48
|
name: rake
|
64
|
-
requirement: !ruby/object:Gem::Requirement
|
49
|
+
requirement: &70146178026620 !ruby/object:Gem::Requirement
|
65
50
|
none: false
|
66
51
|
requirements:
|
67
|
-
- -
|
52
|
+
- - ~>
|
68
53
|
- !ruby/object:Gem::Version
|
69
|
-
version:
|
54
|
+
version: 10.0.3
|
70
55
|
type: :development
|
71
56
|
prerelease: false
|
72
|
-
version_requirements:
|
73
|
-
none: false
|
74
|
-
requirements:
|
75
|
-
- - ! '>='
|
76
|
-
- !ruby/object:Gem::Version
|
77
|
-
version: '0'
|
57
|
+
version_requirements: *70146178026620
|
78
58
|
- !ruby/object:Gem::Dependency
|
79
59
|
name: rspec
|
80
|
-
requirement: !ruby/object:Gem::Requirement
|
60
|
+
requirement: &70146178026160 !ruby/object:Gem::Requirement
|
81
61
|
none: false
|
82
62
|
requirements:
|
83
|
-
- -
|
63
|
+
- - ~>
|
84
64
|
- !ruby/object:Gem::Version
|
85
|
-
version:
|
65
|
+
version: 2.13.0
|
86
66
|
type: :development
|
87
67
|
prerelease: false
|
88
|
-
version_requirements:
|
89
|
-
none: false
|
90
|
-
requirements:
|
91
|
-
- - ! '>='
|
92
|
-
- !ruby/object:Gem::Version
|
93
|
-
version: '0'
|
68
|
+
version_requirements: *70146178026160
|
94
69
|
description: Configure and control deployed instances of GI-Cat.
|
95
70
|
email:
|
96
71
|
- stuart.reed@nsidc.org
|
@@ -106,8 +81,8 @@ files:
|
|
106
81
|
- README.md
|
107
82
|
- Rakefile
|
108
83
|
- gi_cat_driver.gemspec
|
109
|
-
- lib/esip_opensearch_query_builder.rb
|
110
84
|
- lib/gi_cat_driver.rb
|
85
|
+
- lib/gi_cat_driver/esip_opensearch_query_builder.rb
|
111
86
|
- lib/gi_cat_driver/version.rb
|
112
87
|
- spec/esip_opensearch_query_builder_spec.rb
|
113
88
|
- spec/gi_cat_driver_spec.rb
|
@@ -125,21 +100,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
125
100
|
- - ! '>='
|
126
101
|
- !ruby/object:Gem::Version
|
127
102
|
version: '0'
|
128
|
-
segments:
|
129
|
-
- 0
|
130
|
-
hash: -2265981651223281896
|
131
103
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
132
104
|
none: false
|
133
105
|
requirements:
|
134
106
|
- - ! '>='
|
135
107
|
- !ruby/object:Gem::Version
|
136
108
|
version: '0'
|
137
|
-
segments:
|
138
|
-
- 0
|
139
|
-
hash: -2265981651223281896
|
140
109
|
requirements: []
|
141
110
|
rubyforge_project:
|
142
|
-
rubygems_version: 1.8.
|
111
|
+
rubygems_version: 1.8.15
|
143
112
|
signing_key:
|
144
113
|
specification_version: 3
|
145
114
|
summary: Configure and control deployed instances of GI-Cat.
|