ruboty-zulip 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e22f0268de713154d9243b4da1153d24583fd9a8
4
+ data.tar.gz: fd290c99d242c3f20e1c8b655b2fc3bf648863d2
5
+ SHA512:
6
+ metadata.gz: db221cae724c9afecd2e54f1c50022e0193a3768e069f4067d9940ecbec7f78b32d4824c8d031f9096152c577f32073849a1bf0154218a9c3f897c665831ef80
7
+ data.tar.gz: b304f146414cefcfe370a10951e4cbaa0e53a7925aeecf5c7145a05a4ca6cde2b8ae9075f06dba87bceb23c0cd390cd6d2e64ea89d531ad41ae200334de869d6
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ruboty-zulip.gemspec
4
+ gemspec
5
+
6
+ gem "zulip-client", path: "../zulip-client"
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 okkez
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
+ # Ruboty::Zulip
2
+
3
+ [Zulip](https://zulip.org) adapter for [Ruboty](https://github.com/r7kamura/ruboty).
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'ruboty-zulip'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install ruboty-zulip
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. 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/okkez/ruboty-zulip.
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
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task default: :test
@@ -0,0 +1,77 @@
1
+ require "zulip/client"
2
+
3
+ module Ruboty
4
+ module Adapters
5
+ class Zulip < Base
6
+
7
+ env :ZULIP_SITE, "Zulip site URL"
8
+ env :ZULIP_USERNAME, "Zulip username (email address)"
9
+ env :ZULIP_API_KEY, "Zulip API key"
10
+ env :ZULIP_STREAM, "Zulip stream name to monitor", optional: true
11
+ env :ZULIP_TOPIC, "Zulip topic name to monitor", optional: true
12
+
13
+ def run
14
+ listen
15
+ end
16
+
17
+ def say(message)
18
+ message_type = message.dig(:original, :type).to_sym
19
+ client.send_message(
20
+ type: message_type,
21
+ to: message.dig(:original, :to),
22
+ subject: message.dig(:original, :subject),
23
+ content: message[:body]
24
+ )
25
+ end
26
+
27
+ private
28
+
29
+ def client
30
+ @client ||= ::Zulip::Client.new(site: site, username: username, api_key: api_key)
31
+ end
32
+
33
+ def site
34
+ ENV["ZULIP_SITE"]
35
+ end
36
+
37
+ def username
38
+ ENV["ZULIP_USERNAME"]
39
+ end
40
+
41
+ def api_key
42
+ ENV["ZULIP_API_KEY"]
43
+ end
44
+
45
+ def stream_name
46
+ ENV["ZULIP_STREAM"]
47
+ end
48
+
49
+ def topic
50
+ ENV["ZULIP_TOPIC"]
51
+ end
52
+
53
+ def listen
54
+ client.stream_message do |message|
55
+ message[:body] = message[:content]
56
+ robot.receive(
57
+ body: message[:content],
58
+ from: message[:sender_email],
59
+ from_name: message[:sender_full_name],
60
+ to: display_recipient(message),
61
+ type: message[:type],
62
+ subject: message[:subject],
63
+ )
64
+ end
65
+ end
66
+
67
+ def display_recipient(message)
68
+ case message[:type].to_sym
69
+ when :stream
70
+ message[:display_recipient]
71
+ when :private
72
+ message[:display_recipient].map {|recipient| recipient[:email] }
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,5 @@
1
+ module Ruboty
2
+ module Zulip
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,8 @@
1
+ require "ruboty/zulip/version"
2
+
3
+ module Ruboty
4
+ module Zulip
5
+ end
6
+ end
7
+
8
+ require "ruboty/adapters/zulip"
@@ -0,0 +1,27 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'ruboty/zulip/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "ruboty-zulip"
7
+ spec.version = Ruboty::Zulip::VERSION
8
+ spec.authors = ["okkez"]
9
+ spec.email = ["okkez000@gmail.com"]
10
+
11
+ spec.summary = "Zulip adapter for Ruboty."
12
+ spec.description = "Zulip adapter for Ruboty."
13
+ spec.homepage = "https://github.com/okkez/ruboty-zulip"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_dependency "ruboty", ">= 1.3.0"
24
+ spec.add_dependency "zulip-client"
25
+ spec.add_development_dependency "bundler", "~> 1.14"
26
+ spec.add_development_dependency "rake", "~> 12.0"
27
+ end
metadata ADDED
@@ -0,0 +1,109 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruboty-zulip
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - okkez
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-04-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: ruboty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 1.3.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 1.3.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: zulip-client
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.14'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.14'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '12.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '12.0'
69
+ description: Zulip adapter for Ruboty.
70
+ email:
71
+ - okkez000@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - Gemfile
78
+ - LICENSE.txt
79
+ - README.md
80
+ - Rakefile
81
+ - lib/ruboty/adapters/zulip.rb
82
+ - lib/ruboty/zulip.rb
83
+ - lib/ruboty/zulip/version.rb
84
+ - ruboty-zulip.gemspec
85
+ homepage: https://github.com/okkez/ruboty-zulip
86
+ licenses:
87
+ - MIT
88
+ metadata: {}
89
+ post_install_message:
90
+ rdoc_options: []
91
+ require_paths:
92
+ - lib
93
+ required_ruby_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ required_rubygems_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ requirements: []
104
+ rubyforge_project:
105
+ rubygems_version: 2.6.11
106
+ signing_key:
107
+ specification_version: 4
108
+ summary: Zulip adapter for Ruboty.
109
+ test_files: []