vortex_client 0.5.2 → 0.5.3

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.2
1
+ 0.5.3
data/lib/vortex_client.rb CHANGED
@@ -4,6 +4,8 @@ require 'vortex_client/string_utils'
4
4
  require 'highline/import'
5
5
  require 'time'
6
6
 
7
+
8
+
7
9
  # Utilities for managing content in the web content management system Vortex.
8
10
  # All calls are done with the webdav protocol.
9
11
  module Vortex
@@ -62,7 +64,7 @@ module Vortex
62
64
  # article = Vortex::StructuredArticle(:title=>"My title")
63
65
  # vortex.publish(article)
64
66
  def publish(object)
65
- if(object.is_a? HtmlArticle or object.is_a? HtmlEvent)
67
+ if(object.is_a? HtmlArticle or object.is_a? HtmlEvent or object.is_a? StructuredArticle)
66
68
  uri = @uri.merge(object.url)
67
69
  # puts "DEBUG: '" + object.class.to_s + "=" + object.properties
68
70
  self.put_string(uri, object.content)
@@ -97,7 +99,8 @@ module Vortex
97
99
 
98
100
  end
99
101
 
100
-
102
+ # Gimmick the internal resource hierarchy in Vortex as class hierarchy in ruby
103
+ # with resource as the root class.
101
104
  class Resource
102
105
  end
103
106
 
@@ -106,7 +109,7 @@ module Vortex
106
109
  # Named PlainFile so it won't get mixed up with standard File class.
107
110
  end
108
111
 
109
- # Plain HTML files with title, introduction and keywords set as webdav properties.
112
+ # HtmlArticle: Plain HTML files with title, introduction and keywords set as WebDAV properties.
110
113
  #
111
114
  # Examples:
112
115
  #
@@ -213,7 +216,6 @@ module Vortex
213
216
  end
214
217
  props += '</vrtx:values></v:tags>'
215
218
  end
216
-
217
219
  return props
218
220
  end
219
221
 
@@ -362,9 +364,9 @@ module Vortex
362
364
 
363
365
  # Vortex article stored as JSON data.
364
366
  # TODO: Fill out the stub.
365
- class StructuredArticle < PlainFile
367
+ class StructuredArticle < HtmlArticle
366
368
 
367
- attr_accessor :title, :introduction, :content, :filename, :modifiedDate, :publishedDate, :owner, :url
369
+ attr_accessor :title, :introduction, :content, :filename, :modifiedDate, :publishedDate, :owner, :url, :picture
368
370
 
369
371
  # Create an article
370
372
  # Options:
@@ -374,18 +376,120 @@ module Vortex
374
376
  options.each{|k,v|send("#{k}=",v)}
375
377
  end
376
378
 
379
+
380
+ def url
381
+ if(@url)
382
+ @url
383
+ else
384
+ if(filename)
385
+ filename
386
+ end
387
+ if(title)
388
+ StringUtils.create_filename(title) + ".html"
389
+ else
390
+ warn "Article must have either a full url or title. "
391
+ end
392
+ end
393
+ end
394
+
377
395
  def to_s
378
396
  "#<Vortex::StructuredArticle "+instance_variables.collect{|var|var+": "+instance_variable_get(var).to_s}.join(",")+">"
379
397
  end
380
398
 
381
- def dav_properties
382
- "<xml todo>"
399
+
400
+ def content
401
+ json = <<-EOF
402
+ {
403
+ "resourcetype": "structured-article",
404
+ "properties": {
405
+ EOF
406
+ if(body and body.size > 0)
407
+ tmp_body = body
408
+ # Escape '"' and line shifts so html will be valid json data.
409
+ tmp_body = body.gsub(/\r/,"\\\r").gsub(/\n/,"\\\n").gsub(/\"/,"\\\"")
410
+ json += " \"content\": \"#{tmp_body}\",\n"
411
+ end
412
+ if(author and author.size > 0)
413
+ json += " \"author\": [\"#{author}\"],\n"
414
+ end
415
+ json += " \"title\": \"#{title}\",\n"
416
+ if(introduction and introduction.size > 0)
417
+ tmp_introduction = introduction
418
+ tmp_introduction = tmp_introduction.gsub(/\r/,"\\\r")
419
+ tmp_introduction = tmp_introduction.gsub(/\n/,"\\\n")
420
+ tmp_introduction = tmp_introduction.gsub(/\"/,"\\\"")
421
+ json += " \"introduction\": \"#{tmp_introduction}\",\n"
422
+ end
423
+ if(picture)
424
+ json += " \"picture\": \"#{picture}\",\n"
425
+ end
426
+ json += <<-EOF
427
+ "hideAdditionalContent": "false"
428
+ }
429
+ }
430
+ EOF
431
+ return json
383
432
  end
384
433
 
385
- def dav_content
386
- "<html todo>"
434
+ def properties
435
+ props = '<v:resourceType xmlns:v="vrtx">structured-article</v:resourceType>' +
436
+ # '<v:xhtml10-type xmlns:v="vrtx">structured-article</v:xhtml10-type>' +
437
+ '<v:userSpecifiedCharacterEncoding xmlns:v="vrtx">utf-8</v:userSpecifiedCharacterEncoding>' +
438
+ '<d:getcontenttype>application/json</d:getcontenttype>'
439
+
440
+ if(@publishedDate and @publishedDate != "")
441
+ if(@publishedDate.kind_of? Time)
442
+ @publishedDate = @publishedDate.httpdate.to_s
443
+ end
444
+ props += '<v:published-date xmlns:v="vrtx">' + @publishedDate + '</v:published-date>'
445
+ end
446
+
447
+ if(date and date != "")
448
+ if(date.kind_of? Time)
449
+ date = @date.httpdate.to_s
450
+ end
451
+ if(@publishedDate == nil or @publishedDate != "")
452
+ props += '<v:published-date xmlns:v="vrtx">' + date + '</v:published-date>'
453
+ end
454
+ props += '<d:getlastmodified>' + date + '</d:getlastmodified>' +
455
+ '<v:contentLastModified xmlns:v="vrtx">' + date + '</v:contentLastModified>' +
456
+ '<v:propertiesLastModified xmlns:v="vrtx">' + date + '</v:propertiesLastModified>' +
457
+ '<v:creationTime xmlns:v="vrtx">' + date + '</v:creationTime>'
458
+ end
459
+
460
+ if(picture)
461
+ # props += '<v:picture xmlns:v="vrtx">' + picture + '</v:picture>'
462
+ end
463
+
464
+ if(title)
465
+ # props += '<v:userTitle xmlns:v="vrtx">' + title + '</v:userTitle>'
466
+ end
467
+ if(owner)
468
+ props += '<owner xmlns="vrtx">' + owner + '</owner>'
469
+ end
470
+ if(introduction and introduction != "")
471
+ # props += '<introduction xmlns="vrtx">' + escape_html(introduction) + '</introduction>'
472
+ end
473
+ if(author and author != "")
474
+ # props += '<v:authors xmlns:v="vrtx">' +
475
+ # '<vrtx:values xmlns:vrtx="http://vortikal.org/xml-value-list">' +
476
+ # '<vrtx:value>' + author + '</vrtx:value>' +
477
+ # '</vrtx:values>' +
478
+ # '</v:authors>'
479
+ end
480
+
481
+ if(tags and tags.kind_of?(Array) and tags.size > 0)
482
+ # props += '<v:tags xmlns:v="vrtx">' +
483
+ # '<vrtx:values xmlns:vrtx="http://vortikal.org/xml-value-list">'
484
+ # tags.each do |tag|
485
+ # props += "<vrtx:value>#{tag}</vrtx:value>"
486
+ # end
487
+ # props += '</vrtx:values></v:tags>'
488
+ end
489
+ return props
387
490
  end
388
491
 
492
+
389
493
  end
390
494
 
391
495
 
@@ -55,7 +55,7 @@ module Vortex
55
55
  ['é','è','ê','ë','Ë','É','È','Ê'] => 'e',
56
56
  ['í','ì','î','ï','I','Î','Ì'] => 'i',
57
57
  ['ó','ò','ô','ö','õ','Õ','Ö','Ô','Ò'] => 'o',
58
- ['œ'] => 'oe',
58
+ ['œ'] => 'e',
59
59
  ['ß'] => 'ss',
60
60
  ['ú','ù','û','ü','U','Û','Ù'] => 'u',
61
61
  ['æ'] => 'ae',
@@ -0,0 +1,40 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'helper'
3
+
4
+ class TestJSONPublish < Test::Unit::TestCase
5
+ include Vortex
6
+
7
+ def setup
8
+ if(not(@vortex))
9
+ user = ENV['DAVUSER']
10
+ pass = ENV['DAVPASS']
11
+ # puts "JSON testene kan foreløpig ikke kjøres på vortex.uio.no?"
12
+ @vortex = Connection.new("https://nyweb1-dav.uio.no",user, pass)
13
+ end
14
+ end
15
+
16
+ should "publish JSON articles" do
17
+ # url = 'https://vortex-dav.uio.no/bloggimport/json-test.html'
18
+ url = 'bloggimport/json-test.html'
19
+ if(@vortex.exists?(url))
20
+ @vortex.delete(url)
21
+ end
22
+
23
+ body = "<p>&nbsp;Bla bla<\/p>\r\n<p>Mer &quot;Bla&quot; bla<\/p>\r\n<p>"+
24
+ "<strong>Enda<\/strong> <a href=\"http://www.vg.no\">mer<\/a> bla bla<\/p>\r\n<p>&nbsp;<\/p>"
25
+
26
+ @vortex.cd('/bloggimport/')
27
+ article = Vortex::StructuredArticle.new(:title => "JSON test",
28
+ :introduction => "Sample introduction",
29
+ :body => body, # .to_json, # "<p>Hello world</p><p>Bla bla</p>",
30
+ :publishedDate => "05.01.2010 12:00",
31
+ :author => "Thomas Flemming",
32
+ :picture => "/bloggimport/forskning/arrangementer/disputaser/2008/01/gran_boe.jpg" )
33
+
34
+ url = @vortex.publish(article)
35
+ puts "For å fullføre testen: Se på denne siden i en nettleser: " + url
36
+ assert @vortex.exists?(url)
37
+ end
38
+
39
+ end
40
+
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 5
8
- - 2
9
- version: 0.5.2
8
+ - 3
9
+ version: 0.5.3
10
10
  platform: ruby
11
11
  authors:
12
12
  - Thomas Flemming
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-03-03 00:00:00 +01:00
17
+ date: 2010-03-11 00:00:00 +01:00
18
18
  default_executable: vrtx-sync
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -123,6 +123,7 @@ test_files:
123
123
  - test/helper.rb
124
124
  - test/test_acl.rb
125
125
  - test/test_date_conversion.rb
126
+ - test/test_json_publish.rb
126
127
  - test/test_vortex_article_publish.rb
127
128
  - test/test_vortex_client.rb
128
129
  - test/test_vortex_collection.rb