Skip to content

Instantly share code, notes, and snippets.

@diffshare
Last active May 19, 2018 14:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save diffshare/f7899c48dca9988942c14d7126cefd29 to your computer and use it in GitHub Desktop.
Save diffshare/f7899c48dca9988942c14d7126cefd29 to your computer and use it in GitHub Desktop.
replace-from-cybozu-to-redmine.rb
# $ rails r ./replace-from-cybozu-to-redmine.rb
#
# RailsのGemfileで以下が必要
# require "rest-client"
# require "oauth"
consumer_key = "" # cybozuliveの開発者登録
consumer_secret = ""
consumer = OAuth::Consumer.new(
consumer_key,
consumer_secret,
:site => "https://api.cybozulive.com",
:request_token_url => "https://api.cybozulive.com/oauth/initiate",
:access_token_url => "https://api.cybozulive.com/oauth/token"
)
x_auth_username = "" # 自分のID/PW
x_auth_password = ""
access_token = consumer.get_access_token(
nil,
{},
{
:x_auth_mode => "client_auth",
:x_auth_username => x_auth_username,
:x_auth_password => x_auth_password,
}
)
RestClient.add_before_execution_proc do |req, params|
access_token.sign! req
end
#p access_token
response = RestClient.get "https://api.cybozulive.com/api/group/V2"
group = Hash.from_xml(response.body).with_indifferent_access
id = group[:feed][:entry][:id][6..-1]
response = RestClient.get "https://api.cybozulive.com/api/board/V2?group=#{id}&max-results=100"
board_feed = Nokogiri.XML response
# 破壊的テストなので、よろしく
#Board.destroy_all
#Message.destroy_all
board = Project.first.boards.build
board.name = "サイボウズ"
board.description = "異色だよ"
board.save
board_feed.css("entry").each do |entry|
board_id = entry.at("id").text
id = board_id.split(":")[2]
message = board.messages.new
message.subject = entry.at(:title).text
message.content = entry.at(:summary).text
unless message.save
p message.errors.messages
raise :error
end
comment_response = RestClient.get "https://api.cybozulive.com/api/comment/V2?entry=#{board_id}&max-results=100"
comment_feed = Nokogiri.XML comment_response.body
comment_feed.css("entry").each do |comment|
reply = board.messages.new
reply.subject = "test"
reply.parent = message
reply.content = comment.at(:summary).text
reply.content = "test" if reply.content.blank?
next if reply.board.blank?
p reply
unless reply.save
p reply.errors.messages
raise :error
end
end
p board
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment