Confluence Ruby API
At work, we use the most excellent Confluence wiki system by Atlassian for all of our shared documentation. We also use it for weekly status reports, which are based on a template that needs some minor changes each week before being created.
Creating these weekly pages for people to fill in used to be a manual process—copying the template to a new wiki document, then editing it to make some pre-defined changes (such as the date)—until I learned about a Ruby gem for the Confluence API. Now a small Ruby program run weekly does the work for me:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | #!/usr/bin/ruby require 'rubygems' require 'confluence4r' # Some variables specific for my Confluence setup url = 'https://your.confluence.wiki.com/' user = 'jamesbond' password = '007' wikispace = 'statusreports' template = 'Status for week ending YYYY-MM-DD' # Find the date of the next Friday friday = Date.today friday += 1 while friday.wday != 5 # Log in to Confluence and retrieve the template page server = Confluence::Wiki.new(url) server.login(user, password) page = server.getPage(space, template) # Create a new page based on the template, changing the # date placeholder with this Friday's date newpage = Hash.new newpage['space'] = space newpage['title'] = template.gsub(/YYYY-MM-DD/, friday.to_s) newpage['content'] = page['content'].gsub(/YYYY-MM-DD/, friday.to_s) newpage['parentId'] = page['parentId'] # Save the new page server.storePage(newpage) server.logout() |
Resources:
* Confluence by Atlassian
* confluence4r gem on github
* confluence4r documentation by Atlassian
One Comment to “Confluence Ruby API”
Leave a Reply
Question, how did you get this installed as a gem? I am having some trouble trying to do just that.