vortex_client 0.3.1 → 0.4.0
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/VERSION +1 -1
- data/bin/vrtx-sync +2 -37
- data/lib/vortex_client.rb +80 -22
- data/test/test_date_conversion.rb +15 -0
- data/test/test_vortex_event.rb +36 -0
- metadata +5 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.4.0
|
data/bin/vrtx-sync
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
require 'rubygems'
|
3
3
|
require 'uri'
|
4
4
|
require 'vortex_client'
|
5
|
+
require 'filewatcher'
|
5
6
|
|
6
7
|
# vrtx-sync: keep local files synced with webdav content
|
7
8
|
#
|
@@ -31,42 +32,6 @@ def download(url, vortex)
|
|
31
32
|
return path
|
32
33
|
end
|
33
34
|
|
34
|
-
|
35
|
-
# Monitor files
|
36
|
-
class FileMon
|
37
|
-
|
38
|
-
def initialize(filenames)
|
39
|
-
@last_mtimes = { }
|
40
|
-
filenames.each do |filename|
|
41
|
-
raise "File does not exist: " + filename unless File.exist?(filename)
|
42
|
-
@last_mtimes[filename] = File.stat(filename).mtime
|
43
|
-
end
|
44
|
-
@filenames = filenames
|
45
|
-
end
|
46
|
-
|
47
|
-
def run(sleep=1, &on_update)
|
48
|
-
loop do
|
49
|
-
Kernel.sleep sleep until file_updated?
|
50
|
-
yield @updated_file
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
def file_updated?
|
55
|
-
@filenames.each do |filename|
|
56
|
-
mtime = File.stat(filename).mtime
|
57
|
-
updated = @last_mtimes[filename] < mtime
|
58
|
-
@last_mtimes[filename] = mtime
|
59
|
-
if(updated)
|
60
|
-
@updated_file = filename
|
61
|
-
return true
|
62
|
-
end
|
63
|
-
end
|
64
|
-
return false
|
65
|
-
end
|
66
|
-
|
67
|
-
end
|
68
|
-
|
69
|
-
|
70
35
|
if $*.size < 1
|
71
36
|
print_usage
|
72
37
|
end
|
@@ -85,7 +50,7 @@ $*.each do |url|
|
|
85
50
|
downloaded_files[filename] = url
|
86
51
|
end
|
87
52
|
|
88
|
-
|
53
|
+
FileWatcher.new(downloaded_files.keys).watch do |filename|
|
89
54
|
url = downloaded_files[filename]
|
90
55
|
file = File.open(filename, "rb")
|
91
56
|
contents = file.read
|
data/lib/vortex_client.rb
CHANGED
@@ -7,6 +7,44 @@ require 'time'
|
|
7
7
|
# All calls are done with the webdav protocol.
|
8
8
|
module Vortex
|
9
9
|
|
10
|
+
# Convert norwegian date to Time object with a forgiven regexp
|
11
|
+
#
|
12
|
+
# Examples:
|
13
|
+
#
|
14
|
+
# t = norwegian_date('1.1.2010')
|
15
|
+
# t = norwegian_date('22.01.2010')
|
16
|
+
# t = norwegian_date('22.01.2010 12:15')
|
17
|
+
# t = norwegian_date('22.01.2010 12:15:20')
|
18
|
+
def norwegian_date(date)
|
19
|
+
if /\A\s*
|
20
|
+
(\d\d?).(\d\d?).(-?\d+)
|
21
|
+
\s?
|
22
|
+
(\d\d?)?:?(\d\d?)?:?(\d\d?)?
|
23
|
+
\s*\z/ix =~ date
|
24
|
+
year = $3.to_i
|
25
|
+
mon = $2.to_i
|
26
|
+
day = $1.to_i
|
27
|
+
hour = $4.to_i
|
28
|
+
min = $5.to_i
|
29
|
+
sec = $6.to_i
|
30
|
+
|
31
|
+
# puts "Debug: #{year} #{mon} #{day} #{hour}:#{min}:#{sec}"
|
32
|
+
|
33
|
+
usec = 0
|
34
|
+
usec = $7.to_f * 1000000 if $7
|
35
|
+
if $8
|
36
|
+
zone = $8
|
37
|
+
year, mon, day, hour, min, sec =
|
38
|
+
apply_offset(year, mon, day, hour, min, sec, zone_offset(zone))
|
39
|
+
Time.utc(year, mon, day, hour, min, sec, usec)
|
40
|
+
else
|
41
|
+
Time.local(year, mon, day, hour, min, sec, usec)
|
42
|
+
end
|
43
|
+
else
|
44
|
+
raise ArgumentError.new("invalid date: #{date.inspect}")
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
10
48
|
class Connection < Net::DAV
|
11
49
|
|
12
50
|
# Create a new connection to Vortex. Prompts for username and password if not
|
@@ -61,7 +99,7 @@ module Vortex
|
|
61
99
|
# article = Vortex::StructuredArticle(:title=>"My title")
|
62
100
|
# vortex.publish(article)
|
63
101
|
def publish(object)
|
64
|
-
if(object.is_a? HtmlArticle)
|
102
|
+
if(object.is_a? HtmlArticle or object.is_a? HtmlEvent)
|
65
103
|
uri = @uri.merge(object.url)
|
66
104
|
# puts "DEBUG: '" + object.properties
|
67
105
|
self.put_string(uri, object.content)
|
@@ -312,18 +350,23 @@ module Vortex
|
|
312
350
|
#
|
313
351
|
# Examples:
|
314
352
|
#
|
315
|
-
#
|
316
|
-
#
|
317
|
-
#
|
318
|
-
#
|
319
|
-
#
|
320
|
-
#
|
321
|
-
#
|
353
|
+
# event = Vortex::HtmlEvent.new(:title => "Sample Event 1",
|
354
|
+
# :introduction => "Sample event introduction",
|
355
|
+
# :body => "<p>Hello world</p>",
|
356
|
+
# :startDate => Time.now, ## "22.01.2010 12:15",
|
357
|
+
# :endDate => Time.now + 60*60, ## "22.01.2010 13:00",
|
358
|
+
# :location => "Forskningsveien 3B",
|
359
|
+
# :mapUrl => "http://maps.google.com/123",
|
360
|
+
# :tags => ["vortex","testing"],
|
361
|
+
# :publishedDate => "05.01.2010 12:00")
|
362
|
+
# vortex.publish(event)
|
322
363
|
class HtmlEvent < PlainFile
|
323
364
|
|
324
|
-
attr_accessor :title, :introduction, :body, :filename, :modifiedDate, :publishedDate, :
|
365
|
+
attr_accessor :title, :introduction, :body, :filename, :modifiedDate, :publishedDate, :date,
|
366
|
+
:owner, :url, :tags, :startDate, :endDate, :location, :mapUrl
|
325
367
|
|
326
|
-
# Create a new article of type html-article: plain html file with
|
368
|
+
# Create a new article of type html-article: plain html file with
|
369
|
+
# introduction stored as a webdav property.
|
327
370
|
def initialize(options={})
|
328
371
|
options.each{|k,v|send("#{k}=",v)}
|
329
372
|
end
|
@@ -344,8 +387,8 @@ module Vortex
|
|
344
387
|
end
|
345
388
|
|
346
389
|
def properties
|
347
|
-
props = '<v:resourceType xmlns:v="vrtx">
|
348
|
-
'<v:xhtml10-type xmlns:v="vrtx">
|
390
|
+
props = '<v:resourceType xmlns:v="vrtx">event</v:resourceType>' +
|
391
|
+
'<v:xhtml10-type xmlns:v="vrtx">event</v:xhtml10-type>' +
|
349
392
|
'<v:userSpecifiedCharacterEncoding xmlns:v="vrtx">utf-8</v:userSpecifiedCharacterEncoding>'
|
350
393
|
|
351
394
|
if(@publishedDate and @publishedDate != "")
|
@@ -355,9 +398,9 @@ module Vortex
|
|
355
398
|
props += '<v:published-date xmlns:v="vrtx">' + @publishedDate + '</v:published-date>'
|
356
399
|
end
|
357
400
|
|
358
|
-
if(date and date != "")
|
359
|
-
if(date.kind_of? Time)
|
360
|
-
date = @date.httpdate.to_s
|
401
|
+
if(@date and @date != "")
|
402
|
+
if(@date.kind_of? Time)
|
403
|
+
@date = @date.httpdate.to_s
|
361
404
|
end
|
362
405
|
if(@publishedDate == nil or @publishedDate != "")
|
363
406
|
props += '<v:published-date xmlns:v="vrtx">' + date + '</v:published-date>'
|
@@ -376,13 +419,6 @@ module Vortex
|
|
376
419
|
if(introduction and introduction != "")
|
377
420
|
props += '<introduction xmlns="vrtx">' + introduction + '</introduction>'
|
378
421
|
end
|
379
|
-
if(author and author != "")
|
380
|
-
props += '<v:authors xmlns:v="vrtx">' +
|
381
|
-
'<vrtx:values xmlns:vrtx="http://vortikal.org/xml-value-list">' +
|
382
|
-
'<vrtx:value>' + author + '</vrtx:value>' +
|
383
|
-
'</vrtx:values>' +
|
384
|
-
'</v:authors>'
|
385
|
-
end
|
386
422
|
|
387
423
|
if(tags and tags.kind_of?(Array) and tags.size > 0)
|
388
424
|
props += '<v:tags xmlns:v="vrtx">' +
|
@@ -393,9 +429,31 @@ module Vortex
|
|
393
429
|
props += '</vrtx:values></v:tags>'
|
394
430
|
end
|
395
431
|
|
432
|
+
|
433
|
+
if(@startDate and @startDate != "")
|
434
|
+
if(@startDate.kind_of? Time)
|
435
|
+
@startDate = @startDate.httpdate.to_s
|
436
|
+
end
|
437
|
+
props += '<v:start-date xmlns:v="vrtx">' + @startDate + '</v:start-date>'
|
438
|
+
end
|
439
|
+
|
440
|
+
if(@endDate and @endDate != "")
|
441
|
+
if(@endDate.kind_of? Time)
|
442
|
+
@endDate = @endDate.httpdate.to_s
|
443
|
+
end
|
444
|
+
props += '<v:end-date xmlns:v="vrtx">' + @endDate + '</v:end-date>'
|
445
|
+
end
|
446
|
+
|
447
|
+
if(@location and @location != "")
|
448
|
+
props += '<v:location xmlns:v="vrtx">' + @location + '</v:location>'
|
449
|
+
end
|
450
|
+
if(@mapUrl and @mapUrl != "")
|
451
|
+
props += '<v:mapurl xmlns:v="vrtx">' + @mapUrl + '</v:mapurl>'
|
452
|
+
end
|
396
453
|
return props
|
397
454
|
end
|
398
455
|
|
456
|
+
# TODO: Samme kode som i article... Bruk arv!
|
399
457
|
def content
|
400
458
|
content = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ' +
|
401
459
|
'"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">' +
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'helper'
|
3
|
+
|
4
|
+
class TestVortexDateConversion < Test::Unit::TestCase
|
5
|
+
include Vortex
|
6
|
+
|
7
|
+
should "parse norwegian date and time formats" do
|
8
|
+
assert norwegian_date('1.1.2010')
|
9
|
+
assert norwegian_date('1.1.2010')
|
10
|
+
assert norwegian_date('22.01.2010')
|
11
|
+
assert norwegian_date('22.01.2010 12:15')
|
12
|
+
assert norwegian_date('22.01.2010 12:15:20')
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'helper'
|
3
|
+
|
4
|
+
class TestVortexClientUtils < Test::Unit::TestCase
|
5
|
+
include Vortex
|
6
|
+
|
7
|
+
def setup
|
8
|
+
if(not(@vortex))
|
9
|
+
user = ENV['DAVUSER']
|
10
|
+
pass = ENV['DAVPASS']
|
11
|
+
@vortex = Connection.new("https://vortex-dav.uio.no/",user, pass)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
should "publish events" do
|
16
|
+
url = 'https://vortex-dav.uio.no/brukere/thomasfl/nyheter/sample-event-1.html'
|
17
|
+
if(@vortex.exists?(url))
|
18
|
+
@vortex.delete(url)
|
19
|
+
end
|
20
|
+
|
21
|
+
@vortex.cd('/brukere/thomasfl/nyheter/')
|
22
|
+
event = HtmlEvent.new(:title => "Sample Event 1",
|
23
|
+
:introduction => "Sample event introduction",
|
24
|
+
:body => "<p>Hello world</p>",
|
25
|
+
:startDate => "19.06.2010 17:56",
|
26
|
+
:endDate => "19.06.2010 19:00",
|
27
|
+
:location => "Forskningsveien 3B",
|
28
|
+
:mapUrl => "http://maps.google.com/123",
|
29
|
+
:tags => ["vortex","testing","ruby"],
|
30
|
+
:publishedDate => "05.01.2010 12:00")
|
31
|
+
@vortex.publish(event)
|
32
|
+
assert @vortex.exists?(url)
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vortex_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thomas Flemming
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-01-
|
12
|
+
date: 2010-01-26 00:00:00 +01:00
|
13
13
|
default_executable: vrtx-sync
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -58,6 +58,7 @@ files:
|
|
58
58
|
- README.rdoc
|
59
59
|
- Rakefile
|
60
60
|
- VERSION
|
61
|
+
- bin/vrtx-sync
|
61
62
|
- lib/vortex_client.rb
|
62
63
|
- lib/vortex_client/string_utils.rb
|
63
64
|
- test/helper.rb
|
@@ -96,8 +97,10 @@ specification_version: 3
|
|
96
97
|
summary: Vortex CMS client
|
97
98
|
test_files:
|
98
99
|
- test/helper.rb
|
100
|
+
- test/test_date_conversion.rb
|
99
101
|
- test/test_vortex_article_publish.rb
|
100
102
|
- test/test_vortex_client.rb
|
101
103
|
- test/test_vortex_collection.rb
|
104
|
+
- test/test_vortex_event.rb
|
102
105
|
- test/test_vortex_tags.rb
|
103
106
|
- test/test_vortex_utils.rb
|