gi_cat_driver 0.2.3 → 0.2.4

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/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- gi_cat_driver (0.2.2)
4
+ gi_cat_driver (0.2.4)
5
5
  faraday (~> 0.8.7)
6
6
  nokogiri (~> 1.5.6)
7
7
 
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.4
47
+ * Added new methods to create and delete accessors (GI-Cat resources) for a profile
46
48
  * 0.2.3
47
49
  * Changed the harvest to be sequential. (one resource won't start harvest till the current one is completed or timeout)
48
50
  * 0.2.2
@@ -1,3 +1,3 @@
1
1
  module GiCatDriver
2
- VERSION = "0.2.3"
2
+ VERSION = "0.2.4"
3
3
  end
data/lib/gi_cat_driver.rb CHANGED
@@ -129,6 +129,36 @@ module GiCatDriver
129
129
  end
130
130
  end
131
131
 
132
+ # Create an accessor (xml feed resource) for the given profile with the provided accessor configuration
133
+ def create_accessor( profile_name, accessor_configuration )
134
+ profile_id = find_profile_id( profile_name )
135
+ distributor_id = get_active_profile_distributor_id(profile_id)
136
+
137
+ response = Faraday.post do |req|
138
+ req.url "#{@base_url}/services/conf/brokerConfigurations/#{profile_id}/distributors/#{distributor_id}"
139
+ req.headers = AUTHORIZATION_HEADERS.merge({:enctype=>'multipart/form-data', :content_type=>'application/x-www-form-urlencoded'})
140
+ req.body = accessor_configuration
141
+ end
142
+
143
+ # The response contains a comma separated list of the accessor id as well as the harvester id
144
+ (accessor_id, harvester_id) = response.body.split(',', 2)
145
+
146
+ update_accessor_configuration( profile_id, accessor_id, accessor_configuration )
147
+
148
+ return accessor_id
149
+ end
150
+
151
+ # Remove an accessor (xml feed resource) with the given name from the given profile
152
+ def delete_accessor( profile_name, accessor_name )
153
+ profile_id = find_profile_id(profile_name)
154
+ harvester_id = find_harvester_id(profile_name, accessor_name)
155
+
156
+ Faraday.get do |req|
157
+ req.url "#{@base_url}/services/conf/brokerConfigurations/#{profile_id}/harvesters/#{harvester_id}", { :delete => 'true', :random => generate_random_number }
158
+ req.headers = AUTHORIZATION_HEADERS.merge({:enctype=>'multipart/form-data'})
159
+ end
160
+ end
161
+
132
162
  #### Private Methods
133
163
 
134
164
  private
@@ -147,15 +177,37 @@ module GiCatDriver
147
177
  AUTHORIZATION_HEADERS)
148
178
  end
149
179
 
150
- # Retrive the distributor id given a profile id
151
- def get_active_profile_distributor_id(id)
152
- active_profile_request = "#{@base_url}/services/conf/brokerConfigurations/#{id}"
180
+ # Retrieve the harvester id given a profile name and accessor name
181
+ def find_harvester_id( profile_name, accessor_name )
182
+ profile_id = find_profile_id(profile_name)
183
+
184
+ distributor_id = get_active_profile_distributor_id(profile_id)
185
+
186
+ harvester_id = get_active_profile_harvester_id(profile_id, distributor_id)
187
+
188
+ return harvester_id
189
+ end
190
+
191
+ # Retrieve the distributor id given a profile id
192
+ def get_active_profile_distributor_id(profile_id)
193
+ active_profile_request = "#{@base_url}/services/conf/brokerConfigurations/#{profile_id}"
153
194
  response = Faraday.get do |req|
154
195
  req.url active_profile_request
155
196
  req.headers = AUTHORIZATION_HEADERS
156
197
  end
157
- id = Nokogiri.XML(response.body).css("component id").text
158
- return id
198
+ distributor_id = Nokogiri.XML(response.body).css("component id").text
199
+ return distributor_id
200
+ end
201
+
202
+ # Retrieve the harvester id given a profile id and distributor id
203
+ def get_active_profile_harvester_id(profile_id, distributor_id)
204
+ harvester_request = "#{@base_url}/services/conf/brokerConfigurations/#{profile_id}/distributors/#{distributor_id}"
205
+ response = Faraday.get do |req|
206
+ req.url harvester_request
207
+ req.headers = AUTHORIZATION_HEADERS
208
+ end
209
+ harvester_id = Nokogiri.XML(response.body).css("component id").text
210
+ return harvester_id
159
211
  end
160
212
 
161
213
  # Given a profile id, put all the associated resource id and title into harvest info array
@@ -251,6 +303,15 @@ module GiCatDriver
251
303
 
252
304
  end
253
305
 
306
+ def update_accessor_configuration( profile_id, accessor_id, accessor_configuration )
307
+ response = Faraday.post do |req|
308
+ req.url "#{@base_url}/services/conf/brokerConfigurations/#{profile_id}/accessors/#{accessor_id}/update"
309
+ req.headers = AUTHORIZATION_HEADERS.merge({:enctype=>'multipart/form-data', :content_type=>'application/x-www-form-urlencoded'})
310
+ req.body = accessor_configuration
311
+ end
312
+ return response.body
313
+ end
314
+
254
315
  def generate_random_number
255
316
  return rand
256
317
  end
@@ -0,0 +1,2 @@
1
+ <?xml version="1.0" encoding="UTF-8" standalone="yes"?><distributors xmlns="http://imaa.cnr.it/sdi/services/7.0/configurationMessages/schema"><distributor id="UUID-f446ba0c-ad5c-44
2
+ 1e-ba66-269042d4f86e"><component><id>UUID-dfe61211-56f4-4fb9-9f99-a7f4d95916c</id><type>Harvester</type><title>fixture-nsidc-oai</title></component></distributor></distributors>
@@ -83,7 +83,7 @@ describe GiCatDriver do
83
83
  'User-Agent'=>'Ruby',
84
84
  'Content-Type'=>'*/*'
85
85
  }, :query => {:opts => "active"})
86
- .to_return(:status => 200, :body => File.new("spec/fixtures/brokerConfigurations.xml"), :headers => {})
86
+ .to_return(:status => 200, :body => "", :headers => {})
87
87
 
88
88
  active_conf_url = "http://admin:pass@www.somecompany.com/services/conf/brokerConfigurations"
89
89
  stub_request(:get,active_conf_url)
@@ -168,7 +168,7 @@ describe GiCatDriver do
168
168
  'User-Agent'=>'Faraday v0.8.7',
169
169
  'Content-Type'=>'*/*'
170
170
  }, :query => {:opts => "active"})
171
- .to_return(:status => 200, :body => File.new("spec/fixtures/brokerConfigurations.xml"), :headers => {})
171
+ .to_return(:status => 200, :body => "", :headers => {})
172
172
 
173
173
  query_url = "http://www.somecompany.com/services/opensearchesip?bbox=&ct=&gdc=&lac=&loc=&luc=&outputFormat=&rel=&si=&st=arctic%20alaskan%20shrubs&te=&ts="
174
174
  stub_request(:get, query_url)
@@ -208,7 +208,7 @@ describe GiCatDriver do
208
208
  'User-Agent'=>'Faraday v0.8.7',
209
209
  'Content-Type'=>'*/*'
210
210
  }, :query => {:opts => "active"})
211
- .to_return(:status => 200, :body => File.new("spec/fixtures/brokerConfigurations.xml"), :headers => {})
211
+ .to_return(:status => 200, :body => "", :headers => {})
212
212
 
213
213
  query_url = "http://www.somecompany.com/services/opensearchesip?bbox=&ct=&gdc=&lac=&loc=&luc=&outputFormat=&rel=&si=&st=arctic%20alaskan%20shrubs&te=&ts="
214
214
  stub_request(:get, query_url)
@@ -274,4 +274,46 @@ describe GiCatDriver do
274
274
  end
275
275
  end
276
276
 
277
+ describe "accessor (xml feed resource) configurations" do
278
+ it "creates a new feed resource for a profile" do
279
+ profile_name = 'some_profile'
280
+ accessor_configuration = {:nameComponent => 'fixture-nsidc-oai', :endPoint => 'http://scm.nsidc.org:3000/nsidc/oai.htm', :type => 'OAI-PMH/DIF', :versions => '2.0', :comment => '', :bindingAccessor => 'HTTP_GET', :nameContactPoint => '', :organizationContact => '', :mailContactPoint => '', :telephoneContactPoint => '', :startDate => '', :interval => 'P0Y0M0DT0H0M0S', :typeComponent => 'harvester', :stop => ''}
281
+
282
+ stub_request(:get, "http://admin:pass@www.somecompany.com/services/conf/brokerConfigurations").
283
+ with(:headers => {'Accept'=>'application/xml', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Type'=>'*/*'}, :query => {:nameRepository => 'gicat'}).
284
+ to_return(:status => 200, :body => File.new("spec/fixtures/brokerConfigurations.xml"), :headers => {})
285
+
286
+ enable_conf_url = "http://admin:pass@www.somecompany.com/services/conf/brokerConfigurations/1"
287
+ stub_request(:get,enable_conf_url)
288
+ .with(:headers => {
289
+ 'Accept'=>'application/xml',
290
+ 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
291
+ 'User-Agent'=>'Ruby',
292
+ 'Content-Type'=>'*/*'
293
+ })
294
+ .to_return(:status => 200, :body => File.new("spec/fixtures/brokerConfigurations.xml"), :headers => {})
295
+
296
+ get_resources_url = "http://admin:pass@www.somecompany.com/services/conf/brokerConfigurations/1/distributors/UUID-6c89ab7d-82aa-446c-902e-0b1f6e412a45"
297
+ stub_request(:post, get_resources_url)
298
+ .with(:headers => {
299
+ 'Accept'=>'application/xml',
300
+ 'User-Agent'=>'Ruby',
301
+ 'Content-Type'=>'application/x-www-form-urlencoded'
302
+ }, :body => accessor_configuration)
303
+ .to_return(:status => 200, :body => "UUID-dfe61211-56f4-4fb9-9f99-a7f4d95916c,UUID-0cd0c6a9-498c-400a-9bdd-20778ec62beb", :headers => {})
304
+
305
+ update_resource_url = "http://admin:pass@www.somecompany.com/services/conf/brokerConfigurations/1/accessors/UUID-dfe61211-56f4-4fb9-9f99-a7f4d95916c/update"
306
+ stub_request(:post, update_resource_url)
307
+ .with(:headers => {
308
+ 'Accept'=>'application/xml',
309
+ 'User-Agent'=>'Ruby',
310
+ 'Enctype'=>'multipart/form-data',
311
+ 'Content-Type'=>'application/x-www-form-urlencoded'
312
+ }, :body => accessor_configuration)
313
+ .to_return(:status => 200, :body => "Salvato", :headers => {})
314
+
315
+ @gi_cat.create_accessor(profile_name, accessor_configuration)
316
+ end
317
+ end
318
+
277
319
  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.2.3
4
+ version: 0.2.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-04-19 00:00:00.000000000 Z
13
+ date: 2013-04-20 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: faraday
17
- requirement: &70132345151200 !ruby/object:Gem::Requirement
17
+ requirement: !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ~>
@@ -22,10 +22,15 @@ dependencies:
22
22
  version: 0.8.7
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *70132345151200
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ~>
29
+ - !ruby/object:Gem::Version
30
+ version: 0.8.7
26
31
  - !ruby/object:Gem::Dependency
27
32
  name: nokogiri
28
- requirement: &70132345149560 !ruby/object:Gem::Requirement
33
+ requirement: !ruby/object:Gem::Requirement
29
34
  none: false
30
35
  requirements:
31
36
  - - ~>
@@ -33,10 +38,15 @@ dependencies:
33
38
  version: 1.5.6
34
39
  type: :runtime
35
40
  prerelease: false
36
- version_requirements: *70132345149560
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ~>
45
+ - !ruby/object:Gem::Version
46
+ version: 1.5.6
37
47
  - !ruby/object:Gem::Dependency
38
48
  name: bundler
39
- requirement: &70132345148160 !ruby/object:Gem::Requirement
49
+ requirement: !ruby/object:Gem::Requirement
40
50
  none: false
41
51
  requirements:
42
52
  - - ~>
@@ -44,10 +54,15 @@ dependencies:
44
54
  version: '1.3'
45
55
  type: :development
46
56
  prerelease: false
47
- version_requirements: *70132345148160
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ~>
61
+ - !ruby/object:Gem::Version
62
+ version: '1.3'
48
63
  - !ruby/object:Gem::Dependency
49
64
  name: rake
50
- requirement: &70132345147140 !ruby/object:Gem::Requirement
65
+ requirement: !ruby/object:Gem::Requirement
51
66
  none: false
52
67
  requirements:
53
68
  - - ~>
@@ -55,10 +70,15 @@ dependencies:
55
70
  version: 10.0.3
56
71
  type: :development
57
72
  prerelease: false
58
- version_requirements: *70132345147140
73
+ version_requirements: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ~>
77
+ - !ruby/object:Gem::Version
78
+ version: 10.0.3
59
79
  - !ruby/object:Gem::Dependency
60
80
  name: rspec
61
- requirement: &70132345146380 !ruby/object:Gem::Requirement
81
+ requirement: !ruby/object:Gem::Requirement
62
82
  none: false
63
83
  requirements:
64
84
  - - ~>
@@ -66,10 +86,15 @@ dependencies:
66
86
  version: 2.13.0
67
87
  type: :development
68
88
  prerelease: false
69
- version_requirements: *70132345146380
89
+ version_requirements: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ~>
93
+ - !ruby/object:Gem::Version
94
+ version: 2.13.0
70
95
  - !ruby/object:Gem::Dependency
71
96
  name: pygments.rb
72
- requirement: &70132345145620 !ruby/object:Gem::Requirement
97
+ requirement: !ruby/object:Gem::Requirement
73
98
  none: false
74
99
  requirements:
75
100
  - - ~>
@@ -77,10 +102,15 @@ dependencies:
77
102
  version: 0.4.2
78
103
  type: :development
79
104
  prerelease: false
80
- version_requirements: *70132345145620
105
+ version_requirements: !ruby/object:Gem::Requirement
106
+ none: false
107
+ requirements:
108
+ - - ~>
109
+ - !ruby/object:Gem::Version
110
+ version: 0.4.2
81
111
  - !ruby/object:Gem::Dependency
82
112
  name: mustache
83
- requirement: &70132345144960 !ruby/object:Gem::Requirement
113
+ requirement: !ruby/object:Gem::Requirement
84
114
  none: false
85
115
  requirements:
86
116
  - - ~>
@@ -88,10 +118,15 @@ dependencies:
88
118
  version: 0.99.4
89
119
  type: :development
90
120
  prerelease: false
91
- version_requirements: *70132345144960
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ none: false
123
+ requirements:
124
+ - - ~>
125
+ - !ruby/object:Gem::Version
126
+ version: 0.99.4
92
127
  - !ruby/object:Gem::Dependency
93
128
  name: redcarpet
94
- requirement: &70132345144500 !ruby/object:Gem::Requirement
129
+ requirement: !ruby/object:Gem::Requirement
95
130
  none: false
96
131
  requirements:
97
132
  - - ~>
@@ -99,10 +134,15 @@ dependencies:
99
134
  version: 2.2.2
100
135
  type: :development
101
136
  prerelease: false
102
- version_requirements: *70132345144500
137
+ version_requirements: !ruby/object:Gem::Requirement
138
+ none: false
139
+ requirements:
140
+ - - ~>
141
+ - !ruby/object:Gem::Version
142
+ version: 2.2.2
103
143
  - !ruby/object:Gem::Dependency
104
144
  name: rocco
105
- requirement: &70132345144040 !ruby/object:Gem::Requirement
145
+ requirement: !ruby/object:Gem::Requirement
106
146
  none: false
107
147
  requirements:
108
148
  - - ~>
@@ -110,10 +150,15 @@ dependencies:
110
150
  version: 0.8.2
111
151
  type: :development
112
152
  prerelease: false
113
- version_requirements: *70132345144040
153
+ version_requirements: !ruby/object:Gem::Requirement
154
+ none: false
155
+ requirements:
156
+ - - ~>
157
+ - !ruby/object:Gem::Version
158
+ version: 0.8.2
114
159
  - !ruby/object:Gem::Dependency
115
160
  name: webmock
116
- requirement: &70132345143500 !ruby/object:Gem::Requirement
161
+ requirement: !ruby/object:Gem::Requirement
117
162
  none: false
118
163
  requirements:
119
164
  - - ~>
@@ -121,7 +166,12 @@ dependencies:
121
166
  version: 1.11.0
122
167
  type: :development
123
168
  prerelease: false
124
- version_requirements: *70132345143500
169
+ version_requirements: !ruby/object:Gem::Requirement
170
+ none: false
171
+ requirements:
172
+ - - ~>
173
+ - !ruby/object:Gem::Version
174
+ version: 1.11.0
125
175
  description: Configure and control deployed instances of GI-Cat.
126
176
  email:
127
177
  - stuart.reed@nsidc.org
@@ -145,6 +195,7 @@ files:
145
195
  - spec/esip_opensearch_query_builder_spec.rb
146
196
  - spec/fixtures/brokerConfigurations.xml
147
197
  - spec/fixtures/distributors.xml
198
+ - spec/fixtures/harvesters.xml
148
199
  - spec/fixtures/opensearchesip_lucene_disabled.xml
149
200
  - spec/fixtures/opensearchesip_lucene_enabled.xml
150
201
  - spec/fixtures/status.xml
@@ -171,7 +222,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
171
222
  version: '0'
172
223
  requirements: []
173
224
  rubyforge_project:
174
- rubygems_version: 1.8.15
225
+ rubygems_version: 1.8.23
175
226
  signing_key:
176
227
  specification_version: 3
177
228
  summary: Configure and control deployed instances of GI-Cat.
@@ -179,6 +230,7 @@ test_files:
179
230
  - spec/esip_opensearch_query_builder_spec.rb
180
231
  - spec/fixtures/brokerConfigurations.xml
181
232
  - spec/fixtures/distributors.xml
233
+ - spec/fixtures/harvesters.xml
182
234
  - spec/fixtures/opensearchesip_lucene_disabled.xml
183
235
  - spec/fixtures/opensearchesip_lucene_enabled.xml
184
236
  - spec/fixtures/status.xml