zulip 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/README.md +5 -8
- data/example/zulip_message_echo.rb +5 -3
- data/lib/zulip/client.rb +2 -2
- data/lib/zulip/client/queue_registration.rb +5 -0
- data/lib/zulip/version.rb +1 -1
- data/spec/lib/zulip/client/event_streaming_spec.rb +1 -1
- data/spec/lib/zulip/client/stream_subscriptions_spec.rb +1 -1
- data/spec/lib/zulip/client/users_spec.rb +1 -1
- data/spec/lib/zulip/client_spec.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1c26f1799992de53d2b0e4d3b949d48c5f483442
|
4
|
+
data.tar.gz: f7ab02ae72f18856b636c474c659cd86637580b1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dcb0d482d015f5700ff7655ef927614949a0c586bfc9cbf028fc39faa91dca2e08c9dde4c6d62ffa942065895c176c7c619a92618d97a91d460dc7f970c03cb3
|
7
|
+
data.tar.gz: 652a0ba97e0d108ce5e5358f50f89feb3df088e433f044d52390d410ae0f4b75914af2e10a7d4936acd7cc45202d714ab8fdc569dc76b387883516e2e7009165
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -6,7 +6,7 @@ A ruby interface to the Zulip API.
|
|
6
6
|
|
7
7
|
Add this line to your application's Gemfile:
|
8
8
|
|
9
|
-
`gem 'zulip
|
9
|
+
`gem 'zulip'`
|
10
10
|
|
11
11
|
And then execute:
|
12
12
|
|
@@ -17,20 +17,17 @@ Or install it yourself as:
|
|
17
17
|
`$ gem install zulip-rb`
|
18
18
|
|
19
19
|
### Configuration
|
20
|
-
You'll need to register a bot to use the Zulip API.
|
21
20
|
You can obtain your Zulip API key, create bots, and manage bots all
|
22
21
|
from your Zulip [settings page](https://zulip.com/#settings).
|
23
22
|
|
24
|
-
Set your api key and
|
23
|
+
Set your api key and email address by passing a block to your Zulip::Client instance:
|
25
24
|
```ruby
|
26
25
|
client = Zulip::Client.new do |config|
|
27
|
-
config.
|
26
|
+
config.email_address = "YOUR_EMAIL_ADDRESS"
|
28
27
|
config.api_key = "YOUR_API_KEY"
|
29
28
|
end
|
30
29
|
```
|
31
30
|
|
32
|
-
You'll need to subscribe your bot to streams you want to read from. Do so by adding your bot's email to the stream's membership from a zulip client, or use the #subscribe method (see example below).
|
33
|
-
|
34
31
|
### Usage
|
35
32
|
|
36
33
|
Send messages to a stream:
|
@@ -50,12 +47,12 @@ client.stream_messages do |message|
|
|
50
47
|
end
|
51
48
|
```
|
52
49
|
|
53
|
-
Get your
|
50
|
+
Get your current subscriptions:
|
54
51
|
```ruby
|
55
52
|
client.get_subscriptions
|
56
53
|
```
|
57
54
|
|
58
|
-
Subscribe
|
55
|
+
Subscribe to a stream, passing the stream name:
|
59
56
|
```ruby
|
60
57
|
client.subscribe "food"
|
61
58
|
```
|
@@ -7,12 +7,14 @@ class ZulipEcho
|
|
7
7
|
|
8
8
|
def run
|
9
9
|
client = Zulip::Client.new do |config|
|
10
|
-
config.
|
10
|
+
config.email_address = ENV['BOT_EMAIL_ADDRESS'] || "bot@example.com"
|
11
11
|
config.api_key = ENV['BOT_API_KEY'] || "apikey"
|
12
12
|
end
|
13
13
|
|
14
|
-
client.
|
15
|
-
|
14
|
+
client.stream_private_messages do |message|
|
15
|
+
if message.stream == "test-stream"
|
16
|
+
client.send_private_message(private_message_content(message), "example@gmail.com")
|
17
|
+
end
|
16
18
|
end
|
17
19
|
end
|
18
20
|
|
data/lib/zulip/client.rb
CHANGED
@@ -17,7 +17,7 @@ module Zulip
|
|
17
17
|
include Zulip::Client::EventStreaming
|
18
18
|
include Zulip::Client::EventParser
|
19
19
|
|
20
|
-
attr_accessor :
|
20
|
+
attr_accessor :email_address, :api_key
|
21
21
|
attr_writer :connection
|
22
22
|
ENDPOINT = "https://api.zulip.com"
|
23
23
|
|
@@ -33,7 +33,7 @@ module Zulip
|
|
33
33
|
|
34
34
|
def initialize_connection
|
35
35
|
conn = Faraday.new(url: ENDPOINT)
|
36
|
-
conn.basic_auth(
|
36
|
+
conn.basic_auth(email_address, api_key)
|
37
37
|
conn
|
38
38
|
end
|
39
39
|
|
@@ -1,6 +1,9 @@
|
|
1
1
|
module Zulip
|
2
2
|
class Client
|
3
3
|
module QueueRegistration
|
4
|
+
|
5
|
+
class InvalideEmailOrAPI < StandardError; end
|
6
|
+
|
4
7
|
EVENT_TYPES = { message: "message" }
|
5
8
|
# TODO: Add support for other event types
|
6
9
|
# TODO: Add support setting apply markdown to false
|
@@ -13,6 +16,8 @@ module Zulip
|
|
13
16
|
connection.params = { "event_types" => json_encode_list(event_types) }
|
14
17
|
end
|
15
18
|
|
19
|
+
raise InvalideEmailOrAPI if registration_response['result'] == "error"
|
20
|
+
|
16
21
|
QueueRegistrationResponse.new( registration_response['queue_id'],
|
17
22
|
registration_response['last_event_id'] )
|
18
23
|
end
|
data/lib/zulip/version.rb
CHANGED
@@ -17,7 +17,7 @@ module Zulip
|
|
17
17
|
let(:fake_queue) { double("fake queue", queue_id: "id", last_event_id: -1) }
|
18
18
|
|
19
19
|
describe "#stream_private_messages" do
|
20
|
-
it "returns private messages viewable to the
|
20
|
+
it "returns private messages viewable to the user" do
|
21
21
|
|
22
22
|
# Returns a public-message, then a private message
|
23
23
|
fake_response.stub(:body).and_return(public_message_fixture, private_message_fixture)
|
@@ -5,7 +5,7 @@ module Zulip
|
|
5
5
|
class Client
|
6
6
|
describe StreamSubscriptions do
|
7
7
|
describe "#get_subscriptions" do
|
8
|
-
it "returns the
|
8
|
+
it "returns the user's stream subscriptions" do
|
9
9
|
fake_http_response = double("fake http response",
|
10
10
|
body: fixture("get-user-subscriptions.json"))
|
11
11
|
fake_connection = double("fake connection", get: fake_http_response)
|
@@ -5,7 +5,7 @@ module Zulip
|
|
5
5
|
class Client
|
6
6
|
describe Users do
|
7
7
|
describe "get_users" do
|
8
|
-
it "returns
|
8
|
+
it "returns a list of users" do
|
9
9
|
|
10
10
|
fake_http_response = double("fake http response", body: fixture("get-users.json"))
|
11
11
|
fake_connection = double("fake connection", get: fake_http_response)
|
@@ -5,11 +5,11 @@ describe Zulip::Client do
|
|
5
5
|
it "yields itself upon initialization for configuration" do
|
6
6
|
|
7
7
|
client = Zulip::Client.new do |config|
|
8
|
-
config.
|
8
|
+
config.email_address = "bot@example.com"
|
9
9
|
config.api_key = "apikey"
|
10
10
|
end
|
11
11
|
|
12
|
-
expect(client.
|
12
|
+
expect(client.email_address).to eq "bot@example.com"
|
13
13
|
expect(client.api_key).to eq "apikey"
|
14
14
|
end
|
15
15
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zulip
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Vergeront
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-11-
|
11
|
+
date: 2013-11-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|