confluencer 0.4.7 → 0.4.8
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -0
- data/VERSION +1 -1
- data/confluencer.gemspec +6 -3
- data/lib/confluence/attachment.rb +36 -0
- data/lib/confluence/blog_entry.rb +1 -5
- data/lib/confluence/findable.rb +4 -1
- data/lib/confluence/page.rb +12 -5
- data/lib/confluencer.rb +2 -1
- data/spec/confluence/attachment_spec.rb +46 -0
- data/spec/confluence/bookmark_spec.rb +8 -0
- data/spec/confluence/page_spec.rb +22 -35
- data/spec/spec_helper.rb +19 -0
- metadata +7 -4
data/Rakefile
CHANGED
@@ -29,6 +29,7 @@ Spec::Rake::SpecTask.new(:rcov) do |spec|
|
|
29
29
|
spec.libs << 'lib' << 'spec'
|
30
30
|
spec.pattern = 'spec/**/*_spec.rb'
|
31
31
|
spec.rcov = true
|
32
|
+
spec.rcov_opts = ['--text-report', '--include-file lib/confluence/', '--exclude app,config,gems,lib,src,spec']
|
32
33
|
end
|
33
34
|
|
34
35
|
task :spec => :check_dependencies
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.4.
|
1
|
+
0.4.8
|
data/confluencer.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{confluencer}
|
8
|
-
s.version = "0.4.
|
8
|
+
s.version = "0.4.8"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Gabor Ratky"]
|
12
|
-
s.date = %q{2010-05-
|
12
|
+
s.date = %q{2010-05-20}
|
13
13
|
s.description = %q{ActiveRecord-like classes to access Confluence through XMLRPC.}
|
14
14
|
s.email = %q{rgabo@rgabostyle.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -26,6 +26,7 @@ Gem::Specification.new do |s|
|
|
26
26
|
"VERSION",
|
27
27
|
"confluencer.gems",
|
28
28
|
"confluencer.gemspec",
|
29
|
+
"lib/confluence/attachment.rb",
|
29
30
|
"lib/confluence/blog_entry.rb",
|
30
31
|
"lib/confluence/bookmark.rb",
|
31
32
|
"lib/confluence/client.rb",
|
@@ -40,6 +41,7 @@ Gem::Specification.new do |s|
|
|
40
41
|
"script/console",
|
41
42
|
"script/console_init.rb",
|
42
43
|
"spec/confluence.yaml.example",
|
44
|
+
"spec/confluence/attachment_spec.rb",
|
43
45
|
"spec/confluence/bookmark_spec.rb",
|
44
46
|
"spec/confluence/client_spec.rb",
|
45
47
|
"spec/confluence/page_spec.rb",
|
@@ -57,7 +59,8 @@ Gem::Specification.new do |s|
|
|
57
59
|
s.rubygems_version = %q{1.3.7}
|
58
60
|
s.summary = %q{Useful classes to manage Confluence.}
|
59
61
|
s.test_files = [
|
60
|
-
"spec/confluence/
|
62
|
+
"spec/confluence/attachment_spec.rb",
|
63
|
+
"spec/confluence/bookmark_spec.rb",
|
61
64
|
"spec/confluence/client_spec.rb",
|
62
65
|
"spec/confluence/page_spec.rb",
|
63
66
|
"spec/confluence/record_spec.rb",
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Confluence
|
2
|
+
class Attachment < Record
|
3
|
+
extend Findable
|
4
|
+
|
5
|
+
record_attr_accessor :id => :attachment_id
|
6
|
+
record_attr_accessor :pageId => :page_id
|
7
|
+
record_attr_accessor :fileName => :filename
|
8
|
+
record_attr_accessor :fileSize => :filesize
|
9
|
+
record_attr_accessor :contentType => :content_type
|
10
|
+
record_attr_accessor :title, :creator, :created, :url, :comment
|
11
|
+
|
12
|
+
attr_writer :data
|
13
|
+
|
14
|
+
def data
|
15
|
+
@data ||= client.getAttachmentData(page_id, filename, "0")
|
16
|
+
end
|
17
|
+
|
18
|
+
def store
|
19
|
+
# reinitialize attachment after storing it
|
20
|
+
initialize(client.addAttachment(page_id, self.to_hash, XMLRPC::Base64.new(@data)))
|
21
|
+
|
22
|
+
# return self
|
23
|
+
self
|
24
|
+
end
|
25
|
+
|
26
|
+
def remove
|
27
|
+
client.removeAttachment(page_id, filename)
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.find_criteria(args)
|
31
|
+
if args.key? :page_id and args.key? :filename
|
32
|
+
self.new(client.getAttachment(args[:page_id], args[:filename], args[:version] || "0"))
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -9,11 +9,7 @@ module Confluence
|
|
9
9
|
record_attr_accessor :url
|
10
10
|
|
11
11
|
private
|
12
|
-
|
13
|
-
def self.find_all
|
14
|
-
raise ArgumentError, "Cannot find all blog entries, find by id or title instead."
|
15
|
-
end
|
16
|
-
|
12
|
+
|
17
13
|
def self.find_criteria(args)
|
18
14
|
if args.key? :id
|
19
15
|
self.new(client.getBlogEntries(args[:id]))
|
data/lib/confluence/findable.rb
CHANGED
@@ -7,7 +7,10 @@ module Confluence
|
|
7
7
|
def find(args)
|
8
8
|
begin
|
9
9
|
case args
|
10
|
-
when :all:
|
10
|
+
when :all: begin
|
11
|
+
raise "Cannot find all #{self.class.name.downcase}s, find by criteria instead." unless respond_to? :find_all
|
12
|
+
find_all
|
13
|
+
end
|
11
14
|
when Hash: find_criteria(args)
|
12
15
|
end
|
13
16
|
rescue Confluence::Error
|
data/lib/confluence/page.rb
CHANGED
@@ -80,7 +80,12 @@ module Confluence
|
|
80
80
|
|
81
81
|
def children(klass = self.class)
|
82
82
|
children = client.getChildren(page_id)
|
83
|
-
children.collect { |
|
83
|
+
children.collect { |hash| klass.find(:id => hash["id"]) } if children
|
84
|
+
end
|
85
|
+
|
86
|
+
def attachments
|
87
|
+
attachments = client.getAttachments(page_id)
|
88
|
+
attachments.collect { |hash| Attachment.new(hash) } if attachments
|
84
89
|
end
|
85
90
|
|
86
91
|
def store(args = {})
|
@@ -115,6 +120,12 @@ module Confluence
|
|
115
120
|
def remove
|
116
121
|
client.removePage(page_id)
|
117
122
|
end
|
123
|
+
|
124
|
+
def add_attachment(filename, content_type, data = IO.read(filename), comment = "")
|
125
|
+
attachment = Attachment.new :pageId => page_id, :fileName => filename, :contentType => content_type, :comment => comment
|
126
|
+
attachment.data = data
|
127
|
+
attachment.store
|
128
|
+
end
|
118
129
|
|
119
130
|
def to_hash
|
120
131
|
# record hash
|
@@ -132,10 +143,6 @@ module Confluence
|
|
132
143
|
|
133
144
|
private
|
134
145
|
|
135
|
-
def self.find_all
|
136
|
-
raise ArgumentError, "Cannot find all pages, find by id or title instead."
|
137
|
-
end
|
138
|
-
|
139
146
|
def self.find_criteria(args)
|
140
147
|
if args.key? :id
|
141
148
|
self.new(client.getPage(args[:id]))
|
data/lib/confluencer.rb
CHANGED
@@ -0,0 +1,46 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
|
2
|
+
|
3
|
+
describe Confluence::Attachment do
|
4
|
+
include PageHelperMethods
|
5
|
+
|
6
|
+
FILENAME = File.basename(__FILE__)
|
7
|
+
|
8
|
+
it "should store an attachment" do
|
9
|
+
with_test_page do |page|
|
10
|
+
attachment = Confluence::Attachment.new :pageId => page.page_id, :fileName => FILENAME, :contentType => "text/plain", :comment => "Test upload"
|
11
|
+
attachment.data = IO.read(__FILE__)
|
12
|
+
attachment.store
|
13
|
+
|
14
|
+
attachment.attachment_id.should_not be_nil
|
15
|
+
attachment.filesize.should_not be_nil
|
16
|
+
attachment.url.should_not be_nil
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should find an attachment and get its data" do
|
21
|
+
with_test_page do |page|
|
22
|
+
attachment = Confluence::Attachment.new :pageId => page.page_id, :fileName => FILENAME, :contentType => "text/plain", :comment => "Test upload"
|
23
|
+
attachment.data = IO.read(__FILE__)
|
24
|
+
attachment.store
|
25
|
+
|
26
|
+
attachment = Confluence::Attachment.find :page_id => page.page_id, :filename => FILENAME
|
27
|
+
attachment.should_not be_nil
|
28
|
+
attachment.filename.should == FILENAME
|
29
|
+
attachment.data.should == IO.read(__FILE__)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should remove an attachment" do
|
34
|
+
with_test_page do |page|
|
35
|
+
attachment = Confluence::Attachment.new :pageId => page.page_id, :fileName => FILENAME, :contentType => "text/plain", :comment => "Test upload"
|
36
|
+
attachment.data = IO.read(__FILE__)
|
37
|
+
attachment.store
|
38
|
+
|
39
|
+
# remove attachment
|
40
|
+
attachment.remove
|
41
|
+
|
42
|
+
# should not be able to find attachment
|
43
|
+
Confluence::Attachment.find(:page_id => page.page_id, :filename => FILENAME).should be_nil
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -46,8 +46,16 @@ describe Confluence::Bookmark do
|
|
46
46
|
|
47
47
|
it "should find bookmarks by space" do
|
48
48
|
new_session do
|
49
|
+
# add a test bookmark to the confluencer space
|
50
|
+
bookmark = Confluence::Bookmark.new :space => "confluencer", :bookmark_url => 'http://github.com/rgabo/confluencer', :description => 'Home sweet home', :title => "Page title"
|
51
|
+
bookmark.store
|
52
|
+
|
53
|
+
# find bookmarks in space
|
49
54
|
bookmarks = Confluence::Bookmark.find :space => "confluencer"
|
50
55
|
bookmarks.should_not be_empty
|
56
|
+
|
57
|
+
# remove test bookmark
|
58
|
+
bookmark.remove
|
51
59
|
end
|
52
60
|
end
|
53
61
|
end
|
@@ -46,32 +46,9 @@ CONTENT
|
|
46
46
|
end
|
47
47
|
|
48
48
|
describe Confluence::Page do
|
49
|
-
include
|
50
|
-
|
51
|
-
def create_test_page(content = "foobar")
|
52
|
-
Confluence::Page.new :space => config[:space], :title => config[:page_title], :content => content
|
53
|
-
end
|
54
|
-
|
55
|
-
def store_test_page
|
56
|
-
new_session do
|
57
|
-
return create_test_page.store
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
after :each do
|
62
|
-
new_session do
|
63
|
-
begin
|
64
|
-
# check whether we need to remove the test page
|
65
|
-
test_page = Confluence::Page.find :space => config[:space], :title => config[:page_title]
|
66
|
-
test_page.remove if test_page
|
67
|
-
rescue Confluence::Error
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
49
|
+
include PageHelperMethods
|
71
50
|
|
72
51
|
it "should add a new page in Confluence" do
|
73
|
-
page = nil
|
74
|
-
|
75
52
|
new_session do
|
76
53
|
# initialize test page
|
77
54
|
page = create_test_page
|
@@ -84,23 +61,21 @@ describe Confluence::Page do
|
|
84
61
|
|
85
62
|
# check page_id
|
86
63
|
page.page_id.should_not be_nil
|
87
|
-
end
|
88
64
|
|
89
|
-
# initialize new session
|
90
|
-
new_session do
|
91
65
|
# find page by id
|
92
66
|
new_page = Confluence::Page.find :id => page.page_id
|
93
67
|
|
94
68
|
# assert page
|
95
69
|
new_page.should_not be_nil
|
96
70
|
new_page.title.should == page.title
|
71
|
+
|
72
|
+
# remove page
|
73
|
+
new_page.remove
|
97
74
|
end
|
98
75
|
end
|
99
76
|
|
100
77
|
it "should update an existing page in Confluence by id" do
|
101
|
-
|
102
|
-
|
103
|
-
new_session do
|
78
|
+
with_test_page do |page|
|
104
79
|
# create test page with same id but updated content
|
105
80
|
updated_page = create_test_page "updated content"
|
106
81
|
|
@@ -116,9 +91,7 @@ describe Confluence::Page do
|
|
116
91
|
end
|
117
92
|
|
118
93
|
it "should update an existing page in Confluence by space and title" do
|
119
|
-
|
120
|
-
|
121
|
-
new_session do
|
94
|
+
with_test_page do |page|
|
122
95
|
# create test page with same title but updated content
|
123
96
|
updated_page = create_test_page "updated content"
|
124
97
|
|
@@ -136,7 +109,7 @@ describe Confluence::Page do
|
|
136
109
|
end
|
137
110
|
|
138
111
|
it "should keep metadata for the page" do
|
139
|
-
page =
|
112
|
+
page = create_test_page
|
140
113
|
|
141
114
|
# set :creator in {details:label=bender} to 'rgabo'
|
142
115
|
page.details[:confluencer][:creator] = 'rgabo'
|
@@ -145,7 +118,7 @@ describe Confluence::Page do
|
|
145
118
|
end
|
146
119
|
|
147
120
|
it "should include metadata in content of the page" do
|
148
|
-
page =
|
121
|
+
page = create_test_page
|
149
122
|
|
150
123
|
# set :creator in {details:label=bender} to 'rgabo'
|
151
124
|
page.details[:confluencer][:creator] = 'rgabo'
|
@@ -168,5 +141,19 @@ describe Confluence::Page do
|
|
168
141
|
|
169
142
|
page.details[:confluencer][:creator].should == "rgabo"
|
170
143
|
end
|
144
|
+
|
145
|
+
it "should add an attachment" do
|
146
|
+
with_test_page do |page|
|
147
|
+
page.add_attachment(File.basename(__FILE__), "text/plain", IO.read(__FILE__), "test attachment comment")
|
148
|
+
|
149
|
+
page.attachments.count.should == 1
|
150
|
+
|
151
|
+
attachment = page.attachments.first
|
152
|
+
|
153
|
+
attachment.should_not be_nil
|
154
|
+
attachment.url.should_not be_nil
|
155
|
+
attachment.data.should == IO.read(__FILE__)
|
156
|
+
end
|
157
|
+
end
|
171
158
|
end
|
172
159
|
|
data/spec/spec_helper.rb
CHANGED
@@ -34,4 +34,23 @@ module SessionHelperMethods
|
|
34
34
|
end
|
35
35
|
end
|
36
36
|
end
|
37
|
+
|
38
|
+
module PageHelperMethods
|
39
|
+
include SessionHelperMethods
|
37
40
|
|
41
|
+
def create_test_page(content = "foobar")
|
42
|
+
Confluence::Page.new :space => config[:space], :title => config[:page_title], :content => content
|
43
|
+
end
|
44
|
+
|
45
|
+
def with_test_page
|
46
|
+
new_session do
|
47
|
+
begin
|
48
|
+
# yield created test page
|
49
|
+
yield page = create_test_page.store
|
50
|
+
ensure
|
51
|
+
# remove test page
|
52
|
+
page.remove
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: confluencer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 31
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 4
|
9
|
-
-
|
10
|
-
version: 0.4.
|
9
|
+
- 8
|
10
|
+
version: 0.4.8
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Gabor Ratky
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-05-
|
18
|
+
date: 2010-05-20 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -69,6 +69,7 @@ files:
|
|
69
69
|
- VERSION
|
70
70
|
- confluencer.gems
|
71
71
|
- confluencer.gemspec
|
72
|
+
- lib/confluence/attachment.rb
|
72
73
|
- lib/confluence/blog_entry.rb
|
73
74
|
- lib/confluence/bookmark.rb
|
74
75
|
- lib/confluence/client.rb
|
@@ -83,6 +84,7 @@ files:
|
|
83
84
|
- script/console
|
84
85
|
- script/console_init.rb
|
85
86
|
- spec/confluence.yaml.example
|
87
|
+
- spec/confluence/attachment_spec.rb
|
86
88
|
- spec/confluence/bookmark_spec.rb
|
87
89
|
- spec/confluence/client_spec.rb
|
88
90
|
- spec/confluence/page_spec.rb
|
@@ -128,6 +130,7 @@ signing_key:
|
|
128
130
|
specification_version: 3
|
129
131
|
summary: Useful classes to manage Confluence.
|
130
132
|
test_files:
|
133
|
+
- spec/confluence/attachment_spec.rb
|
131
134
|
- spec/confluence/bookmark_spec.rb
|
132
135
|
- spec/confluence/client_spec.rb
|
133
136
|
- spec/confluence/page_spec.rb
|