class CrowiClient
Crowi
のクライアントクラス
Public Class Methods
new(crowi_url: '', access_token: '', rest_client_param: {})
click to toggle source
コンストラクタ
# File lib/crowi/client/client.rb, line 13 def initialize(crowi_url: '', access_token: '', rest_client_param: {}) raise ArgumentError, 'Config `crowi_url` is required.' if crowi_url.empty? raise ArgumentError, 'Config `access_token` is required.' if access_token.empty? @crowi_url = crowi_url @access_token = access_token @rest_client_param = rest_client_param @cp_entry_point = URI.join(crowi_url, '/_api/').to_s end
Public Instance Methods
attachment(path_exp: nil, attachment_name: nil)
click to toggle source
指定した添付ファイル情報を取得する @param [String] path_exp ページパス(正規表現) @return [String] attachment's file name
# File lib/crowi/client/client.rb, line 68 def attachment(path_exp: nil, attachment_name: nil) ret = request(CPApiRequestAttachmentsList.new page_id: page_id(path_exp: path_exp)) return ret&.data&.find { |a| a.originalName == attachment_name } end
attachment_exist?(path_exp: nil, attachment_name: nil)
click to toggle source
ページに添付ファイルが存在するか調べる @param [String] path_exp ページパス(正規表現) @param [String] attachment_name 添付ファイル名 @return [true/false] 添付ファイルの存在
# File lib/crowi/client/client.rb, line 52 def attachment_exist?(path_exp: nil, attachment_name: nil) ret = request(CPApiRequestAttachmentsList.new page_id: page_id(path_exp: path_exp)) return ret&.ok && ret&.data&.find { |a| a.originalName == attachment_name } != nil end
attachment_id(path_exp: nil, attachment_name: nil)
click to toggle source
指定した添付ファイルのIDを取得する @param [String] path_exp ページパス(正規表現) @return [String] attachment's file name
# File lib/crowi/client/client.rb, line 60 def attachment_id(path_exp: nil, attachment_name: nil) ret = request(CPApiRequestAttachmentsList.new page_id: page_id(path_exp: path_exp)) return ret&.data&.find { |a| a.originalName == attachment_name }&._id end
page_exist?(path_exp: nil)
click to toggle source
ページが存在するか調べる @param [String] path ページパス @return [true/false] ページの存在
# File lib/crowi/client/client.rb, line 44 def page_exist?(path_exp: nil) return !page_id(path_exp: path_exp).nil? end
page_id(path_exp: nil)
click to toggle source
ページIDを取得する @param [String] path_exp ページパス @return [String] ページID
# File lib/crowi/client/client.rb, line 35 def page_id(path_exp: nil) ret = request(CPApiRequestPagesList.new path_exp: path_exp) return nil if (ret.kind_of? CPInvalidRequest || ret.data.nil?) return ret.data.find { |page| URI.unescape(page.path) == path_exp }&.id end
request(req)
click to toggle source
APIリクエストを送信する @param [ApiRequestBase] req APIリクエスト @return [String] APIリクエストの応答(JSON形式)
# File lib/crowi/client/client.rb, line 26 def request(req) req.param[:access_token] = @access_token return req.execute URI.join(@cp_entry_point, req.entry_point).to_s, rest_client_param: @rest_client_param end