tarumi 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +4 -2
- data/lib/tarumi/bot.rb +21 -8
- data/lib/tarumi/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0f06eeaef8132a24e5164f9898ac80d64436284a
|
4
|
+
data.tar.gz: 76234f6d7348349ddc9f67a79fc7800a9760167d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8745178a3f021be520b34769023bc103e4aabe11b6bf94180ed60e3e4e076732014dc79517c3afc403a27a6c6b5f880c1acab4b136be77bea0c28e6cfa6298bb
|
7
|
+
data.tar.gz: 3d2afdccb5d311ddd3d7b64f56466d011812eec8bf8eb29f68523e10bd4e114de04523dd71710b138667e971f363ad6e9499c5c30076445b09c1bc7c29ac7449
|
data/README.md
CHANGED
@@ -58,7 +58,9 @@ The example above will post a message to the `#general` channel, but you can eas
|
|
58
58
|
options = {
|
59
59
|
username: "usernametopost",
|
60
60
|
channel: "#anotherchannel",
|
61
|
-
hook_name: "webhookname"
|
61
|
+
hook_name: "webhookname",
|
62
|
+
icon_url: "http://a_url_to_an_icon.com/icon.png",
|
63
|
+
icon_emoji: "http://a_url_to_an_emoji.com/emoji.png"
|
62
64
|
}
|
63
65
|
```
|
64
66
|
That should be it for you to easily configure the bot and start sending messages.
|
@@ -67,7 +69,7 @@ That should be it for you to easily configure the bot and start sending messages
|
|
67
69
|
|
68
70
|
## Contributing
|
69
71
|
|
70
|
-
1. Fork it ( http://github.com
|
72
|
+
1. Fork it ( http://github.com/IcaliaLabs/tarumi/fork )
|
71
73
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
72
74
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
73
75
|
4. Push to the branch (`git push origin my-new-feature`)
|
data/lib/tarumi/bot.rb
CHANGED
@@ -4,8 +4,8 @@ module Tarumi
|
|
4
4
|
class Bot
|
5
5
|
include HTTParty
|
6
6
|
|
7
|
-
attr_reader :
|
8
|
-
:
|
7
|
+
attr_reader :username, :channel, :hook_name,
|
8
|
+
:icon_emoji, :icon_url
|
9
9
|
|
10
10
|
# Add the default format to be json on each request
|
11
11
|
format :json
|
@@ -14,27 +14,40 @@ module Tarumi
|
|
14
14
|
disable_rails_query_string_format if defined?(Rails)
|
15
15
|
|
16
16
|
def initialize(team, token, options = {})
|
17
|
-
self.class.base_uri("https://#{team}.slack.com")
|
17
|
+
self.class.base_uri("https://#{team}.slack.com")
|
18
18
|
self.class.default_params(token: token) #we sent this token on each request
|
19
19
|
|
20
|
-
@username
|
21
|
-
@channel
|
22
|
-
@hook_name
|
20
|
+
@username = options[:username] || "webhookbot"
|
21
|
+
@channel = options[:channel] || "#general"
|
22
|
+
@hook_name = options[:hook_name] || "incoming-webhook"
|
23
|
+
@icon_url = options[:icon_url] || "https://slack.com/img/icons/app-57.png"
|
24
|
+
@icon_emoji = options[:icon_emoji]
|
23
25
|
|
24
26
|
raise ArgumentError, 'You need to specify a team' if team.blank?
|
25
27
|
raise ArgumentError, 'You need to specify the token, to get one go to https://yourteamname.slack.com/services/new' if token.blank?
|
26
28
|
end
|
27
29
|
|
28
30
|
def ping(text, options = {})
|
29
|
-
payload = {
|
31
|
+
payload = {
|
32
|
+
text: text,
|
33
|
+
channel: @channel,
|
34
|
+
username: @username
|
35
|
+
}.merge(icon).merge(options)
|
36
|
+
|
30
37
|
body = { body: "payload=#{payload.to_json}"}
|
31
38
|
|
32
|
-
response = self.class.post("/services/hooks/#{@hook_name}", body)
|
39
|
+
response = self.class.post("/services/hooks/#{@hook_name}", body)
|
33
40
|
|
34
41
|
raise ArgumentError, 'You need to specify a text' if text.blank?
|
35
42
|
|
36
43
|
"#{response.body} - #{response.code}"
|
37
44
|
end
|
38
45
|
|
46
|
+
private
|
47
|
+
|
48
|
+
def icon
|
49
|
+
@icon_emoji ? { icon_emoji: @icon_emoji } : { icon_url: @icon_url }
|
50
|
+
end
|
51
|
+
|
39
52
|
end
|
40
53
|
end
|
data/lib/tarumi/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tarumi
|
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
|
- Abraham Kuri
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-02-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -103,7 +103,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
103
103
|
version: '0'
|
104
104
|
requirements: []
|
105
105
|
rubyforge_project:
|
106
|
-
rubygems_version: 2.2
|
106
|
+
rubygems_version: 2.4.2
|
107
107
|
signing_key:
|
108
108
|
specification_version: 4
|
109
109
|
summary: A super simple library to interact with Slack webhooks
|