あるwikiデータをConfluenceに突っ込み直すことがあり、ある程度ページ操作だったり自動でできないかなとドキュメントを見ると、REST、XMLRPC、SOAPがサポートされているようだった。
今回はrubyでconfluence-clientというgemがあったのでそれを使って操作してみる。詳細なメッセージ仕様がなかなか見つからず何を渡せばよいのかちょっとわかりづらかった。どこかにまとまったドキュメントがあるのだろうか??
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 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# coding: utf-8 require 'confluence-client' require 'openssl' HOST = 'http://localhost:8090/rpc/xmlrpc' Confluence::Client.new(HOST) do |confluence| confluence.instance_eval { @confluence = @server.proxy('confluence2') } # Target space SPACE_KEY = 'MYSPACE' if confluence.login('id', 'password') raise confluence.error unless confluence.ok? # # If the space does not exist, create it. # space = confluence.get_space(SPACE_KEY) if space puts "#{space} alread exists" else if space = confluence.add_space(SPACE_KEY, 'myspace', 'test space') puts "#{space} created" else puts "failed to create #{space}" end end # # We store a page into the space. # page = confluence.getPage(SPACE_KEY, 'Test page') if page puts "page-#{page['id']} already exists" else page_struct = { :space => SPACE_KEY, :title => 'Test Page', :content => <<EOS <h2>Test page</h2> EOS } if page = confluence.storePage(page_struct) puts "a page-#{page['id']} has been created" else puts "failed to create a page" end end # Create a child page child_page = confluence.storePage({ :space => SPACE_KEY, :parentId => page['id'], :title => "Child page", :content => "This is a child page" }) if child_page puts "a child page-#{child_page['id']} created" else puts "failed to create a child page" end # # Add comment to a page # comment = confluence.addComment({ :pageId => page["id"], :title => "Comment title", :content => "test_comment" }) if comment puts "comment to page-#{page['id']} created" else puts "failed to add comment to page-#{page['id']}" end # # Add a blog entry # entry = confluence.storeBlogEntry({ :space => SPACE_KEY, :title => "Blog entry", :content => "This is a blog entry", }) if entry puts "entry-#{entry['id']} created" else puts "failed to create a entry" end end end |
参考
- https://docs.atlassian.com/atlassian-confluence/latest/index.html?com/atlassian/confluence/rpc/soap/ConfluenceSoapService.html
- https://developer.atlassian.com/display/CONFDEV/Confluence+XML-RPC+and+SOAP+APIs
- https://developer.atlassian.com/display/CONFDEV/Remote+Confluence+Methods
- https://github.com/blairc/confluence-client
コメント