Skip to content

Commit

Permalink
Merge pull request #4 from ryu-sato/imprv/update-for-growi-v3_3
Browse files Browse the repository at this point in the history
Imprv/update for growi v3 3
  • Loading branch information
ryu-sato authored Jan 1, 2019
2 parents 71a89b0 + 213cf20 commit ec7c419
Show file tree
Hide file tree
Showing 13 changed files with 341 additions and 193 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ growi-client is passed the test of these Growi versions.

|growi-client|Growi|
| --- | --- |
|1.0.0|3.3.3|
|0.9.0|3.1.12|

## Installation
Expand Down Expand Up @@ -219,3 +220,7 @@ The gem is available as open source under the terms of the [MIT License](http://
## Code of Conduct

Everyone interacting in the Growi::Client project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/ryu-satgrowiwi-client/blob/master/CODE_OF_CONDUCT.md).

## TODO

- [ ] pagenation に対応する
18 changes: 9 additions & 9 deletions lib/growi/client/apireq/api_request_attachments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def execute(entry_point, rest_client_param: {})
params = { method: :get, url: entry_point, headers: { params: @param } }.merge(rest_client_param)
ret = JSON.parse RestClient::Request.execute params
if (ret['ok'] == false)
return CPInvalidRequest.new "API return false with msg: #{ret['msg']}"
return GCInvalidRequest.new "API return false with msg: #{ret['msg']}"
end
attachments = []
ret['attachments'].each do |attachment|
Expand All @@ -35,10 +35,10 @@ def execute(entry_point, rest_client_param: {})
protected

# バリデーションエラーを取得する
# @return [nil/CPInvalidRequest] バリデーションエラー結果
# @return [nil/GCInvalidRequest] バリデーションエラー結果
def _invalid
if ! (@param[:page_id])
CPInvalidRequest.new 'Parameter page_id is required.'
GCInvalidRequest.new 'Parameter page_id is required.'
end
end

Expand Down Expand Up @@ -76,18 +76,18 @@ def execute(entry_point, rest_client_param: {})
}.merge(rest_client_param)
ret = JSON.parse RestClient::Request.execute params
if (ret['ok'] == false)
return CPInvalidRequest.new "API return false with msg: #{ret['msg']}"
return GCInvalidRequest.new "API return false with msg: #{ret['msg']}"
end
return GApiReturn.new(ok: ret['ok'], data: GrowiPage.new(ret['page']))
end

protected

# バリデーションエラーを取得する
# @return [nil/CPInvalidRequest] バリデーションエラー結果
# @return [nil/GCInvalidRequest] バリデーションエラー結果
def _invalid
if ! (@param[:file] && @param[:page_id])
CPInvalidRequest.new 'Parameters file and page_id are required.'
GCInvalidRequest.new 'Parameters file and page_id are required.'
end
end

Expand Down Expand Up @@ -121,18 +121,18 @@ def execute(entry_point, rest_client_param: {})
}.merge(rest_client_param)
ret = JSON.parse RestClient::Request.execute params
if (ret['ok'] == false)
return CPInvalidRequest.new "API return false with msg: #{ret['msg']}"
return GCInvalidRequest.new "API return false with msg: #{ret['msg']}"
end
return GApiReturn.new(ok: ret['ok'], data: nil)
end

protected

# バリデーションエラーを取得する
# @return [nil/CPInvalidRequest] バリデーションエラー結果
# @return [nil/GCInvalidRequest] バリデーションエラー結果
def _invalid
if ! (@param[:attachment_id])
CPInvalidRequest.new 'Parameter attachment_id is required.'
GCInvalidRequest.new 'Parameter attachment_id is required.'
end
end

Expand Down
9 changes: 5 additions & 4 deletions lib/growi/client/apireq/api_request_base.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# APIリクエストのバリデーションエラー
# @note rescue する必要はないので Exception クラスは継承しない
class CPInvalidRequest
attr_reader :msg
class GCInvalidRequest
attr_reader :ok, :msg

# コンストラクタ
# @param [String] msg エラーメッセージ(原因と対策が分かるとよい)
def initialize(msg)
@ok = false
@msg = msg
end

Expand Down Expand Up @@ -97,9 +98,9 @@ def execute(entry_point, rest_client_param: {})
protected

# バリデーションエラーを取得する
# @return [nil/CPInvalidRequest] バリデーションエラー結果
# @return [nil/GCInvalidRequest] バリデーションエラー結果
def _invalid
return CPInvalidRequest "Invalid API request.";
return GCInvalidRequest "Invalid API request.";
end

end
Expand Down
Loading

0 comments on commit ec7c419

Please sign in to comment.