Skip to content

Commit edf32c6

Browse files
committed
commit
0 parents  commit edf32c6

10 files changed

+873
-0
lines changed

Gemfile

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
source 'https://rubygems.org'
2+
3+
# Specify your gem's dependencies in ruby-rocketchat.gemspec
4+
gemspec

LICENSE.txt

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2016 int512
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.

README.md

+111
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
# Rocket.Chat REST API for Ruby
2+
3+
This is a gem for [Rocket.Chat](https://rocket.chat/).
4+
5+
## Installation
6+
7+
Add this line to your application's Gemfile:
8+
9+
```ruby
10+
gem 'rocketchat'
11+
```
12+
13+
And then execute:
14+
15+
$ bundle
16+
17+
Or install it yourself as:
18+
19+
$ gem install rocketchat
20+
21+
22+
## List of supported API
23+
24+
Currently this gem supports below APIs only. (And also supports API version 0.1 only.)
25+
26+
* /api/version
27+
* /api/login
28+
* /api/logout
29+
* /api/publicRooms
30+
* /api/room/:id/join
31+
* /api/room/:id/leave
32+
* /api/room/:id/send
33+
34+
35+
## Usage
36+
37+
To get Rocket.Chat version and API version:
38+
39+
```ruby
40+
require 'rocketchat'
41+
42+
rcs = RocketChat::Server.new("http://your.server.address/")
43+
version = rcs.version
44+
puts "Rocket.Chat version: #{version.rocketchat}"
45+
puts "API version: #{version.api}"
46+
```
47+
48+
To find public rooms:
49+
50+
```ruby
51+
require 'rocketchat'
52+
53+
rcs = RocketChat::Server.new("http://your.server.address/")
54+
rc = rcs.login("username", "password")
55+
rc.public_rooms.each do |room|
56+
puts "##{room.name}(#{room.id}): #{room.msgs}messages"
57+
end
58+
```
59+
60+
You can also use [] to open a specific room.
61+
62+
```ruby
63+
require 'rocketchat'
64+
65+
rcs = RocketChat::Server.new("http://your.server.address/")
66+
rc = rcs.login("username", "password")
67+
puts "#general has #{rc["general"].msgs} messages"
68+
```
69+
70+
To join or leave a room:
71+
72+
```ruby
73+
require 'rocketchat'
74+
75+
rcs = RocketChat::Server.new("http://your.server.address/")
76+
rc = rcs.login("username", "password")
77+
rc["dev"].join
78+
rc["dev"].leave
79+
```
80+
81+
To send a message:
82+
83+
```ruby
84+
require 'rocketchat'
85+
86+
rcs = RocketChat::Server.new("http://your.server.address/")
87+
rc = rcs.login("username", "password")
88+
rc["dev"].post("message")
89+
```
90+
91+
To logout from a server.
92+
93+
```ruby
94+
require 'rocketchat'
95+
96+
rcs = RocketChat::Server.new("http://your.server.address/")
97+
rc = rcs.login("username", "password")
98+
# ... join, leave, send a message, etc ...
99+
rc.logout
100+
```
101+
102+
103+
## Contributing
104+
105+
Bug reports and pull requests are welcome on GitHub at https://github.com/int2xx9/ruby-rocketchat.
106+
107+
108+
## License
109+
110+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
111+

Rakefile

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
require "bundler/gem_tasks"
2+
require "rspec/core/rake_task"
3+
4+
RSpec::Core::RakeTask.new(:spec)
5+
6+
task :default => :spec

bin/console

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env ruby
2+
3+
require "bundler/setup"
4+
require "rocketchat"
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

bin/setup

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
IFS=$'\n\t'
4+
set -vx
5+
6+
bundle install
7+
8+
# Do any other automated setup that you need to do here

0 commit comments

Comments
 (0)