mattermost-api4-ruby 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +39 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/mattermost.rb +8 -0
- data/lib/mattermost/client.rb +44 -0
- data/lib/mattermost/endpoint.rb +51 -0
- data/lib/mattermost/endpoint/brand.rb +27 -0
- data/lib/mattermost/endpoint/channels.rb +118 -0
- data/lib/mattermost/endpoint/cluster.rb +12 -0
- data/lib/mattermost/endpoint/commands.rb +39 -0
- data/lib/mattermost/endpoint/compliance.rb +33 -0
- data/lib/mattermost/endpoint/data_retention.rb +12 -0
- data/lib/mattermost/endpoint/elasticsearch.rb +16 -0
- data/lib/mattermost/endpoint/emoji.rb +38 -0
- data/lib/mattermost/endpoint/files.rb +60 -0
- data/lib/mattermost/endpoint/jobs.rb +28 -0
- data/lib/mattermost/endpoint/ldap.rb +17 -0
- data/lib/mattermost/endpoint/oauth.rb +40 -0
- data/lib/mattermost/endpoint/open_graph.rb +9 -0
- data/lib/mattermost/endpoint/plugins.rb +33 -0
- data/lib/mattermost/endpoint/posts.rb +62 -0
- data/lib/mattermost/endpoint/preferences.rb +28 -0
- data/lib/mattermost/endpoint/reactions.rb +9 -0
- data/lib/mattermost/endpoint/saml.rb +43 -0
- data/lib/mattermost/endpoint/status.rb +20 -0
- data/lib/mattermost/endpoint/system.rb +80 -0
- data/lib/mattermost/endpoint/teams.rb +113 -0
- data/lib/mattermost/endpoint/users.rb +9 -0
- data/lib/mattermost/endpoint/webhooks.rb +60 -0
- data/lib/mattermost/request.rb +7 -0
- data/mattermost-api4-ruby.gemspec +26 -0
- metadata +137 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ae6ca1e3c233e6d6c953582635f23895b506cab8
|
4
|
+
data.tar.gz: d9e8fd4c84e5a4bd54884e7084bd7f0e0f83d7dc
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3e130e395c64901f8d7d99b39abb882db95b6baa45c3aaddd6fa9d64f0958053ac97fc9c62214aebc9a5908146b615417997aa0399fa24554bd0cae91ee0ea06
|
7
|
+
data.tar.gz: a0a16200c978cf328be7c5d9a5cdc172aabf23ff9c2915a5ae1f893d893ddf3648f28f0e5bedaa3b100f16889f4eeb380cef9eed89cdaec6b877d66ebcb20b15
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Takayuki Maruyama
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# mattermost-api4-ruby
|
2
|
+
|
3
|
+
Mattermost API v4 client for ruby
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'mattermost-api4-ruby'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install mattermost-api4-ruby
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
TODO: Write usage instructions here
|
24
|
+
|
25
|
+
## Development
|
26
|
+
|
27
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
28
|
+
|
29
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
30
|
+
|
31
|
+
## Contributing
|
32
|
+
|
33
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/maruTA-bis5/mattermost-api4-ruby.
|
34
|
+
|
35
|
+
|
36
|
+
## License
|
37
|
+
|
38
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
39
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "mattermost-api4"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/lib/mattermost.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
require_relative 'endpoint'
|
3
|
+
require_relative 'request'
|
4
|
+
|
5
|
+
module Mattermost
|
6
|
+
|
7
|
+
class Client
|
8
|
+
import Mattermost::Endpoint
|
9
|
+
import Mattermost::Request
|
10
|
+
|
11
|
+
attr_accessor :server, :token
|
12
|
+
|
13
|
+
def initialize(server)
|
14
|
+
self.server = server
|
15
|
+
self.base_uri = "#{server}/api/v4"
|
16
|
+
end
|
17
|
+
|
18
|
+
def login(username, password)
|
19
|
+
login_request = post('/users/login', :body => {:login_id => uername, :password => password}.to_json)
|
20
|
+
self.token = login_request.headers['token']
|
21
|
+
update_token
|
22
|
+
end
|
23
|
+
|
24
|
+
def logout
|
25
|
+
self.token = nil
|
26
|
+
update_token
|
27
|
+
end
|
28
|
+
|
29
|
+
def use_access_token(token)
|
30
|
+
self.token = token
|
31
|
+
update_token
|
32
|
+
end
|
33
|
+
|
34
|
+
def connected?
|
35
|
+
getMe().success?
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def update_token
|
41
|
+
self.headers "Authorization: Bearer #{token}"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require_relative 'endpoint/brand'
|
2
|
+
require_relative 'endpoint/channels'
|
3
|
+
require_relative 'endpoint/cluster'
|
4
|
+
require_relative 'endpoint/commands'
|
5
|
+
require_relative 'endpoint/compliance'
|
6
|
+
require_relative 'endpoint/data_retention'
|
7
|
+
require_relative 'endpoint/elasticsearch'
|
8
|
+
require_relative 'endpoint/emoji'
|
9
|
+
require_relative 'endpoint/files'
|
10
|
+
require_relative 'endpoint/jobs'
|
11
|
+
require_relative 'endpoint/ldap'
|
12
|
+
require_relative 'endpoint/oauth'
|
13
|
+
require_relative 'endpoint/open_graph'
|
14
|
+
require_relative 'endpoint/plugins'
|
15
|
+
require_relative 'endpoint/posts'
|
16
|
+
require_relative 'endpoint/preferences'
|
17
|
+
require_relative 'endpoint/reactions'
|
18
|
+
require_relative 'endpoint/saml'
|
19
|
+
require_relative 'endpoint/status'
|
20
|
+
require_relative 'endpoint/system'
|
21
|
+
require_relative 'endpoint/teams'
|
22
|
+
require_relative 'endpoint/users'
|
23
|
+
require_relative 'endpoint/webhooks'
|
24
|
+
|
25
|
+
module Mattermost
|
26
|
+
module Endpoint
|
27
|
+
include Brand
|
28
|
+
include Channels
|
29
|
+
include Cluster
|
30
|
+
include Commands
|
31
|
+
include Compliance
|
32
|
+
include DataRetention
|
33
|
+
include Elasticsearch
|
34
|
+
include Emoji
|
35
|
+
include Files
|
36
|
+
include Jobs
|
37
|
+
include LDAP
|
38
|
+
include OAuth
|
39
|
+
include OpenGraph
|
40
|
+
include Plugins
|
41
|
+
include Posts
|
42
|
+
include Preferences
|
43
|
+
include Reactions
|
44
|
+
include SAML
|
45
|
+
include Status
|
46
|
+
include System
|
47
|
+
include Teams
|
48
|
+
include Users
|
49
|
+
include Webhooks
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module Mattermost
|
4
|
+
module Endpoint
|
5
|
+
module Brand
|
6
|
+
|
7
|
+
def get_brand_image(file_name)
|
8
|
+
File.open(file_name, "w") do |file|
|
9
|
+
file.binmode
|
10
|
+
get(get_brand_image_url(), stream_body: true) do |fragment|
|
11
|
+
file.write(fragment)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def get_brand_image_url
|
17
|
+
"/brand/image"
|
18
|
+
end
|
19
|
+
|
20
|
+
def upload_brand_image(image_file)
|
21
|
+
#post("/brand/image", image_file)
|
22
|
+
raise NotImplementedError
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,118 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module Mattermost
|
4
|
+
module Endpoint
|
5
|
+
module Channels
|
6
|
+
def create_channel(channel = {})
|
7
|
+
post("/channels", :body => channels.to_json)
|
8
|
+
end
|
9
|
+
|
10
|
+
def create_direct_channel(user_id_1, user_id_2)
|
11
|
+
post("/channels/direct", :body => JSON.generate([user_id_1, user_id_2]))
|
12
|
+
end
|
13
|
+
|
14
|
+
def create_group_message(user_ids = [])
|
15
|
+
post("/channels/group", :body => JSON.generate(user_ids))
|
16
|
+
end
|
17
|
+
|
18
|
+
def get_channel_list_by_ids(team_id, channel_ids = [])
|
19
|
+
post("/teams/#{team_id}/channels/ids", :body => JSON.generate(channel_ids))
|
20
|
+
end
|
21
|
+
|
22
|
+
def get_channel(channel_id)
|
23
|
+
get("/channels/#{channel_id}")
|
24
|
+
end
|
25
|
+
|
26
|
+
def update_channel(channel_id, channel = {})
|
27
|
+
put("/channels/#{channel_id}", channel.to_json)
|
28
|
+
end
|
29
|
+
|
30
|
+
def delete_channel(channel_id)
|
31
|
+
delete("/channels/#{channel_id}")
|
32
|
+
end
|
33
|
+
|
34
|
+
def patch_channel(channel_id, patch = {})
|
35
|
+
put("/channels/#{channel_id}/patch", patch.to_json)
|
36
|
+
end
|
37
|
+
|
38
|
+
def restore_channel(channel_id)
|
39
|
+
post("/channels/#{channel_id}/restore")
|
40
|
+
end
|
41
|
+
|
42
|
+
def get_channel_stats(channel_id)
|
43
|
+
get("/channels/#{channel_id}/stats")
|
44
|
+
end
|
45
|
+
|
46
|
+
def get_pinned_posts(channel_id)
|
47
|
+
get("/channels/#{channel_id}/pinned")
|
48
|
+
end
|
49
|
+
|
50
|
+
def get_public_channels(team_id, max = 60)
|
51
|
+
get("/teams/#{team_id}/channels?per_page=#{max}")
|
52
|
+
end
|
53
|
+
|
54
|
+
def get_deleted_channels(team_id, max = 60)
|
55
|
+
get("/teams/#{team_id}/channels/deleted?per_page=#{max}")
|
56
|
+
end
|
57
|
+
|
58
|
+
def search_channels(team_id, term)
|
59
|
+
post("/teams/#{team_id}/channels/search", :body => {:term => term}.to_json)
|
60
|
+
end
|
61
|
+
|
62
|
+
def get_channel_by_name(team_id, channel_name)
|
63
|
+
get("/teams/#{team_id}/channels/name/#{channel_name}")
|
64
|
+
end
|
65
|
+
|
66
|
+
def get_channel_by_name_and_team_name(team_name, channel_name)
|
67
|
+
get("/teams/name/#{team_name}/channels/name/#{channel_name}")
|
68
|
+
end
|
69
|
+
|
70
|
+
def get_channel_members(channel_id, max = 60)
|
71
|
+
get("/channels/#{channel_id}/members?per_page=#{max}")
|
72
|
+
end
|
73
|
+
|
74
|
+
def add_user_to_channel(channel_id, user_id)
|
75
|
+
post("/channels/#{channel_id}/members", :body => {:user_id => user_id}.to_json)
|
76
|
+
end
|
77
|
+
|
78
|
+
def get_channel_members_by_ids(channel_id, user_ids = [])
|
79
|
+
post("/channels/#{channel_id}/members/ids", :body => JSON.generate(user_ids))
|
80
|
+
end
|
81
|
+
|
82
|
+
def get_channel_member(channel_id, user_id)
|
83
|
+
get("/channels/#{channel_id}/members/#{user_id}")
|
84
|
+
end
|
85
|
+
|
86
|
+
def remove_user_from_channel(channel_id, user_id)
|
87
|
+
delete("/channels/#{channel_id}/members/#{user_id}")
|
88
|
+
end
|
89
|
+
|
90
|
+
def update_channel_roles(channel_id, user_id, roles)
|
91
|
+
put("/channels/#{channel_id}/members/#{user_id}/roles", :body => {:roles => roles}.to_json)
|
92
|
+
end
|
93
|
+
|
94
|
+
def update_channel_notifications(channel_id, user_id, notify_props = {})
|
95
|
+
put("/channels/#{channel_id}/members/#{user_id}/notify_props", notify_props.to_json)
|
96
|
+
end
|
97
|
+
|
98
|
+
def view_channel(user_id, channel_id, prev_channel_id)
|
99
|
+
post("/channels/members/#{user_id}/view", :body => {
|
100
|
+
:channel_id => channel_id,
|
101
|
+
:prev_channel_id => prev_channel_id
|
102
|
+
}.to_json)
|
103
|
+
end
|
104
|
+
|
105
|
+
def get_channel_members_for_user(user_id, team_id)
|
106
|
+
get("/users/#{user_id}/teams/#{team_id}/channels/members")
|
107
|
+
end
|
108
|
+
|
109
|
+
def get_channels_for_user(user_id, team_id)
|
110
|
+
get("/users/#{user_id}/teams/#{team_id}/channels")
|
111
|
+
end
|
112
|
+
|
113
|
+
def get_unread_messages(user_id, channel_id)
|
114
|
+
get("/users/#{user_id}/channels/#{channel_id}/unread")
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module Mattermost
|
4
|
+
module Endpoint
|
5
|
+
module Commands
|
6
|
+
|
7
|
+
def create_command(command)
|
8
|
+
post("/commands", :body => command.to_json)
|
9
|
+
end
|
10
|
+
|
11
|
+
def list_commands(team_id, custom_only = false)
|
12
|
+
get("/commands?team_id=#{team_id}&custom_only#{custom_only}")
|
13
|
+
end
|
14
|
+
|
15
|
+
def list_autocomplete_commands(team_id)
|
16
|
+
get("/teams/#{team_id}/commands/autocomplete")
|
17
|
+
end
|
18
|
+
|
19
|
+
def update_command(command_id, command)
|
20
|
+
put("/commands/#{command_id}", :body => command.to_json)
|
21
|
+
end
|
22
|
+
|
23
|
+
def delete_command(command_id)
|
24
|
+
delete("/commands/#{command_id}")
|
25
|
+
end
|
26
|
+
|
27
|
+
def regenerate_command_token(command_id)
|
28
|
+
put("/commands/#{command_id}/regen_token")
|
29
|
+
end
|
30
|
+
|
31
|
+
def execute_command(channel_id, command)
|
32
|
+
post("/commands/execute", :body => {
|
33
|
+
:channel_id => channel_id,
|
34
|
+
:command => command
|
35
|
+
}.to_json)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module Mattermost
|
4
|
+
module Endpoint
|
5
|
+
module Compliance
|
6
|
+
|
7
|
+
def create_compliance_report
|
8
|
+
post("/compliance/reports")
|
9
|
+
end
|
10
|
+
|
11
|
+
def get_compliance_reports(max = 60)
|
12
|
+
get("/compliance/reports?per_page=#{max}")
|
13
|
+
end
|
14
|
+
|
15
|
+
def get_compliance_report(report_id)
|
16
|
+
get("/compliance/reports/#{report_id}")
|
17
|
+
end
|
18
|
+
|
19
|
+
def download_compliance_report(report_id, file_name)
|
20
|
+
File.open(file_name, "w") do |file|
|
21
|
+
file.binmode
|
22
|
+
get(download_compliance_report_url(report_id), stream_body: true) do |fragment|
|
23
|
+
file.write(fragment)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def download_compliance_report_url(report_id)
|
29
|
+
"/compliance/reports/#{report_id}/download"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|