zerofetcher 0.0.6 → 0.0.7

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/zerofetcher.rb +67 -27
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 07f69907316db9502c48570a9af8709c04bc8cbf
4
- data.tar.gz: d11a4225908538c7c4d1fe04ef2a7b9debdcde21
3
+ metadata.gz: ea6e02068bab92b4f4fc2763436be55a5b420a4b
4
+ data.tar.gz: 3db0a481047c4b6e6e3897e44c27c45995648912
5
5
  SHA512:
6
- metadata.gz: e07822f820e27c378574936981c630539a718aea5b4f137f2acfe226003ea8513344aeeba115f6a41c906bf7c6b4f1c00ce8cba9efbb6d224637d343e94bc848
7
- data.tar.gz: 6cbc24f801d986b209f5d59000d8598196965bc28ddfafe26cc240adc5a640dc4ffecfc0ef32a0c51a09b93541dbbacf0734ac4003f12a4f1c738fa118e6afb1
6
+ metadata.gz: 45db955853b9b213e6d828b977d93ff26d96769d3b85f47071e94fbe27be990fcaf5a68e47b40f46a43a356855af3a7da43627395c4ee485d8cb3bbdcf6ef99c
7
+ data.tar.gz: db5106b61400829c639ac69cd77578834d6d490bc52fc5fa1f368024d42ccdac0a54ee5e36d8e5b83df9fbf18eeaa45f77bff5820ac90a32e805f1fca843f46c
data/lib/zerofetcher.rb CHANGED
@@ -47,8 +47,9 @@ class ZeroFetcher
47
47
  end
48
48
 
49
49
  end_point = config['fetcher']['end_point']
50
+ site_id = config['fetcher']['site_id'].to_s
50
51
 
51
- data = self.loadDataFromApi(end_point, config['fetcher']['api_key'], config['fetcher']['site_id'])
52
+ data = self.loadDataFromApi(end_point, config['fetcher']['api_key'], site_id)
52
53
 
53
54
  # Site Info
54
55
  if data.key?("site")
@@ -102,7 +103,7 @@ class ZeroFetcher
102
103
  file_basename = Pathname.new(file).basename.to_s
103
104
  if 'README.md' != file_basename
104
105
  if !pages_files_saved.include?( file_basename )
105
- self.log(" - Deleting:"+jfile)
106
+ self.log(" - Deleting:"+file)
106
107
  FileUtils.rm(file)
107
108
  end
108
109
  end
@@ -188,11 +189,11 @@ class ZeroFetcher
188
189
  if data['calendar'].key?("events")
189
190
  data['calendar']['events'].each do |event|
190
191
  if event['image']
191
- self.getAndSaveFile(end_point + '/media/images/calendar/' + event['image'], jekyll_path+'/assets/images/calendar/' + event['image'])
192
+ self.getAndSaveFile(end_point + '/media/images/calendar/'+site_id+'/' + event['image'], jekyll_path+'/assets/images/calendar/' + event['image'])
192
193
  end
193
194
 
194
195
  if event['file']
195
- self.getAndSaveFile(end_point + '/media/files/calendar/' + event['file'], jekyll_path+'/assets/files/calendar/' + event['file'])
196
+ self.getAndSaveFile(end_point + '/media/files/calendar/'+site_id+'/' + event['file'], jekyll_path+'/assets/files/calendar/' + event['file'])
196
197
  end
197
198
  end
198
199
  end
@@ -208,32 +209,67 @@ class ZeroFetcher
208
209
  puts "Collection - " + collection_type + ' - ' + collection_data.length.to_s
209
210
  self.log("Collection - " + collection_type + ' - ' + collection_data.length.to_s)
210
211
 
211
- # Add to collection hash
212
- collection_config[ collection_type ] = ['output' => true];
213
-
214
212
  # Save Json Data
215
- File.write(jekyll_path+'/_data/'+collection_type+'.json', collection_data.to_json)
213
+ File.write(jekyll_path+'/_data/'+collection_type+'.json', collection_data['data'].to_json)
216
214
  self.log('Writing File /_data/'+collection_type+'.json')
217
215
 
218
- # Directory Check
219
- collection_path = jekyll_path+'/_' + collection_type
220
- FileUtils::mkdir_p collection_path
221
-
222
- # Create files saved array
223
- files_saved = Array.new
224
-
225
216
  # Loop through the collection data
226
- collection_data.each do |row|
227
- jfile = JekyllFile.new(collection_path, row, 'collection')
228
- jfile.savePageFile
229
-
230
- files_saved.push( Pathname.new( jfile.getFileName ).basename.to_s )
231
-
232
- self.log('Saving Collection File ' + file.getFileName)
217
+ case collection_data['settings']['type']
218
+ when 'collection'
219
+ # Add to collection hash
220
+ collection_config[ collection_type ] = ['output' => true];
221
+
222
+ # Directory Check
223
+ collection_path = jekyll_path+'/_' + collection_type
224
+ FileUtils::mkdir_p collection_path
225
+
226
+ # Create files saved array
227
+ files_saved = Array.new
228
+
229
+ # Save Individual Collection Files
230
+ collection_data['data'].each do |row|
231
+ jfile = JekyllFile.new(collection_path, row, 'collection')
232
+ jfile.savePageFile
233
+
234
+ files_saved.push( Pathname.new( jfile.getFileName ).basename.to_s )
235
+
236
+ self.log('Saving Collection File ' + jfile.getFileName)
237
+ end
238
+
239
+ # Clean up unused collection files
240
+ self.cleanUpFolder(collection_path, files_saved)
241
+ end
242
+
243
+ # Save Images / Files
244
+ collection_data['data'].each do |row|
245
+ collection_data['fields'].each do |fld_key,fld_info|
246
+ row.each do |key,val|
247
+ #puts 'Row ['+key+']:['+val.to_s+']'
248
+ if fld_key == key
249
+ puts 'Row ['+key+']:['+val.to_s+'] type['+fld_info['type']+']'
250
+ case fld_info['type']
251
+ when 'image'
252
+ # Directory Check
253
+ image_path = jekyll_path+'/assets/images/'+collection_type
254
+ FileUtils::mkdir_p image_path
255
+ src_image = end_point + '/media/images/'+collection_type+'/'+site_id+'/' + val
256
+
257
+ #puts 'Found Image ['+src_image+'] for collection ['+collection_type+']'
258
+
259
+ self.getAndSaveFile(src_image, image_path+'/' + val)
260
+ when 'file'
261
+ # Directory Check
262
+ file_path = jekyll_path+'/assets/files/'+collection_type
263
+ FileUtils::mkdir_p file_path
264
+
265
+ src_file = end_point + '/media/files/'+collection_type+'/'+site_id+'/' + val
266
+
267
+ self.getAndSaveFile(src_file, file_path+'/' + val)
268
+ end
269
+ end
270
+ end
271
+ end
233
272
  end
234
-
235
- # Clean up unused collection files
236
- self.cleanUpFolder(collection_path, files_saved)
237
273
  end
238
274
 
239
275
  # Add Collections to _config.tml
@@ -271,8 +307,12 @@ class ZeroFetcher
271
307
  self.log('Get/Save ' + dest)
272
308
  uri = URI.encode(source)
273
309
 
274
- open(dest, 'wb') do |file|
275
- file << open(uri).read
310
+ begin
311
+ open(dest, 'wb') do |file|
312
+ file << open(uri).read
313
+ end
314
+ rescue OpenURI::HTTPError => ex
315
+ self.log('source ['+source+'] Could not be opened to save')
276
316
  end
277
317
  end
278
318
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zerofetcher
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Liccardo