mattermost-ruby 0.2 → 0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 25e25af58c2cddfaec9f104a01d2e175630536b0
4
- data.tar.gz: e630507758d67fc08881ca1d0ba1ef2dc3dcb44d
3
+ metadata.gz: e693b82aee767301a05202ab5dbe02ef370e2493
4
+ data.tar.gz: 51b17471e2cde352de3a467a54be8530ca2db3a6
5
5
  SHA512:
6
- metadata.gz: bef58638a0e26002b9e4f836bc337b9d25d0eed7e3702d1508af2532cd24e6d37466338945013c1586cf0cc826bbd14e8eb2cf1b2b0cfe17f603573755c2bc92
7
- data.tar.gz: 67a0da25a8eb63ca465353dca08e7dc1235a36346cc52224ba7b95d710c3b8fbeb3d34382484ff10126faebd155a5c941836a458808d26abf7d047e8432998dd
6
+ metadata.gz: 068aec5035d347c89b39ad67c770489642c1ced0a163bd69300bcee6822f2fe75d879c693558ea0db9607a36ea44cafeae21c2d040318dba9b278e6110fca5f2
7
+ data.tar.gz: 08b1872b4dc2b9a147a013936aea85210930ab3700dd37b7953885c2f0e128ba799dc754fc876ee4024efb36d2266a13466169249afa274cccf75cdf855ff220
data/README.md CHANGED
@@ -18,11 +18,19 @@ Or install it yourself as:
18
18
 
19
19
  $ gem install mattermost-ruby
20
20
 
21
+ ## Supported versions of Mattermost
22
+
23
+ Tested against v3. In the future I'll publish separate versions for those who don't upgrade. But I'm going to assume most of us do since this is an infant.
24
+
25
+ ## Setup
26
+
27
+ Because Mattermost doesn't provide an API user, Mattermost-Ruby uses a system admin account for its API calls.
28
+
21
29
  ## Configuration
22
30
 
23
31
  ```
24
32
  options = {:httparty => {:debug_output => $stdout} } # pass defaults to httparty
25
- Mattermost.connect("apiuser", "apipassword", "https://mattermost.example.com/api/v1", "default_team_name", options)
33
+ Mattermost.connect("apiuser", "apipassword", "https://mattermost.example.com/api/v3", "default_team_name", options)
26
34
 
27
35
  users = Mattermost::User.all
28
36
  users.last.class #User
@@ -2,6 +2,9 @@ module Mattermost
2
2
  class Channel < MattermostObject
3
3
 
4
4
  def self.new(attributes = {})
5
+ if attributes.empty?
6
+ return ::Channel.default_attributes
7
+ end
5
8
  ::Channel.new(attributes)
6
9
  end
7
10
 
@@ -7,8 +7,7 @@ module Mattermost
7
7
  # Return an object that matches a given attribute.
8
8
  # Return nil if no matches
9
9
  def self.find_by(opts = {})
10
- obj = all.select { |obj| obj.send(opts.keys.first) == opts.values.first }.first
11
- return obj
10
+ all.select { |obj| obj.send(opts.keys.first) == opts.values.first }.first
12
11
  end
13
12
 
14
13
  # Return the user that has an id of @param id
@@ -4,10 +4,15 @@ class Channel < Base
4
4
  defined?(self.id) ? update : create_channel
5
5
  end
6
6
 
7
+ def name
8
+ @name ||= self.display_name.gsub(" ", '-')
9
+ end
10
+
7
11
  # Delete a channel
8
12
  def delete
9
13
  Mattermost.post("/channels/#{self.id}/delete")
10
14
  end
15
+ alias_method :destroy, :delete
11
16
 
12
17
  # Get channel info
13
18
  def info
@@ -98,10 +103,15 @@ class Channel < Base
98
103
  {:display_name => String, :team_id => String, :type => Integer, :purpose => String}
99
104
  end
100
105
 
101
-
102
106
  protected
103
107
  def create_channel
104
- `curl '#{Mattermost.base_uri}/channels/create' -H 'Cookie: MMTOKEN=#{Mattermost.headers['Cookie'].split("=")[1]};' -H 'X-Requested-With: XMLHttpRequest' --data-binary '{"display_name":"#{self.display_name}","name":"#{self.display_name.gsub(" ", '-')}","team_id":"#{Mattermost.team.id}","purpose":"#{self.purpose}.","type":"#{self.type}"}' --compressed`
105
- end
106
-
108
+ Mattermost.post("/channels/create",
109
+ :body => {
110
+ :display_name => self.display_name,
111
+ :name => self.name,
112
+ :team_id => Mattermost::Team.id,
113
+ :purpose => self.purpose,
114
+ :type => self.type
115
+ }.to_json)
116
+ end
107
117
  end
@@ -1,3 +1,3 @@
1
1
  module Mattermost
2
- VERSION = "0.2"
2
+ VERSION = "0.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mattermost-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.2'
4
+ version: '0.3'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josh Brody
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-05-18 00:00:00.000000000 Z
11
+ date: 2016-05-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler