confluence-rest-api 1.0.8 → 1.0.10
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.
- checksums.yaml +4 -4
- data/README.md +24 -25
- data/confluence-rest-api.gemspec +3 -3
- data/lib/confluence.rb +4 -4
- data/lib/page.rb +74 -0
- data/lib/storage_format.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ed5f052109908ba6e1cc2ed313802359131330793cef7a9bc444c4d1f72bfe22
|
4
|
+
data.tar.gz: 7d7d21092d94dde2f347f018173b8cd611b74c9f6fc20b8bbc79ba146aa2b72a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 24fb564f85688ed4435cc0f654f36b69a351467fe851114802435e1b733d089f958e1bcca66c5341f7efed2eb59ac4e6b7f84e911d1418750d2935d99c6f625b
|
7
|
+
data.tar.gz: 0351b16fb8e6e743ed6c5eadce6c92869406ed74c00ec6437478183ed829d2ebe1b740c8906f948f9cfd51f586c2f8b56f1615a19b086368b037cd432d266cb3
|
data/README.md
CHANGED
@@ -1,10 +1,12 @@
|
|
1
1
|
# Ruby Confluence REST API Client
|
2
2
|
|
3
3
|
[](https://badge.fury.io/rb/confluence-rest-api)
|
4
|
+
|
4
5
|
### Installation
|
5
6
|
```cassandraql
|
6
7
|
gem install confluence-rest-api
|
7
8
|
```
|
9
|
+
|
8
10
|
### Usage
|
9
11
|
```ruby
|
10
12
|
require 'confluence-rest-api'
|
@@ -63,30 +65,6 @@ unless home_page.id.nil?
|
|
63
65
|
client.create_page_with_parent('My Page Title', space_key, 'My Page Body Content', home_page.id)
|
64
66
|
end
|
65
67
|
|
66
|
-
###########################################################
|
67
|
-
# Update a page with a new title and keep the same parent
|
68
|
-
###########################################################
|
69
|
-
page_obj = PageObject.new('My Page Title', space_key)
|
70
|
-
title = 'My New Page Title'
|
71
|
-
# Storage Format for the page can also be modified here if needed.
|
72
|
-
content = page_obj.storage_format
|
73
|
-
unless page_obj.id.nil?
|
74
|
-
client.update_page_with_no_parent(page_obj, title, space_key, content)
|
75
|
-
end
|
76
|
-
|
77
|
-
################################################
|
78
|
-
# Update a page with a new title and new parent
|
79
|
-
################################################
|
80
|
-
page_obj = PageObject.new('My Page Title', space_key)
|
81
|
-
parent_obj = PageObject.new('My New Parent', space_key)
|
82
|
-
title = 'My New Page Title'
|
83
|
-
# Storage Format for the page can also be modified here if needed.
|
84
|
-
content = page_obj.storage_format
|
85
|
-
unless page_obj.id.nil? || parent_obj.id.nil?
|
86
|
-
client.update_page_with_parent(page_obj, title, parent_obj, space_key, content)
|
87
|
-
end
|
88
|
-
|
89
|
-
|
90
68
|
#############################
|
91
69
|
# Add an attachment to a page
|
92
70
|
#############################
|
@@ -97,7 +75,7 @@ unless page_obj.id.nil?
|
|
97
75
|
if page_obj.attach_binary_file(image, img_base_name).nil?
|
98
76
|
puts "*** WARNING: Image attachment #{image} for #{title} was not successful."
|
99
77
|
else
|
100
|
-
puts "Image attachment #{image} for #{title} was successful."
|
78
|
+
puts "Image attachment #{image} for #{page_obj.title} was successful."
|
101
79
|
end
|
102
80
|
end
|
103
81
|
|
@@ -134,6 +112,27 @@ end
|
|
134
112
|
page_obj = PageObject.new('My Page Title', space_key)
|
135
113
|
page_obj.save_file_attachments(page_obj.id, './')
|
136
114
|
|
115
|
+
################################################
|
116
|
+
# Get all labels associated with a given page ID
|
117
|
+
################################################
|
118
|
+
page_obj = PageObject.new('My Page Title', space_key)
|
119
|
+
page_labels = page_obj.labels(page_obj.id)
|
120
|
+
puts "Page Labels for #{page_obj.title}: #{page_labels}"
|
121
|
+
|
122
|
+
#########################
|
123
|
+
# Adding labels to a page
|
124
|
+
#########################
|
125
|
+
page_obj = PageObject.new('My Page Title', space_key)
|
126
|
+
new_labels = ['my_label1','my_label2']
|
127
|
+
page_obj.add_labels(new_labels)
|
128
|
+
|
129
|
+
#############################
|
130
|
+
# Deleting labels from a page
|
131
|
+
#############################
|
132
|
+
page_obj = PageObject.new('My Page Title', space_key)
|
133
|
+
del_labels = ['my_label1','my_label2']
|
134
|
+
page_obj.delete_labels(del_labels)
|
135
|
+
|
137
136
|
###############
|
138
137
|
# Delete a page
|
139
138
|
###############
|
data/confluence-rest-api.gemspec
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = %q{confluence-rest-api}
|
3
|
-
s.version = "1.0.
|
4
|
-
s.date = %q{2020-
|
3
|
+
s.version = "1.0.10"
|
4
|
+
s.date = %q{2020-08-25}
|
5
5
|
s.summary = %q{Ruby REST API Client to create, update, and view pages}
|
6
6
|
s.authors = "Gregory J. Miller"
|
7
7
|
s.files = [
|
8
8
|
"lib/confluence-rest-api.rb", "lib/confluence.rb", "lib/page.rb", "lib/storage_format.rb", "README.md", "confluence-rest-api.gemspec"
|
9
9
|
]
|
10
10
|
s.license = "MIT"
|
11
|
-
s.homepage = "https://github.com/
|
11
|
+
s.homepage = "https://github.com/GM314/confluence-rest-api"
|
12
12
|
s.add_runtime_dependency 'rest-client', '~> 2.0', '>= 2.0.0'
|
13
13
|
|
14
14
|
end
|
data/lib/confluence.rb
CHANGED
@@ -22,14 +22,14 @@ class ConfluenceClient
|
|
22
22
|
|
23
23
|
end
|
24
24
|
|
25
|
-
def update_page_with_parent(page_obj,
|
25
|
+
def update_page_with_parent(page_obj, parent_page_obj, spacekey, content)
|
26
26
|
|
27
27
|
version = page_obj.version + 1
|
28
28
|
|
29
29
|
page_meta = { type: 'update_page_with_parent',
|
30
30
|
pageid: page_obj.id,
|
31
31
|
parentid: parent_page_obj.id,
|
32
|
-
title: title,
|
32
|
+
title: page_obj.title,
|
33
33
|
spacekey: spacekey,
|
34
34
|
content: content,
|
35
35
|
version: version }
|
@@ -49,13 +49,13 @@ class ConfluenceClient
|
|
49
49
|
|
50
50
|
end
|
51
51
|
|
52
|
-
def update_page_with_no_parent(page_obj,
|
52
|
+
def update_page_with_no_parent(page_obj, spacekey, content)
|
53
53
|
|
54
54
|
version = page_obj.version + 1
|
55
55
|
|
56
56
|
page_meta = { type: 'update_page_with_no_parent',
|
57
57
|
pageid: page_obj.id,
|
58
|
-
title: title,
|
58
|
+
title: page_obj.title,
|
59
59
|
spacekey: spacekey,
|
60
60
|
content: content,
|
61
61
|
version: version }
|
data/lib/page.rb
CHANGED
@@ -69,6 +69,80 @@ class PageObject < ConfluenceClient
|
|
69
69
|
true
|
70
70
|
end
|
71
71
|
|
72
|
+
def labels(page_id)
|
73
|
+
begin
|
74
|
+
res = RestClient.get "#{@@conf_url}/#{@@urn}/#{page_id}/label", {params: {
|
75
|
+
:os_username => @@login, :os_password => @@pwd,
|
76
|
+
:start => 0, :limit => 1000
|
77
|
+
}}
|
78
|
+
rescue RestClient::ExceptionWithResponse => e
|
79
|
+
puts Nokogiri.XML(e.response)
|
80
|
+
nil
|
81
|
+
end
|
82
|
+
size = JSON.parse(res)['size']
|
83
|
+
if size > 0
|
84
|
+
size -= 1
|
85
|
+
labels = Array.new
|
86
|
+
(0..size).each do |idx|
|
87
|
+
labels << JSON.parse(res)['results'][idx]["name"]
|
88
|
+
end
|
89
|
+
labels
|
90
|
+
else
|
91
|
+
nil
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def add_labels(labels)
|
96
|
+
payload = String.new('[')
|
97
|
+
json_label = '{
|
98
|
+
"prefix": "global",
|
99
|
+
"name": "__LABEL__"
|
100
|
+
}'.freeze
|
101
|
+
|
102
|
+
labels.each_with_index do |l, idx|
|
103
|
+
jl = json_label.sub(/__LABEL__/, l)
|
104
|
+
if idx == 0
|
105
|
+
payload += jl
|
106
|
+
else
|
107
|
+
payload += ',' + jl
|
108
|
+
end
|
109
|
+
end
|
110
|
+
payload = payload + ']'
|
111
|
+
puts "Add label payload: #{payload}"
|
112
|
+
|
113
|
+
begin
|
114
|
+
res = RestClient.post "#{@@conf_url}/#{@@urn}/#{@id}/label?os_username=#{@@login}&os_password=#{@@pwd}", payload, :content_type => 'application/json'
|
115
|
+
rescue RestClient::ExceptionWithResponse => e
|
116
|
+
puts Nokogiri.XML(e.response)
|
117
|
+
end
|
118
|
+
if res.nil?
|
119
|
+
puts "*** WARNING: Label update failed for page with ID: #{@id}"
|
120
|
+
nil
|
121
|
+
else
|
122
|
+
puts JSON.parse(res)
|
123
|
+
true
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
# Note that we must use query parameters here because deleting labels with a "/" will fail otherwise.
|
128
|
+
def delete_labels(labels)
|
129
|
+
labels.each do |l|
|
130
|
+
puts "Deleting label: #{l}"
|
131
|
+
begin
|
132
|
+
res = RestClient.delete "#{@@conf_url}/#{@@urn}/#{@id}/label?name=#{l}&os_username=#{@@login}&os_password=#{@@pwd}"
|
133
|
+
rescue RestClient::ExceptionWithResponse => e
|
134
|
+
puts Nokogiri.XML(e.response)
|
135
|
+
end
|
136
|
+
if res.nil?
|
137
|
+
puts "*** WARNING: Label removal failed for page with ID: #{@id}"
|
138
|
+
return nil
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
true
|
143
|
+
|
144
|
+
end
|
145
|
+
|
72
146
|
# Return an array of all page attachment information
|
73
147
|
def get_all_attachments(page_id)
|
74
148
|
|
data/lib/storage_format.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: confluence-rest-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gregory J. Miller
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-08-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|
@@ -42,7 +42,7 @@ files:
|
|
42
42
|
- lib/confluence.rb
|
43
43
|
- lib/page.rb
|
44
44
|
- lib/storage_format.rb
|
45
|
-
homepage: https://github.com/
|
45
|
+
homepage: https://github.com/GM314/confluence-rest-api
|
46
46
|
licenses:
|
47
47
|
- MIT
|
48
48
|
metadata: {}
|