summaryrefslogtreecommitdiff
path: root/lib/mattermost/command.rb
blob: 5c6f5861a7f147ea6d28410517588c7183dfc426 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
module Mattermost
  class Command
    def self.create(session, params)
      response = session.post("/api/v3/teams/#{params[:team_id]}/commands/create",
        body: params.to_json)

      if response.success?
        response.parsed_response['token']
      elsif response.parsed_response.try(:has_key?, 'message')
        raise response.parsed_response['message']
      else
        raise 'Failed to create a new command'
      end
    end
  end
end