confluence-rest-api 1.0.6 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6ef648c1789440d8b0568c147ecfa0f73977892eaeed56aae36a22b2d2f97505
4
- data.tar.gz: 5732c846ff1dda66a7ca5a63939551088cf9906fc10e78efdbcff2d7748b7f5d
3
+ metadata.gz: 699b6a15feda72043c33df69f39c7babed5e966922febcd374c15099af6f47bd
4
+ data.tar.gz: 729fa6fca4165a5a55c436be0374b4157a7c711b21ecae3a2a7912ef1d8246e2
5
5
  SHA512:
6
- metadata.gz: b35aeb68b573092496b57cb5dfb4156dc551ac45bbb156485bd8815a99a3a5f6922ce1cc8243b734d20774293f281fbce650d24dc2402bba4d93fa3b83d64e37
7
- data.tar.gz: f9e68dbdfaaa568b97f154cc223e3969c3e98abb63cba274c5078fb7e5975ae4fc397b9256b8d339c05478470fe7f9c950d9186c57089f98df2ccc99a70c68ba
6
+ metadata.gz: 12288d43598d66f9ec914ceb1e6a8928ab5bbe8e27d886dbdd82c4174105cc84ffcdc15d9f30214e76a9f0ca885c875d7b14b615c76f9059475558b51d9f702c
7
+ data.tar.gz: 496cf4efd0fd2e66515a32981f2da6bdc3a76cf612f65e3e8ee840ccb7822d8eefbe93b3e6d8c35c81def512502bf0295bede78c2c5ff6ba37a1b0c082c986df
data/README.md CHANGED
@@ -1,10 +1,12 @@
1
1
  # Ruby Confluence REST API Client
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/confluence-rest-api.svg)](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'
@@ -14,12 +16,14 @@ user_name = 'username'
14
16
  password = 'password'
15
17
  space_key = 'space'
16
18
 
19
+ ##################################################################
20
+ # A connection to the client must be done before any page requests
21
+ ##################################################################
17
22
  client = ConfluenceClient.new(rest_server, user_name, password)
18
23
 
19
24
  #################################
20
25
  # Query an existing page by title
21
26
  #################################
22
-
23
27
  page = PageObject.new('page_title', space_key)
24
28
  if page.id.nil?
25
29
  puts '*** WARNING: Unable to open page: page_title'
@@ -38,7 +42,6 @@ end
38
42
  ###############################
39
43
  # Query an existing page by id
40
44
  ###############################
41
-
42
45
  page = PageObject.new(123456789, space_key)
43
46
  if page.title.nil?
44
47
  puts '*** WARNING: Unable to open page with id: 123456789'
@@ -57,7 +60,6 @@ end
57
60
  ###########################################################
58
61
  # Create a new page with a page titled "Home" as its parent
59
62
  ###########################################################
60
-
61
63
  home_page = PageObject.new('Home', space_key)
62
64
  unless home_page.id.nil?
63
65
  client.create_page_with_parent('My Page Title', space_key, 'My Page Body Content', home_page.id)
@@ -66,7 +68,6 @@ end
66
68
  #############################
67
69
  # Add an attachment to a page
68
70
  #############################
69
-
70
71
  page_obj = PageObject.new('My Page Title', space_key)
71
72
  unless page_obj.id.nil?
72
73
  img_base_name = 'my/image/location'
@@ -74,14 +75,13 @@ unless page_obj.id.nil?
74
75
  if page_obj.attach_binary_file(image, img_base_name).nil?
75
76
  puts "*** WARNING: Image attachment #{image} for #{title} was not successful."
76
77
  else
77
- puts "Image attachment #{image} for #{title} was successful."
78
+ puts "Image attachment #{image} for #{page_obj.title} was successful."
78
79
  end
79
80
  end
80
81
 
81
82
  ##################################
82
83
  # Remove an attachment from a page
83
84
  ##################################
84
-
85
85
  page_obj = PageObject.new('My Page Title', space_key)
86
86
  id = page_obj.attachment_id('my_image.png')
87
87
  if id.nil?
@@ -112,10 +112,30 @@ end
112
112
  page_obj = PageObject.new('My Page Title', space_key)
113
113
  page_obj.save_file_attachments(page_obj.id, './')
114
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
+
115
136
  ###############
116
137
  # Delete a page
117
138
  ###############
118
-
119
139
  page_obj = PageObject.new('My Page Title', space_key)
120
140
  if page_obj.delete_page(page_obj.id).nil?
121
141
  puts "*** WARNING: Page with ID #{page_obj.id} was not deleted."
@@ -1,14 +1,16 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = %q{confluence-rest-api}
3
- s.version = "1.0.6"
4
- s.date = %q{2020-04-17}
3
+ s.version = "1.1.1"
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/grmi64/confluence-rest-api"
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
+ s.add_runtime_dependency 'json', '~> 2.3', '>= 2.3.1'
14
+ s.add_runtime_dependency 'addressable', '~> 2.3', '>= 2.3.7'
15
+ s.add_runtime_dependency 'nokogiri', '~> 1.6', '>= 1.6.8'
14
16
  end
@@ -1,4 +1,5 @@
1
1
  require 'nokogiri'
2
+ require 'addressable/uri'
2
3
 
3
4
  class PageObject < ConfluenceClient
4
5
 
@@ -69,6 +70,83 @@ class PageObject < ConfluenceClient
69
70
  true
70
71
  end
71
72
 
73
+ def labels
74
+ begin
75
+ res = RestClient.get "#{@@conf_url}/#{@@urn}/#{@id}/label", {params: {
76
+ :os_username => @@login, :os_password => @@pwd,
77
+ :start => 0, :limit => 500
78
+ }}
79
+ rescue RestClient::ExceptionWithResponse => e
80
+ puts Nokogiri.XML(e.response)
81
+ nil
82
+ end
83
+ size = JSON.parse(res)['size']
84
+ if size > 0
85
+ size -= 1
86
+ labels = Array.new
87
+ (0..size).each do |idx|
88
+ labels << JSON.parse(res)['results'][idx]["name"]
89
+ end
90
+ labels
91
+ else
92
+ nil
93
+ end
94
+ end
95
+
96
+ def add_labels(labels)
97
+ payload = String.new('[')
98
+ json_label = '{
99
+ "prefix": "global",
100
+ "name": "__LABEL__"
101
+ }'.freeze
102
+
103
+ labels.each_with_index do |l, idx|
104
+ jl = json_label.sub(/__LABEL__/, l)
105
+ if idx == 0
106
+ payload += jl
107
+ else
108
+ payload += ',' + jl
109
+ end
110
+ end
111
+ payload = payload + ']'
112
+ # puts "Add label payload: #{payload}"
113
+
114
+ begin
115
+ res = RestClient.post "#{@@conf_url}/#{@@urn}/#{@id}/label?os_username=#{@@login}&os_password=#{@@pwd}", payload, :content_type => 'application/json'
116
+ rescue RestClient::ExceptionWithResponse => e
117
+ puts Nokogiri.XML(e.response)
118
+ end
119
+ if res.nil?
120
+ puts "*** WARNING: Label update failed for page with ID: #{@id}"
121
+ nil
122
+ else
123
+ # puts JSON.parse(res)
124
+ true
125
+ end
126
+ end
127
+
128
+ # Note that we must use query parameters here because deleting labels with a "/" will fail otherwise.
129
+ def delete_labels(labels)
130
+ labels.each do |l|
131
+ puts "Deleting label: #{l}"
132
+ begin
133
+ uri = "#{@@conf_url}/#{@@urn}/#{@id}/label?name=#{l}&os_username=#{@@login}&os_password=#{@@pwd}"
134
+ uri = Addressable::URI.parse(uri).normalize.to_s
135
+ res = RestClient.delete uri
136
+
137
+ rescue RestClient::ExceptionWithResponse => e
138
+ puts Nokogiri.XML(e.response)
139
+ end
140
+ if res.nil?
141
+ puts "*** WARNING: Label removal failed for page with ID: #{@id}"
142
+ return nil
143
+ end
144
+ end
145
+
146
+ true
147
+
148
+ end
149
+
72
150
  # Return an array of all page attachment information
73
151
  def get_all_attachments(page_id)
74
152
 
@@ -1,4 +1,4 @@
1
- class StorageFormat
1
+ class PagePayload
2
2
  attr_accessor :page_format
3
3
 
4
4
  VALID_OPTIONS = [:type, :title, :spacekey, :content, :pageid, :parentid, :version]
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.6
4
+ version: 1.1.1
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-04-17 00:00:00.000000000 Z
11
+ date: 2020-08-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -30,6 +30,66 @@ dependencies:
30
30
  - - ">="
31
31
  - !ruby/object:Gem::Version
32
32
  version: 2.0.0
33
+ - !ruby/object:Gem::Dependency
34
+ name: json
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '2.3'
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: 2.3.1
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '2.3'
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 2.3.1
53
+ - !ruby/object:Gem::Dependency
54
+ name: addressable
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - "~>"
58
+ - !ruby/object:Gem::Version
59
+ version: '2.3'
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: 2.3.7
63
+ type: :runtime
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '2.3'
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: 2.3.7
73
+ - !ruby/object:Gem::Dependency
74
+ name: nokogiri
75
+ requirement: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - "~>"
78
+ - !ruby/object:Gem::Version
79
+ version: '1.6'
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: 1.6.8
83
+ type: :runtime
84
+ prerelease: false
85
+ version_requirements: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.6'
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: 1.6.8
33
93
  description:
34
94
  email:
35
95
  executables: []
@@ -42,7 +102,7 @@ files:
42
102
  - lib/confluence.rb
43
103
  - lib/page.rb
44
104
  - lib/storage_format.rb
45
- homepage: https://github.com/grmi64/confluence-rest-api
105
+ homepage: https://github.com/GM314/confluence-rest-api
46
106
  licenses:
47
107
  - MIT
48
108
  metadata: {}
@@ -61,8 +121,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
61
121
  - !ruby/object:Gem::Version
62
122
  version: '0'
63
123
  requirements: []
64
- rubyforge_project:
65
- rubygems_version: 2.7.6
124
+ rubygems_version: 3.1.3
66
125
  signing_key:
67
126
  specification_version: 4
68
127
  summary: Ruby REST API Client to create, update, and view pages