confluencer 0.2.8 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/confluencer.gemspec +5 -1
- data/lib/confluence/blog_entry.rb +10 -4
- data/lib/confluence/bookmark.rb +11 -10
- data/lib/confluence/client.rb +1 -1
- data/lib/confluence/findable.rb +17 -0
- data/lib/confluence/page.rb +16 -14
- data/lib/confluence/record.rb +18 -2
- data/lib/confluence/space.rb +41 -0
- data/lib/confluencer.rb +2 -0
- data/spec/confluence/page_spec.rb +4 -8
- data/spec/confluence/space_spec.rb +49 -0
- metadata +7 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.0
|
data/confluencer.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{confluencer}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.3.0"
|
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"]
|
@@ -30,9 +30,11 @@ Gem::Specification.new do |s|
|
|
30
30
|
"lib/confluence/bookmark.rb",
|
31
31
|
"lib/confluence/client.rb",
|
32
32
|
"lib/confluence/error.rb",
|
33
|
+
"lib/confluence/findable.rb",
|
33
34
|
"lib/confluence/page.rb",
|
34
35
|
"lib/confluence/record.rb",
|
35
36
|
"lib/confluence/session.rb",
|
37
|
+
"lib/confluence/space.rb",
|
36
38
|
"lib/confluencer.rb",
|
37
39
|
"script/console",
|
38
40
|
"script/console_init.rb",
|
@@ -42,6 +44,7 @@ Gem::Specification.new do |s|
|
|
42
44
|
"spec/confluence/page_spec.rb",
|
43
45
|
"spec/confluence/record_spec.rb",
|
44
46
|
"spec/confluence/session_spec.rb",
|
47
|
+
"spec/confluence/space_spec.rb",
|
45
48
|
"spec/confluencer_spec.rb",
|
46
49
|
"spec/spec.opts",
|
47
50
|
"spec/spec_helper.rb"
|
@@ -57,6 +60,7 @@ Gem::Specification.new do |s|
|
|
57
60
|
"spec/confluence/page_spec.rb",
|
58
61
|
"spec/confluence/record_spec.rb",
|
59
62
|
"spec/confluence/session_spec.rb",
|
63
|
+
"spec/confluence/space_spec.rb",
|
60
64
|
"spec/confluencer_spec.rb",
|
61
65
|
"spec/spec_helper.rb"
|
62
66
|
]
|
@@ -1,17 +1,23 @@
|
|
1
1
|
module Confluence
|
2
2
|
class BlogEntry < Record
|
3
|
+
extend Findable
|
4
|
+
|
3
5
|
record_attr_accessor :id => :entry_id
|
4
6
|
record_attr_accessor :space
|
5
7
|
record_attr_accessor :title, :content
|
6
8
|
record_attr_accessor :publishDate
|
7
9
|
record_attr_accessor :url
|
8
10
|
|
9
|
-
|
10
|
-
|
11
|
+
private
|
12
|
+
|
13
|
+
def self.find_all
|
14
|
+
raise ArgumentError, "Cannot find all blog entries, find by id or title instead."
|
11
15
|
end
|
12
16
|
|
13
|
-
def self.
|
14
|
-
|
17
|
+
def self.find_criteria(args)
|
18
|
+
if args.key? :id
|
19
|
+
self.new(client.getBlogEntries(args[:id]))
|
20
|
+
end
|
15
21
|
end
|
16
22
|
end
|
17
23
|
end
|
data/lib/confluence/bookmark.rb
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
module Confluence
|
2
2
|
class Bookmark < Page
|
3
|
-
BOOKMARKS_PAGE_TITLE = ".bookmarks"
|
4
|
-
|
5
3
|
attr_reader :bookmark_url, :description
|
6
4
|
|
7
5
|
def initialize(hash)
|
@@ -34,22 +32,25 @@ module Confluence
|
|
34
32
|
|
35
33
|
def store
|
36
34
|
# always set .bookmarks as the parent page
|
37
|
-
self.parent_id = Page.
|
35
|
+
self.parent_id = Page.find(:space => space, :title => Space::BOOKMARKS_PAGE_TITLE).page_id
|
38
36
|
|
39
37
|
# continue with storing the page
|
40
38
|
super
|
41
39
|
end
|
42
40
|
|
43
|
-
|
44
|
-
|
45
|
-
|
41
|
+
private
|
42
|
+
|
43
|
+
def self.find_criteria(args)
|
44
|
+
result = super(args) || begin
|
45
|
+
if args.key? :space
|
46
|
+
space = Space.find :space => args[:space]
|
47
|
+
space.bookmarks
|
48
|
+
end
|
49
|
+
end
|
46
50
|
|
47
|
-
|
48
|
-
bookmarks_page.children.collect {|page| Bookmark.new(page.attributes)}
|
51
|
+
result
|
49
52
|
end
|
50
53
|
|
51
|
-
private
|
52
|
-
|
53
54
|
def update_content
|
54
55
|
self.content = "{bookmark:url=#{@bookmark_url}}#{@description}{bookmark}"
|
55
56
|
end
|
data/lib/confluence/client.rb
CHANGED
@@ -81,7 +81,7 @@ module Confluence
|
|
81
81
|
if args.empty?
|
82
82
|
log.debug "#{method_name}"
|
83
83
|
else
|
84
|
-
log.debug "#{method_name}(#{args.join(', ')})"
|
84
|
+
log.debug "#{method_name}(#{(args.collect {|a| a.inspect}).join(', ')})"
|
85
85
|
end
|
86
86
|
result = proxy.send(method_name, *([@token] + args))
|
87
87
|
log.debug(result.inspect)
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Confluence
|
2
|
+
module Findable
|
3
|
+
# Finds records by the given criteria.
|
4
|
+
#
|
5
|
+
# ==== Parameters
|
6
|
+
# args<Hash>:: The search arguments.
|
7
|
+
def find(args)
|
8
|
+
begin
|
9
|
+
case args
|
10
|
+
when :all: find_all
|
11
|
+
when Hash: find_criteria(args)
|
12
|
+
end
|
13
|
+
rescue Confluence::Error
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/confluence/page.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
module Confluence
|
2
2
|
class Page < Record
|
3
|
+
extend Findable
|
4
|
+
|
3
5
|
record_attr_accessor :id => :page_id
|
4
6
|
record_attr_accessor :parentId => :parent_id
|
5
7
|
record_attr_accessor :space
|
@@ -7,18 +9,18 @@ module Confluence
|
|
7
9
|
record_attr_accessor :created, :modified, :version
|
8
10
|
record_attr_accessor :url
|
9
11
|
|
10
|
-
def children
|
12
|
+
def children(klass = self.class)
|
11
13
|
children = client.getChildren(page_id)
|
12
|
-
children.collect { |child|
|
14
|
+
children.collect { |child| klass.find(:id => child["id"]) } if children
|
13
15
|
end
|
14
16
|
|
15
17
|
def store
|
16
18
|
unless self.version
|
17
19
|
# check for existing page by id or title
|
18
20
|
existing_page = if page_id
|
19
|
-
Page.
|
21
|
+
Page.find :id => page_id
|
20
22
|
else
|
21
|
-
Page.
|
23
|
+
Page.find :space => space, :title => title
|
22
24
|
end
|
23
25
|
|
24
26
|
# take page_id and version from existing page if available
|
@@ -38,18 +40,18 @@ module Confluence
|
|
38
40
|
def remove
|
39
41
|
client.removePage(page_id)
|
40
42
|
end
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def self.find_all
|
47
|
+
raise ArgumentError, "Cannot find all pages, find by id or title instead."
|
47
48
|
end
|
48
49
|
|
49
|
-
def self.
|
50
|
-
|
51
|
-
self.new(client.getPage(
|
52
|
-
|
50
|
+
def self.find_criteria(args)
|
51
|
+
if args.key? :id
|
52
|
+
self.new(client.getPage(args[:id]))
|
53
|
+
elsif args.key?(:space) && args.key?(:title)
|
54
|
+
self.new(client.getPage(args[:space], args[:title]))
|
53
55
|
end
|
54
56
|
end
|
55
57
|
end
|
data/lib/confluence/record.rb
CHANGED
@@ -1,15 +1,23 @@
|
|
1
1
|
module Confluence
|
2
|
+
# Base class for working with Confluence records.
|
3
|
+
#
|
2
4
|
class Record
|
3
5
|
class << self
|
6
|
+
# The client used for Confluence API calls.
|
7
|
+
#
|
4
8
|
def client
|
5
9
|
raise "Confluence client is unavailable. Did you forget to use Confluence::Session.new?" unless @@client
|
6
10
|
@@client
|
7
11
|
end
|
8
12
|
|
13
|
+
# Sets the client.
|
14
|
+
#
|
9
15
|
def client=(value)
|
10
16
|
@@client = value
|
11
17
|
end
|
12
18
|
|
19
|
+
# Defines an attr_accessor for a Record attribute.
|
20
|
+
#
|
13
21
|
def record_attr_accessor(*args)
|
14
22
|
attributes = {}
|
15
23
|
|
@@ -38,6 +46,10 @@ module Confluence
|
|
38
46
|
|
39
47
|
attr_accessor :attributes
|
40
48
|
|
49
|
+
# Initializes a new record.
|
50
|
+
#
|
51
|
+
# ==== Parameters
|
52
|
+
# hash<Hash>:: A hash containing the attributes and its values. Keys can be Strings or Symbols.
|
41
53
|
def initialize(hash)
|
42
54
|
@attributes = {}
|
43
55
|
|
@@ -46,7 +58,7 @@ module Confluence
|
|
46
58
|
self[key.to_sym] = value
|
47
59
|
end
|
48
60
|
end
|
49
|
-
|
61
|
+
|
50
62
|
def [](attr)
|
51
63
|
@attributes[attr]
|
52
64
|
end
|
@@ -54,7 +66,9 @@ module Confluence
|
|
54
66
|
def []=(attr, value)
|
55
67
|
@attributes[attr] = value
|
56
68
|
end
|
57
|
-
|
69
|
+
|
70
|
+
# Returns the id of the record.
|
71
|
+
#
|
58
72
|
def record_id
|
59
73
|
self[:id]
|
60
74
|
end
|
@@ -73,6 +87,8 @@ module Confluence
|
|
73
87
|
@labels = value
|
74
88
|
end
|
75
89
|
|
90
|
+
private
|
91
|
+
|
76
92
|
def client
|
77
93
|
Record.client
|
78
94
|
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module Confluence
|
2
|
+
# A Confluence space.
|
3
|
+
class Space < Record
|
4
|
+
extend Findable
|
5
|
+
|
6
|
+
BOOKMARKS_PAGE_TITLE = ".bookmarks"
|
7
|
+
|
8
|
+
record_attr_accessor :key, :name, :url, :description
|
9
|
+
record_attr_accessor :homePage => :homepage
|
10
|
+
|
11
|
+
def bookmark_page
|
12
|
+
@bookmark_page ||= Page.find :space => self.key, :title => BOOKMARKS_PAGE_TITLE
|
13
|
+
end
|
14
|
+
|
15
|
+
def bookmarks
|
16
|
+
bookmark_page ? bookmark_page.children(Bookmark) : []
|
17
|
+
end
|
18
|
+
|
19
|
+
def blog_entries
|
20
|
+
client.getBlogEntries(self.key).collect {|summary| BlogEntry.new(client.getBlogEntry(summary["id"]))}
|
21
|
+
end
|
22
|
+
|
23
|
+
def find_page(args)
|
24
|
+
if args.key? :title
|
25
|
+
Page.find :space => self.key, :title => args[:title]
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def self.find_all
|
32
|
+
client.getSpaces.collect { |summary| Space.find(:key => summary["key"]) }
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.find_criteria(args)
|
36
|
+
if args.key? :key
|
37
|
+
Space.new(client.getSpace(args[:key]))
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/lib/confluencer.rb
CHANGED
@@ -9,7 +9,9 @@ require 'confluence/error'
|
|
9
9
|
require 'confluence/client'
|
10
10
|
require 'confluence/session'
|
11
11
|
|
12
|
+
require 'confluence/findable'
|
12
13
|
require 'confluence/record'
|
14
|
+
require 'confluence/space'
|
13
15
|
require 'confluence/page'
|
14
16
|
require 'confluence/bookmark'
|
15
17
|
require 'confluence/blog_entry'
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
|
2
2
|
|
3
|
-
|
3
|
+
describe Confluence::Page do
|
4
4
|
include SessionHelperMethods
|
5
5
|
|
6
6
|
def create_test_page(content = "foobar")
|
@@ -12,16 +12,12 @@ module PageHelperMethods
|
|
12
12
|
return create_test_page.store
|
13
13
|
end
|
14
14
|
end
|
15
|
-
end
|
16
|
-
|
17
|
-
describe Confluence::Page do
|
18
|
-
include PageHelperMethods
|
19
15
|
|
20
16
|
after :each do
|
21
17
|
new_session do
|
22
18
|
begin
|
23
19
|
# check whether we need to remove the test page
|
24
|
-
test_page = Confluence::Page.
|
20
|
+
test_page = Confluence::Page.find :space => config[:space], :title => config[:page_title]
|
25
21
|
test_page.remove if test_page
|
26
22
|
rescue Confluence::Error
|
27
23
|
end
|
@@ -31,7 +27,7 @@ describe Confluence::Page do
|
|
31
27
|
it "should add a new page in Confluence" do
|
32
28
|
page = nil
|
33
29
|
|
34
|
-
new_session do
|
30
|
+
new_session do
|
35
31
|
# initialize test page
|
36
32
|
page = create_test_page
|
37
33
|
|
@@ -48,7 +44,7 @@ describe Confluence::Page do
|
|
48
44
|
# initialize new session
|
49
45
|
new_session do
|
50
46
|
# find page by id
|
51
|
-
new_page = Confluence::Page.
|
47
|
+
new_page = Confluence::Page.find :id => page.page_id
|
52
48
|
|
53
49
|
# assert page
|
54
50
|
new_page.should_not be_nil
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
|
2
|
+
|
3
|
+
describe Confluence::Space do
|
4
|
+
include SessionHelperMethods
|
5
|
+
|
6
|
+
def test_space
|
7
|
+
@test_space ||= Confluence::Space.find(:key => config[:space])
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should find all spaces" do
|
11
|
+
new_session do
|
12
|
+
spaces = Confluence::Space.find(:all)
|
13
|
+
|
14
|
+
spaces.should_not be_empty
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should find a space by its key" do
|
19
|
+
new_session do
|
20
|
+
space = Confluence::Space.find(:key => config[:space])
|
21
|
+
|
22
|
+
space.should_not be_nil
|
23
|
+
space.key.should == config[:space]
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should find a page in the space" do
|
28
|
+
new_session do
|
29
|
+
page = test_space.find_page :title => "Home"
|
30
|
+
|
31
|
+
page.should_not be_nil
|
32
|
+
page.space.should == test_space.key
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should return all bookmarks in the space" do
|
37
|
+
new_session do
|
38
|
+
# create a bookmark in the test_space
|
39
|
+
bookmark = Confluence::Bookmark.new :space => test_space.key, :title => "Atlassian", :bookmark_url => "http://atlassian.com"
|
40
|
+
bookmark.store
|
41
|
+
|
42
|
+
bookmarks = test_space.bookmarks
|
43
|
+
bookmarks.should_not be_empty
|
44
|
+
|
45
|
+
# delete test bookmark
|
46
|
+
bookmark.remove
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
8
|
-
-
|
9
|
-
version: 0.
|
7
|
+
- 3
|
8
|
+
- 0
|
9
|
+
version: 0.3.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Gabor Ratky
|
@@ -54,9 +54,11 @@ files:
|
|
54
54
|
- lib/confluence/bookmark.rb
|
55
55
|
- lib/confluence/client.rb
|
56
56
|
- lib/confluence/error.rb
|
57
|
+
- lib/confluence/findable.rb
|
57
58
|
- lib/confluence/page.rb
|
58
59
|
- lib/confluence/record.rb
|
59
60
|
- lib/confluence/session.rb
|
61
|
+
- lib/confluence/space.rb
|
60
62
|
- lib/confluencer.rb
|
61
63
|
- script/console
|
62
64
|
- script/console_init.rb
|
@@ -66,6 +68,7 @@ files:
|
|
66
68
|
- spec/confluence/page_spec.rb
|
67
69
|
- spec/confluence/record_spec.rb
|
68
70
|
- spec/confluence/session_spec.rb
|
71
|
+
- spec/confluence/space_spec.rb
|
69
72
|
- spec/confluencer_spec.rb
|
70
73
|
- spec/spec.opts
|
71
74
|
- spec/spec_helper.rb
|
@@ -105,5 +108,6 @@ test_files:
|
|
105
108
|
- spec/confluence/page_spec.rb
|
106
109
|
- spec/confluence/record_spec.rb
|
107
110
|
- spec/confluence/session_spec.rb
|
111
|
+
- spec/confluence/space_spec.rb
|
108
112
|
- spec/confluencer_spec.rb
|
109
113
|
- spec/spec_helper.rb
|