bcl 0.3.5 → 0.3.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 310fa6cd807919ce71dd05ca1a6d94f9d0b5a745
4
+ data.tar.gz: 14ddfb96035844f235e012657bcf48c7d809f458
5
+ SHA512:
6
+ metadata.gz: 58e402c26df46cd04242857ed248138d15b8e4f39f5b7806c7cd8ffadf9eda2036b87d5fdc81d74aa350a08f972796aeadec7dfe8863e9e6aab404539f495cb4
7
+ data.tar.gz: 2b6ce437ca4614ae28ad53655162aa243618967e5c5a6146fefca1e1914e7c35c7ccb81cc7129f6dae656fda18ba0877a725927e8b4f2fef5c8f3142d1a643f5
@@ -39,12 +39,14 @@ module BCL
39
39
  attr_accessor :session
40
40
  attr_accessor :http
41
41
 
42
- def initialize()
42
+ def initialize(group_id = nil)
43
43
  @config = nil
44
44
  @session = nil
45
45
  @access_token = nil
46
46
  @http = nil
47
47
  @api_version = 2.0
48
+ #set group to NREL (32) if nil
49
+ @group_id = group_id.nil? ? 32 : group_id
48
50
  config_path = File.expand_path('~') + '/.bcl'
49
51
  config_name = 'config.yml'
50
52
  if File.exists?(config_path + "/" + config_name)
@@ -56,7 +58,7 @@ module BCL
56
58
  File.open(config_path + "/" + config_name, 'w') do |file|
57
59
  file << default_yaml.to_yaml
58
60
  end
59
- raise "******** Please fill in user credentials in #{config_path}/#{config_name} file. DO NOT COMMIT THIS FILE. **********"
61
+ puts "******** Please fill in user credentials in #{config_path}/#{config_name} file. DO NOT COMMIT THIS FILE. **********"
60
62
  end
61
63
 
62
64
  end
@@ -68,15 +70,13 @@ module BCL
68
70
  end
69
71
 
70
72
 
71
- def login(username=nil, password=nil)
72
- if username.nil? || password.nil?
73
- # log in via cached creditials
74
- username = @config[:server][:user][:username]
75
- password = @config[:server][:user][:password]
76
- end
73
+ def login(username=nil, password=nil, url=nil)
74
+
77
75
 
78
- #figure out what time to use
79
- url = @config[:server][:url]
76
+ #figure out what url to use
77
+ if url.nil?
78
+ url = @config[:server][:url]
79
+ end
80
80
  #look for http vs. https
81
81
  if url.include? "https"
82
82
  port = 443
@@ -86,20 +86,34 @@ module BCL
86
86
  #strip out http(s)
87
87
  url = url.gsub('http://', '')
88
88
  url = url.gsub('https://', '')
89
-
90
- puts "Connecting to #{url} on port #{port} as #{username}"
91
-
89
+
90
+ if username.nil? || password.nil?
91
+ # log in via cached creditials
92
+ puts "logging in using credentials in .bcl/config.yml: Connecting to #{url} on port #{port} as #{username}"
93
+ username = @config[:server][:user][:username]
94
+ password = @config[:server][:user][:password]
95
+ else
96
+ puts "logging in using credentials in function arguments: Connecting to #{url} on port #{port} as #{username}"
97
+ end
98
+
92
99
  @http = Net::HTTP.new(url, port)
93
- @http.use_ssl = true
94
-
100
+ if port == 443
101
+ @http.use_ssl = true
102
+ end
103
+
95
104
  data = %Q({"username":"#{username}","password":"#{password}"})
96
105
  #data = {"username" => username, "password" => password}
97
106
 
98
- login_path = "/api/user/login.json?"
107
+ login_path = "/api/user/login.json"
99
108
  headers = {'Content-Type' => 'application/json'}
100
109
 
101
- res, data = @http.post(login_path, data, headers)
102
-
110
+ res = @http.post(login_path, data, headers)
111
+
112
+ # for debugging:
113
+ #res.each do |key, value|
114
+ # puts "#{key}: #{value}"
115
+ #end
116
+
103
117
  #restClient wasn't working
104
118
  #res = RestClient.post "#{@config[:server][:url]}/api/user/login", data.to_json, :content_type => :json, :accept => :json
105
119
  if res.code == '200'
@@ -154,7 +168,7 @@ module BCL
154
168
  #puts "DATA: #{data}"
155
169
  session_name = ""
156
170
  sessid = ""
157
- json = JSON.parse(data)
171
+ json = JSON.parse(res.body)
158
172
  json.each do |key, val|
159
173
  if key == 'session_name'
160
174
  session_name = val
@@ -169,13 +183,13 @@ module BCL
169
183
  token_path = "/services/session/token"
170
184
  token_headers = {'Content-Type' => 'application/json', 'Cookie' => @session}
171
185
  #puts "token_headers = #{token_headers.inspect}"
172
- access_token_res, access_token = @http.post(token_path,"",token_headers)
173
- if access_token_res.code == '200'
174
- @access_token = access_token
186
+ access_token = @http.post(token_path,"",token_headers)
187
+ if access_token.code == '200'
188
+ @access_token = access_token.body
175
189
  else
176
190
  puts "Unable to get access token; uploads will not work"
177
- puts "error code: #{access_token_res.code}"
178
- puts "error info: #{access_token_res.body}"
191
+ puts "error code: #{access_token.code}"
192
+ puts "error info: #{access_token.body}"
179
193
  end
180
194
 
181
195
  #puts "access_token = *#{@access_token}*"
@@ -193,7 +207,7 @@ module BCL
193
207
 
194
208
  # pushes component to the bcl and publishes them (if logged-in as BCL Website Admin user).
195
209
  # username and password set in ~/.bcl/config.yml file
196
- def push_content(filename_and_path, write_receipt_file, content_type, bcl_group_id)
210
+ def push_content(filename_and_path, write_receipt_file, content_type)
197
211
  raise "Please login before pushing components" if @session.nil?
198
212
  raise "Do not have a valid access token; try again" if @access_token.nil?
199
213
  valid = false
@@ -214,17 +228,19 @@ module BCL
214
228
  "node" =>
215
229
  {
216
230
  "type" => "#{content_type}",
217
- "field_component_tags" => #TODO remove this field_component_tags once BCL is fixed
218
- {
219
- "und" => "1289"
220
- },
231
+ #"field_component_tags" => #TODO remove this field_component_tags once BCL is fixed
232
+ # {
233
+ # "und" => "1289"
234
+ # },
221
235
  "og_group_ref" =>
222
236
  {
223
237
  "und" =>
224
- ["target_id" => bcl_group_id],
225
- "publish" => 1 #NOTE THIS ONLY WORKS IF YOU ARE A BCL SITE ADMIN
226
- }
238
+ ["target_id" => @group_id],
239
+
240
+ },
241
+ "publish" => 1 #NOTE THIS ONLY WORKS IF YOU ARE A BCL SITE ADMIN
227
242
  }
243
+
228
244
  }
229
245
  #restclient not working
230
246
  #res = RestClient.post "#{@config[:server][:url]}/api/content.json", @data.to_json, :content_type => :json, :cookies => @session
@@ -232,7 +248,7 @@ module BCL
232
248
  path = "/api/content.json"
233
249
  headers = {'Content-Type' => 'application/json','X-CSRF-Token' => @access_token, 'Cookie' => @session}
234
250
  #puts headers.inspect
235
- res, data = @http.post(path, @data.to_json, headers)
251
+ res = @http.post(path, @data.to_json, headers)
236
252
 
237
253
  res_j = "could not get json from http post response"
238
254
  if res.code == '200'
@@ -267,7 +283,7 @@ module BCL
267
283
  [valid, res_j]
268
284
  end
269
285
 
270
- def push_contents(array_of_components, skip_files_with_receipts, content_type, bcl_group_id)
286
+ def push_contents(array_of_components, skip_files_with_receipts, content_type)
271
287
  logs = []
272
288
  array_of_components.each do |comp|
273
289
  receipt_file = File.dirname(comp) + "/" + File.basename(comp, '.tar.gz') + ".receipt"
@@ -278,7 +294,7 @@ module BCL
278
294
  else
279
295
  log_message = "pushing content #{File.basename(comp, '.tar.gz')}"
280
296
  puts log_message
281
- valid, res = push_content(comp, true, content_type, bcl_group_id)
297
+ valid, res = push_content(comp, true, content_type)
282
298
  log_message += " #{valid} #{res.inspect.chomp}"
283
299
  end
284
300
  logs << log_message
@@ -289,7 +305,7 @@ module BCL
289
305
 
290
306
  # pushes updated content to the bcl and publishes it (if logged-in as BCL Website Admin user).
291
307
  # username and password set in ~/.bcl/config.yml file
292
- def update_content(filename_and_path, write_receipt_file, uuid, bcl_group_id)
308
+ def update_content(filename_and_path, write_receipt_file, uuid)
293
309
  raise "Please login before pushing components" if @session.nil?
294
310
  valid = false
295
311
  res_j = nil
@@ -309,16 +325,16 @@ module BCL
309
325
  "node" =>
310
326
  {
311
327
  "uuid" => "#{uuid}",
312
- "field_component_tags" => #TODO remove this field_component_tags once BCL is fixed
313
- {
314
- "und" => "1289"
315
- },
328
+ #"field_component_tags" => #TODO remove this field_component_tags once BCL is fixed
329
+ # {
330
+ # "und" => "1289"
331
+ # },
316
332
  "og_group_ref" =>
317
333
  {
318
334
  "und" =>
319
- ["target_id" => bcl_group_id],
320
- "publish" => 1 #NOTE THIS ONLY WORKS IF YOU ARE A BCL SITE ADMIN
321
- }
335
+ ["target_id" => @group_id],
336
+ },
337
+ "publish" => 1 #NOTE THIS ONLY WORKS IF YOU ARE A BCL SITE ADMIN
322
338
  }
323
339
  }
324
340
 
@@ -328,7 +344,7 @@ module BCL
328
344
  path = "/api/content.json"
329
345
  headers = {'Content-Type' => 'application/json', 'Cookie' => @session, 'X-CSRF-Token' => @access_token}
330
346
 
331
- res, data = @http.post(path, @data.to_json, headers)
347
+ res = @http.post(path, @data.to_json, headers)
332
348
 
333
349
  res_j = "could not get json from http post response"
334
350
  if res.code == '200'
@@ -363,7 +379,7 @@ module BCL
363
379
  [valid, res_j]
364
380
  end
365
381
 
366
- def update_contents(array_of_components, skip_files_with_receipts, bcl_group_id)
382
+ def update_contents(array_of_components, skip_files_with_receipts)
367
383
  logs = []
368
384
  array_of_components.each do |comp|
369
385
  receipt_file = File.dirname(comp) + "/" + File.basename(comp, '.tar.gz') + ".receipt"
@@ -386,12 +402,12 @@ module BCL
386
402
  end
387
403
  end
388
404
  if uuid == nil
389
- log_message "ERROR: uuid not found for #{File.basename(comp)}"
405
+ log_message = "ERROR: uuid not found for #{File.basename(comp)}"
390
406
  puts log_message
391
407
  else
392
408
  log_message = "pushing updated content #{File.basename(comp)}"
393
409
  puts log_message
394
- valid, res = update_content(comp, true, uuid, bcl_group_id)
410
+ valid, res = update_content(comp, true, uuid, @group_id)
395
411
  log_message += " #{valid} #{res.inspect.chomp}"
396
412
  end
397
413
  end
@@ -401,12 +417,24 @@ module BCL
401
417
  end
402
418
 
403
419
  # Simple method to search bcl and return the result as an XML object
404
- def search(search_str)
405
- full_url = "#{@config[:server][:url]}/api/search/#{search_str}&api_version=#{@api_version}"
406
- res = RestClient.get "#{full_url}"
407
- xml = LibXML::XML::Document.string(res.body)
420
+ def search(search_str=nil, filter_str=nil)
421
+ full_url = "/api/search.json"
422
+
423
+ #add search term
424
+ if !search_str.nil?
425
+ full_url = full_url + "/" + search_str
426
+ end
427
+ #add api_version
428
+ full_url = full_url + "?api_version=#{@api_version}"
429
+ #add filters
430
+ if !filter_str.nil?
431
+ full_url = full_url + "&" + filter_str
432
+ end
408
433
 
409
- xml
434
+ res = @http.get(full_url)
435
+
436
+ #retrieve in json
437
+ res.body
410
438
  end
411
439
 
412
440
  # Delete receipt files
@@ -424,8 +452,12 @@ module BCL
424
452
 
425
453
  # TODO make this extend the component_xml class (or create a super class around components)
426
454
 
427
- def BCL.gather_components(component_dir, chunk_size = 0, delete_previousgather = false)
428
- @dest_filename = "components"
455
+ def BCL.gather_components(component_dir, chunk_size = 0, delete_previousgather = false, destination=nil)
456
+ if destination.nil?
457
+ @dest_filename = "components"
458
+ else
459
+ @dest_filename = destination
460
+ end
429
461
  @dest_file_ext = "tar.gz"
430
462
 
431
463
  #store the starting directory
data/lib/bcl/version.rb CHANGED
@@ -18,5 +18,5 @@
18
18
  ######################################################################
19
19
 
20
20
  module BCL
21
- VERSION = "0.3.5"
21
+ VERSION = "0.3.6"
22
22
  end
metadata CHANGED
@@ -1,15 +1,9 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: bcl
3
- version: !ruby/object:Gem::Version
4
- hash: 25
5
- prerelease:
6
- segments:
7
- - 0
8
- - 3
9
- - 5
10
- version: 0.3.5
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.6
11
5
  platform: ruby
12
- authors:
6
+ authors:
13
7
  - Daniel Macumber
14
8
  - Nicholas Long
15
9
  - Andrew Parker
@@ -17,116 +11,114 @@ authors:
17
11
  autorequire:
18
12
  bindir: bin
19
13
  cert_chain: []
20
-
21
- date: 2013-11-07 00:00:00 Z
22
- dependencies:
23
- - !ruby/object:Gem::Dependency
14
+ date: 2013-11-15 00:00:00.000000000 Z
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
24
17
  name: uuid
25
- prerelease: false
26
- requirement: &id001 !ruby/object:Gem::Requirement
27
- none: false
28
- requirements:
29
- - - ">="
30
- - !ruby/object:Gem::Version
31
- hash: 3
32
- segments:
33
- - 0
34
- version: "0"
18
+ requirement: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
35
23
  type: :runtime
36
- version_requirements: *id001
37
- - !ruby/object:Gem::Dependency
38
- name: builder
39
24
  prerelease: false
40
- requirement: &id002 !ruby/object:Gem::Requirement
41
- none: false
42
- requirements:
43
- - - ">="
44
- - !ruby/object:Gem::Version
45
- hash: 3
46
- segments:
47
- - 0
48
- version: "0"
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: builder
32
+ requirement: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - '>='
35
+ - !ruby/object:Gem::Version
36
+ version: '0'
49
37
  type: :runtime
50
- version_requirements: *id002
51
- - !ruby/object:Gem::Dependency
52
- name: zliby
53
38
  prerelease: false
54
- requirement: &id003 !ruby/object:Gem::Requirement
55
- none: false
56
- requirements:
57
- - - ">="
58
- - !ruby/object:Gem::Version
59
- hash: 3
60
- segments:
61
- - 0
62
- version: "0"
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ - !ruby/object:Gem::Dependency
45
+ name: zliby
46
+ requirement: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - '>='
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
63
51
  type: :runtime
64
- version_requirements: *id003
65
- - !ruby/object:Gem::Dependency
66
- name: archive-tar-minitar
67
52
  prerelease: false
68
- requirement: &id004 !ruby/object:Gem::Requirement
69
- none: false
70
- requirements:
71
- - - ">="
72
- - !ruby/object:Gem::Version
73
- hash: 3
74
- segments:
75
- - 0
76
- version: "0"
53
+ version_requirements: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - '>='
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ - !ruby/object:Gem::Dependency
59
+ name: archive-tar-minitar
60
+ requirement: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - '>='
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
77
65
  type: :runtime
78
- version_requirements: *id004
79
- - !ruby/object:Gem::Dependency
80
- name: mongo
81
66
  prerelease: false
82
- requirement: &id005 !ruby/object:Gem::Requirement
83
- none: false
84
- requirements:
85
- - - ">="
86
- - !ruby/object:Gem::Version
87
- hash: 3
88
- segments:
89
- - 0
90
- version: "0"
67
+ version_requirements: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - '>='
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ - !ruby/object:Gem::Dependency
73
+ name: mongo
74
+ requirement: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
91
79
  type: :runtime
92
- version_requirements: *id005
93
- - !ruby/object:Gem::Dependency
94
- name: json_pure
95
80
  prerelease: false
96
- requirement: &id006 !ruby/object:Gem::Requirement
97
- none: false
98
- requirements:
99
- - - ">="
100
- - !ruby/object:Gem::Version
101
- hash: 3
102
- segments:
103
- - 0
104
- version: "0"
81
+ version_requirements: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ - !ruby/object:Gem::Dependency
87
+ name: json_pure
88
+ requirement: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - '>='
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
105
93
  type: :runtime
106
- version_requirements: *id006
107
- - !ruby/object:Gem::Dependency
108
- name: rest-client
109
94
  prerelease: false
110
- requirement: &id007 !ruby/object:Gem::Requirement
111
- none: false
112
- requirements:
113
- - - ">="
114
- - !ruby/object:Gem::Version
115
- hash: 3
116
- segments:
117
- - 0
118
- version: "0"
95
+ version_requirements: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - '>='
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ - !ruby/object:Gem::Dependency
101
+ name: rest-client
102
+ requirement: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - '>='
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
119
107
  type: :runtime
120
- version_requirements: *id007
121
- description: This gem contains helper methods for generating the Component XML file needed to upload files to the Building Component Library. It also contains the classes needed for logging in via the api and uploading generating components
108
+ prerelease: false
109
+ version_requirements: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - '>='
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ description: This gem contains helper methods for generating the Component XML file
115
+ needed to upload files to the Building Component Library. It also contains the classes
116
+ needed for logging in via the api and uploading generating components
122
117
  email: Nicholas.Long@nrel.gov
123
118
  executables: []
124
-
125
119
  extensions: []
126
-
127
120
  extra_rdoc_files: []
128
-
129
- files:
121
+ files:
130
122
  - lib/bcl/bcl_xml.rb
131
123
  - lib/bcl/component_methods.rb
132
124
  - lib/bcl/component_spreadsheet.rb
@@ -140,37 +132,28 @@ files:
140
132
  - lib/bcl/version.rb
141
133
  - lib/bcl.rb
142
134
  homepage: http://bcl.nrel.gov
143
- licenses:
135
+ licenses:
144
136
  - LGPL
137
+ metadata: {}
145
138
  post_install_message:
146
139
  rdoc_options: []
147
-
148
- require_paths:
140
+ require_paths:
149
141
  - lib
150
- required_ruby_version: !ruby/object:Gem::Requirement
151
- none: false
152
- requirements:
153
- - - ">="
154
- - !ruby/object:Gem::Version
155
- hash: 3
156
- segments:
157
- - 0
158
- version: "0"
159
- required_rubygems_version: !ruby/object:Gem::Requirement
160
- none: false
161
- requirements:
162
- - - ">="
163
- - !ruby/object:Gem::Version
164
- hash: 3
165
- segments:
166
- - 0
167
- version: "0"
142
+ required_ruby_version: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - '>='
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ required_rubygems_version: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - '>='
150
+ - !ruby/object:Gem::Version
151
+ version: '0'
168
152
  requirements: []
169
-
170
153
  rubyforge_project:
171
- rubygems_version: 1.8.24
154
+ rubygems_version: 2.0.3
172
155
  signing_key:
173
- specification_version: 3
156
+ specification_version: 4
174
157
  summary: Classes for creating component XML files for the BCL
175
158
  test_files: []
176
-
159
+ has_rdoc: