Last active
August 29, 2015 14:01
-
-
Save DriftwoodJP/6302ca6e053150c9833e to your computer and use it in GitHub Desktop.
Backlog API に ruby スクリプトから接続する | http://www.d-wood.com/blog/2014/05/12_6190.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'xmlrpc/client' | |
require 'pp' | |
# | |
# Backlog の設定情報 | |
# | |
# Backlog URI のサーバー名 | |
SPACE = 'スペース名' | |
# 操作権限を持たせたログインアカウント | |
USER = 'ユーザー名' | |
PASSWORD = 'パスワード' | |
# 操作したいプロジェクトのプロジェクトキー | |
PROJECT_KEY = 'プロジェクトキー' | |
class BacklogClient | |
PATH = '/XML-RPC' | |
PORT = 443 | |
PROXY_HOST = nil | |
PROXY_PORT = nil | |
USE_SSL = true | |
TIMEOUT = 60 | |
def initialize(space, user, password) | |
@host = space + '.backlog.jp' | |
@user = user | |
@password = password | |
@client = XMLRPC::Client.new(@host, PATH, PORT, PROXY_HOST, PROXY_PORT, @user, @password, USE_SSL, TIMEOUT) | |
end | |
def call(method, args=nil) | |
if args | |
@client.call(method, args) | |
else | |
@client.call(method) | |
end | |
end | |
def get_project_id(project_key) | |
project_info = self.call('backlog.getProject', project_key) | |
project_info['id'].to_s | |
end | |
def get_project_info(project_key) | |
self.call('backlog.getProject', project_key) | |
end | |
def get_issues(project_id) | |
self.call('backlog.findIssue', {'projectId' => project_id}) | |
end | |
def get_comment(issue_id) | |
self.call('backlog.getComments', issue_id) | |
end | |
end | |
begin | |
# Create XML-RPC Client | |
client = BacklogClient.new(SPACE, USER, PASSWORD) | |
# get project_id | |
pp PROJECT_ID = client.get_project_id(PROJECT_KEY) | |
# get project_info | |
pp client.get_project_info(PROJECT_KEY) | |
# get issues & comments | |
issues = client.get_issues(PROJECT_ID) | |
issues.each do |issue| | |
puts "Issue #{issue['key']}" | |
pp issue | |
puts | |
pp client.get_comment(issue['id']) | |
puts | |
end | |
rescue => e | |
puts "Error: #{e.faultCode}: #{e.faultString}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment