Class: CrowiClient
- Inherits:
-
Object
- Object
- CrowiClient
- Includes:
- Singleton
- Defined in:
- lib/crowi/client/client.rb
Overview
Crowi のクライアントクラス
Instance Method Summary collapse
-
#attachment(path_exp: nil, attachment_name: nil) ⇒ String
指定した添付ファイル情報を取得する.
-
#attachment_exist?(path_exp: nil, attachment_name: nil) ⇒ true/false
ページに添付ファイルが存在するか調べる.
-
#attachment_id(path_exp: nil, attachment_name: nil) ⇒ String
指定した添付ファイルのIDを取得する.
-
#initialize ⇒ CrowiClient
constructor
コンストラクタ(シングルトン).
-
#page_exist?(path_exp: nil) ⇒ true/false
ページが存在するか調べる.
-
#page_id(path_exp: nil) ⇒ String
ページIDを取得する.
-
#request(req) ⇒ String
APIリクエストを送信する.
Constructor Details
#initialize ⇒ CrowiClient
コンストラクタ(シングルトン)
15 16 17 18 19 |
# File 'lib/crowi/client/client.rb', line 15 def initialize raise ArgumentError, 'Config url is required.' unless EasySettings['url'] raise ArgumentError, 'Config token is required.' unless EasySettings['token'] @cp_entry_point = URI.join(EasySettings['url'], '/_api/').to_s end |
Instance Method Details
#attachment(path_exp: nil, attachment_name: nil) ⇒ String
指定した添付ファイル情報を取得する
65 66 67 68 |
# File 'lib/crowi/client/client.rb', line 65 def (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 == } end |
#attachment_exist?(path_exp: nil, attachment_name: nil) ⇒ true/false
ページに添付ファイルが存在するか調べる
49 50 51 52 |
# File 'lib/crowi/client/client.rb', line 49 def (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 == } != nil end |
#attachment_id(path_exp: nil, attachment_name: nil) ⇒ String
指定した添付ファイルのIDを取得する
57 58 59 60 |
# File 'lib/crowi/client/client.rb', line 57 def (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 == }&._id end |
#page_exist?(path_exp: nil) ⇒ true/false
ページが存在するか調べる
40 41 42 43 |
# File 'lib/crowi/client/client.rb', line 40 def page_exist?(path_exp: nil) ret = request(CPApiRequestPagesList.new path_exp: path_exp) return ret&.ok && ret&.data&.find { |p| p.path.match(path_exp) } != nil end |
#page_id(path_exp: nil) ⇒ String
ページIDを取得する
32 33 34 35 |
# File 'lib/crowi/client/client.rb', line 32 def page_id(path_exp: nil) ret = request(CPApiRequestPagesList.new path_exp: path_exp) return ret&.data&.find { |p| p.path.match(path_exp) != nil }&.id end |
#request(req) ⇒ String
APIリクエストを送信する
24 25 26 27 |
# File 'lib/crowi/client/client.rb', line 24 def request(req) req.param[:access_token] = EasySettings['token'] return req.execute URI.join(@cp_entry_point, req.entry_point).to_s end |