vortex_client 0.4.0 → 0.5.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/examples/create_collection.rb +15 -0
- data/examples/publish_article.rb +16 -0
- data/examples/publish_event.rb +18 -0
- data/lib/vortex_client.rb +93 -48
- data/test/test_vortex_collection.rb +51 -1
- metadata +9 -1
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.5.0
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'vortex_client'
|
3
|
+
include Vortex
|
4
|
+
|
5
|
+
vortex = Vortex::Connection.new("https://vortex-dav.uio.no/", ENV['DAVUSER'], ENV['DAVPASS'])
|
6
|
+
vortex.cd('/brukere/thomasfl/events/')
|
7
|
+
|
8
|
+
collection = ArticleListingCollection.new(:url => 'my-collection', :title => 'My articles')
|
9
|
+
path = vortex.create(collection)
|
10
|
+
puts "Created folder: " + path
|
11
|
+
|
12
|
+
|
13
|
+
collection = EventListingCollection.new(:title => 'My events')
|
14
|
+
path = vortex.create(collection)
|
15
|
+
puts "Created folder: " + path
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'vortex_client'
|
3
|
+
include Vortex
|
4
|
+
|
5
|
+
vortex = Vortex::Connection.new("https://vortex-dav.uio.no/")
|
6
|
+
|
7
|
+
vortex.cd('/brukere/thomasfl/nyheter/')
|
8
|
+
article = HtmlArticle.new(:title => "My new title",
|
9
|
+
:introduction => "Short introduction",
|
10
|
+
:body => "<p>Longer body</p>",
|
11
|
+
:publishedDate => Time.now,
|
12
|
+
:author => "Thomas Flemming")
|
13
|
+
path = vortex.publish(article)
|
14
|
+
puts "published " + path
|
15
|
+
|
16
|
+
# => published https://vortex-dav.uio.no/brukere/thomasfl/nyheter/my-new-title.html
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'vortex_client'
|
3
|
+
include Vortex
|
4
|
+
|
5
|
+
vortex = Vortex::Connection.new("https://vortex-dav.uio.no/")
|
6
|
+
vortex.cd('/brukere/thomasfl/events/')
|
7
|
+
event = HtmlEvent.new(:title => "My Sample Event 1",
|
8
|
+
:introduction => "Sample event introduction",
|
9
|
+
:body => "<p>Hello world</p>",
|
10
|
+
:startDate => "19.06.2010 17:56",
|
11
|
+
:endDate => "19.06.2010 19:00",
|
12
|
+
:location => "Forskningsveien 3B",
|
13
|
+
:mapUrl => "http://maps.google.com/123",
|
14
|
+
:tags => ["vortex","testing","ruby"],
|
15
|
+
:publishedDate => "05.01.2010 12:00")
|
16
|
+
path = vortex.publish(event)
|
17
|
+
puts "published " + path
|
18
|
+
|
data/lib/vortex_client.rb
CHANGED
@@ -7,44 +7,6 @@ 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
|
-
|
48
10
|
class Connection < Net::DAV
|
49
11
|
|
50
12
|
# Create a new connection to Vortex. Prompts for username and password if not
|
@@ -118,7 +80,7 @@ module Vortex
|
|
118
80
|
# collecion = ArticleListingCollection.new(:url => '/url')
|
119
81
|
# connection.create(collection)
|
120
82
|
def create(object)
|
121
|
-
if(object.is_a?
|
83
|
+
if(object.is_a? Collection)
|
122
84
|
uri = @uri.merge(object.url)
|
123
85
|
# puts "DEBUG: uri: " + uri.to_s
|
124
86
|
self.mkdir(uri)
|
@@ -139,9 +101,9 @@ module Vortex
|
|
139
101
|
class Resource
|
140
102
|
end
|
141
103
|
|
142
|
-
|
104
|
+
# PlainFile: This is the same as 'File' in Vortex.
|
143
105
|
class PlainFile < Resource
|
144
|
-
#
|
106
|
+
# Named PlainFile so it won't get mixed up with standard File class.
|
145
107
|
end
|
146
108
|
|
147
109
|
|
@@ -346,7 +308,7 @@ module Vortex
|
|
346
308
|
|
347
309
|
|
348
310
|
|
349
|
-
# Event
|
311
|
+
# HtmlEvent: Event document. Article with location, map url, start and end dates.
|
350
312
|
#
|
351
313
|
# Examples:
|
352
314
|
#
|
@@ -469,7 +431,8 @@ module Vortex
|
|
469
431
|
end
|
470
432
|
|
471
433
|
|
472
|
-
# Vortex article stored as JSON data.
|
434
|
+
# Vortex article stored as JSON data.
|
435
|
+
# TODO: Fill out the stub.
|
473
436
|
class StructuredArticle < PlainFile
|
474
437
|
|
475
438
|
attr_accessor :title, :introduction, :content, :filename, :modifiedDate, :publishedDate, :owner, :url
|
@@ -496,18 +459,32 @@ module Vortex
|
|
496
459
|
|
497
460
|
# Collection (folder)
|
498
461
|
class Collection < Resource
|
499
|
-
|
462
|
+
attr_accessor :title, :url, :foldername, :name, :introduction, :navigationTitle, :sortByDate, :sortByTitle, :owner
|
500
463
|
|
501
|
-
|
502
|
-
|
464
|
+
def url
|
465
|
+
if(@url)
|
466
|
+
return @url
|
467
|
+
end
|
468
|
+
if(@foldername)
|
469
|
+
return @foldername
|
470
|
+
end
|
471
|
+
if(@name)
|
472
|
+
return @name
|
473
|
+
end
|
474
|
+
if(@title)
|
475
|
+
return StringUtils.create_filename(title)
|
476
|
+
end
|
477
|
+
return "no-name"
|
478
|
+
end
|
503
479
|
|
504
480
|
def initialize(options={})
|
505
481
|
options.each{|k,v|send("#{k}=",v)}
|
506
482
|
end
|
507
483
|
|
508
484
|
def properties()
|
509
|
-
props = "<v:resourceType xmlns:v=\"vrtx\">
|
510
|
-
|
485
|
+
# props = "<v:resourceType xmlns:v=\"vrtx\">collection</v:resourceType>" +
|
486
|
+
# "<v:collection-type xmlns:v=\"vrtx\">article-listing</v:collection-type>"
|
487
|
+
props = ""
|
511
488
|
if(title and title != "")
|
512
489
|
props += "<v:userTitle xmlns:v=\"vrtx\">#{title}</v:userTitle>"
|
513
490
|
end
|
@@ -522,6 +499,74 @@ module Vortex
|
|
522
499
|
|
523
500
|
end
|
524
501
|
|
502
|
+
class ArticleListingCollection < Collection
|
503
|
+
|
504
|
+
def properties()
|
505
|
+
props = super
|
506
|
+
props += "<v:resourceType xmlns:v=\"vrtx\">article-listing</v:resourceType>" +
|
507
|
+
"<v:collection-type xmlns:v=\"vrtx\">article-listing</v:collection-type>"
|
508
|
+
return props
|
509
|
+
end
|
510
|
+
|
511
|
+
end
|
512
|
+
|
513
|
+
|
514
|
+
class EventListingCollection < Collection
|
515
|
+
|
516
|
+
def properties()
|
517
|
+
props = super
|
518
|
+
props += "<v:resourceType xmlns:v=\"vrtx\">event-listing</v:resourceType>" +
|
519
|
+
"<v:collection-type xmlns:v=\"vrtx\">event-listing</v:collection-type>"
|
520
|
+
return props
|
521
|
+
end
|
522
|
+
|
523
|
+
end
|
524
|
+
|
525
|
+
|
526
|
+
|
527
|
+
# Utilities
|
528
|
+
#
|
529
|
+
# Convert norwegian date to Time object with a forgiven regexp
|
530
|
+
#
|
531
|
+
# TODO: Move this somewhere.
|
532
|
+
#
|
533
|
+
# Examples:
|
534
|
+
#
|
535
|
+
# t = norwegian_date('1.1.2010')
|
536
|
+
# t = norwegian_date('22.01.2010')
|
537
|
+
# t = norwegian_date('22.01.2010 12:15')
|
538
|
+
# t = norwegian_date('22.01.2010 12:15:20')
|
539
|
+
def norwegian_date(date)
|
540
|
+
if /\A\s*
|
541
|
+
(\d\d?).(\d\d?).(-?\d+)
|
542
|
+
\s?
|
543
|
+
(\d\d?)?:?(\d\d?)?:?(\d\d?)?
|
544
|
+
\s*\z/ix =~ date
|
545
|
+
year = $3.to_i
|
546
|
+
mon = $2.to_i
|
547
|
+
day = $1.to_i
|
548
|
+
hour = $4.to_i
|
549
|
+
min = $5.to_i
|
550
|
+
sec = $6.to_i
|
551
|
+
|
552
|
+
# puts "Debug: #{year} #{mon} #{day} #{hour}:#{min}:#{sec}"
|
553
|
+
|
554
|
+
usec = 0
|
555
|
+
usec = $7.to_f * 1000000 if $7
|
556
|
+
if $8
|
557
|
+
zone = $8
|
558
|
+
year, mon, day, hour, min, sec =
|
559
|
+
apply_offset(year, mon, day, hour, min, sec, zone_offset(zone))
|
560
|
+
Time.utc(year, mon, day, hour, min, sec, usec)
|
561
|
+
else
|
562
|
+
Time.local(year, mon, day, hour, min, sec, usec)
|
563
|
+
end
|
564
|
+
else
|
565
|
+
raise ArgumentError.new("invalid date: #{date.inspect}")
|
566
|
+
end
|
567
|
+
end
|
568
|
+
|
569
|
+
|
525
570
|
end
|
526
571
|
|
527
572
|
|
@@ -12,7 +12,7 @@ class TestVortexCollection < Test::Unit::TestCase
|
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
-
should "create collection (folder)" do
|
15
|
+
should "create article listing collection (folder)" do
|
16
16
|
url = 'https://vortex-dav.uio.no/brukere/thomasfl/nyheter/my-collection'
|
17
17
|
if(@vortex.exists?(url))
|
18
18
|
@vortex.delete(url)
|
@@ -26,4 +26,54 @@ class TestVortexCollection < Test::Unit::TestCase
|
|
26
26
|
assert created_path == url
|
27
27
|
end
|
28
28
|
|
29
|
+
|
30
|
+
should "create event listing collection (folder)" do
|
31
|
+
url = 'https://vortex-dav.uio.no/brukere/thomasfl/nyheter/event-collection'
|
32
|
+
if(@vortex.exists?(url))
|
33
|
+
@vortex.delete(url)
|
34
|
+
end
|
35
|
+
|
36
|
+
@vortex.cd('/brukere/thomasfl/nyheter/')
|
37
|
+
collection = EventListingCollection.new(:url => 'event-collection', :title => 'Event Collection')
|
38
|
+
|
39
|
+
created_path = @vortex.create(collection)
|
40
|
+
|
41
|
+
assert @vortex.exists?(created_path)
|
42
|
+
assert created_path == url
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
should "create collection name from title" do
|
47
|
+
url = 'https://vortex-dav.uio.no/brukere/thomasfl/nyheter/event-collection'
|
48
|
+
if(@vortex.exists?(url))
|
49
|
+
@vortex.delete(url)
|
50
|
+
end
|
51
|
+
|
52
|
+
@vortex.cd('/brukere/thomasfl/nyheter/')
|
53
|
+
collection = EventListingCollection.new(:title => 'Event Collection')
|
54
|
+
|
55
|
+
created_path = @vortex.create(collection)
|
56
|
+
|
57
|
+
assert @vortex.exists?(created_path)
|
58
|
+
assert created_path == url
|
59
|
+
end
|
60
|
+
|
61
|
+
|
62
|
+
should "create collection name from foldername" do
|
63
|
+
url = 'https://vortex-dav.uio.no/brukere/thomasfl/nyheter/event-collection'
|
64
|
+
if(@vortex.exists?(url))
|
65
|
+
@vortex.delete(url)
|
66
|
+
end
|
67
|
+
|
68
|
+
@vortex.cd('/brukere/thomasfl/nyheter/')
|
69
|
+
collection = EventListingCollection.new(:foldername => 'event-collection')
|
70
|
+
|
71
|
+
created_path = @vortex.create(collection)
|
72
|
+
|
73
|
+
assert @vortex.exists?(created_path)
|
74
|
+
assert created_path == url
|
75
|
+
end
|
76
|
+
|
77
|
+
|
78
|
+
|
29
79
|
end
|
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.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thomas Flemming
|
@@ -59,12 +59,17 @@ files:
|
|
59
59
|
- Rakefile
|
60
60
|
- VERSION
|
61
61
|
- bin/vrtx-sync
|
62
|
+
- examples/create_collection.rb
|
63
|
+
- examples/publish_article.rb
|
64
|
+
- examples/publish_event.rb
|
62
65
|
- lib/vortex_client.rb
|
63
66
|
- lib/vortex_client/string_utils.rb
|
64
67
|
- test/helper.rb
|
68
|
+
- test/test_date_conversion.rb
|
65
69
|
- test/test_vortex_article_publish.rb
|
66
70
|
- test/test_vortex_client.rb
|
67
71
|
- test/test_vortex_collection.rb
|
72
|
+
- test/test_vortex_event.rb
|
68
73
|
- test/test_vortex_tags.rb
|
69
74
|
- test/test_vortex_utils.rb
|
70
75
|
has_rdoc: true
|
@@ -104,3 +109,6 @@ test_files:
|
|
104
109
|
- test/test_vortex_event.rb
|
105
110
|
- test/test_vortex_tags.rb
|
106
111
|
- test/test_vortex_utils.rb
|
112
|
+
- examples/create_collection.rb
|
113
|
+
- examples/publish_article.rb
|
114
|
+
- examples/publish_event.rb
|