Permalink
Browse files

advancing on confluence integration

  • Loading branch information...
1 parent 605e0b7 commit b510b6833b9f2f249f13be3e85444022fca7e62c Leonardo Campos committed Mar 15, 2012
Showing with 56 additions and 14 deletions.
  1. +1 −0 .gitignore
  2. +3 −0 config/confluence_account.yml.sample
  3. +0 −14 lib/scrum_board/confluence_cleint.rb
  4. +52 −0 lib/scrum_board/confluence_client.rb
View
@@ -5,6 +5,7 @@
# git config --global core.excludesfile ~/.gitignore_global
config/rally_account.yml
+config/confluence_account.yml
# Ignore bundler config
/.bundle
@@ -0,0 +1,3 @@
+test:
+ username: "codebasehq@abril.com.br"
+ password: "TEST"
@@ -1,14 +0,0 @@
-module ScrumBoard
- class ConfluenceClient
- def page_source(title, space='plataforma')
- title = title.gsub(/\+/, ' ')
- user = 'plataforma_alexandria'
- password = 'eu tambem nao sei'
-
- vendor_confluence_path = "#{::Rails.root}/vendor/atlassian-cli-2.5.0"
- command = "#{vendor_confluence_path}/confluence.sh --server=https://confluence.abril.com.br --user=#{user} --password='#{password}' --action=getSource --title='#{title}' --space='#{space}'"
-
- `#{command}`
- end
- end
-end
@@ -0,0 +1,52 @@
+module ScrumBoard
+ class ConfluenceClient
+ def page_source(title, space='plataforma')
+ title = title.gsub(/\+/, ' ')
+
+ call_confluence('getSource', :title => title)
+ end
+
+ #extras: parent, labels, replace, content2, findReplace, noConvert, encoding
+ def addPage(title, content, extras)
+ extras ||= {}
+
+ begin
+ file = write_tmp_file(content)
+ extras.merge! {:file => file.path}
+
+ call_confluence('addPage', extras)
+ ensure
+ file.close
+ file.unlink # deletes the temp file
+ end
+ end
+
+ private
+ def call_confluence(action, extras)
+ user = confluence_configuration[:username]
+ password = confluence_configuration[:password]
+
+ vendor_confluence_path = "#{::Rails.root}/vendor/atlassian-cli-2.5.0"
+ command = "#{vendor_confluence_path}/confluence.sh --server=https://confluence.abril.com.br --user=#{user} --password='#{password}' --space='plataforma' --action=#{action}"
+
+ extras ||= {}
+ extras.each_pair do |key, value|
+ command += " --#{key}='#{value}'"
+ end
+
+ `#{command}`
+ end
+
+ def write_tmp_file(content)
+ temp_file = Tempfile.new 'confluence-page', Rails.root.join('tmp')
+ temp_file.write(content)
+ file
+ end
+
+ private
+ def confluence_configuration
+ @confluence_configuration ||= ScrumBoard::Yml.read_from_config("confluence_account")
+ @confluence_configuration
+ end
+ end
+end

0 comments on commit b510b68

Please sign in to comment.