Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZ.J. van de Weg <git@zjvandeweg.nl>2016-12-19 16:14:09 +0300
committerZ.J. van de Weg <git@zjvandeweg.nl>2016-12-19 23:44:15 +0300
commitd21535602b30316646772b1cd74d7069254076df (patch)
treed5e7533b44d646e8aaee153ce7b0f51e9467faa7 /lib/mattermost
parent4213bd56dea1d6cdbfa8baed8faa7e3ab86e61ab (diff)
Minor adjustments API Mattermost
[ci skip]
Diffstat (limited to 'lib/mattermost')
-rw-r--r--lib/mattermost/command.rb17
-rw-r--r--lib/mattermost/session.rb4
-rw-r--r--lib/mattermost/team.rb20
3 files changed, 17 insertions, 24 deletions
diff --git a/lib/mattermost/command.rb b/lib/mattermost/command.rb
index 9c37d0b0d79..afbf2ce3349 100644
--- a/lib/mattermost/command.rb
+++ b/lib/mattermost/command.rb
@@ -1,14 +1,13 @@
module Mattermost
- class Command < Session
- def self.create(team_id, trigger: 'gitlab', url:, icon_url:)
+ class Command
+ def self.create(session, team_id, command)
+ response = session.post("/api/v3/teams/#{team_id}/commands/create", body: command.to_json).parsed_response
- post_command(command)['token']
- end
-
- private
-
- def post_command(command)
- post( "/teams/#{team_id}/commands/create", body: command.to_json).parsed_response
+ if response.has_key?('message')
+ response
+ else
+ response['token']
+ end
end
end
end
diff --git a/lib/mattermost/session.rb b/lib/mattermost/session.rb
index dcdff94814c..670f83bb6bc 100644
--- a/lib/mattermost/session.rb
+++ b/lib/mattermost/session.rb
@@ -30,6 +30,8 @@ module Mattermost
begin
yield self
+ rescue Errno::ECONNREFUSED
+ raise NoSessionError
ensure
destroy
end
@@ -112,4 +114,4 @@ module Mattermost
end
end
end
-end \ No newline at end of file
+end
diff --git a/lib/mattermost/team.rb b/lib/mattermost/team.rb
index 714748aea3c..c1b867629b6 100644
--- a/lib/mattermost/team.rb
+++ b/lib/mattermost/team.rb
@@ -1,21 +1,13 @@
module Mattermost
- class Team < Session
- def self.team_admin
- return [] unless initial_load['team_members']
+ class Team
+ def self.all(session)
+ response_body = retreive_teams(session)
- team_ids = initial_load['team_members'].map do |team|
- team['team_id'] if team['roles'].split.include?('team_admin')
- end.compact
-
- initial_load['teams'].select do |team|
- team_ids.include?(team['id'])
- end
+ response_body.has_key?('message') ? response_body : response_body.values
end
- private
-
- def initial_load
- @initial_load ||= get('/users/initial_load').parsed_response
+ def self.retreive_teams(session)
+ session.get('/api/v3/teams/all').parsed_response
end
end
end