diff options
author | Kamil Trzcinski <ayufan@ayufan.eu> | 2016-12-20 00:22:10 +0100 |
---|---|---|
committer | Kamil Trzcinski <ayufan@ayufan.eu> | 2016-12-20 00:22:10 +0100 |
commit | 841960f847f04da9c427bcdb19037e2112a90890 (patch) | |
tree | ff485924db7614a01d5f3f52f66dd28056097ff8 /lib/mattermost/client.rb | |
parent | 34295036e2a9ecf18ca5440a5dd6dbb0c7f05643 (diff) | |
download | gitlab-ce-841960f847f04da9c427bcdb19037e2112a90890.tar.gz |
Fix flow
Diffstat (limited to 'lib/mattermost/client.rb')
-rw-r--r-- | lib/mattermost/client.rb | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/lib/mattermost/client.rb b/lib/mattermost/client.rb new file mode 100644 index 00000000000..2a0e4b400d3 --- /dev/null +++ b/lib/mattermost/client.rb @@ -0,0 +1,39 @@ +module Mattermost + class Client + attr_reader :user + + def initialize(user) + @user = user + end + + private + + def with_session(&blk) + Session.new(user).with_session(&blk) + end + + def json_get(path, options = {}) + with_session do |session| + json_response session.get(path, options) + end + end + + def json_post(path, options = {}) + with_session do |session| + json_response session.post(path, options) + end + end + + def json_response(response) + json_response = JSON.parse(response.body) + + if response.success? + json_response + elsif json_response['message'] + raise json_response['message'] + else + raise 'Undefined error' + end + end + end +end |