slackbotsy 0.0.8 → 0.1.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7ec8e606f409b90614e9919d98281ecd3d0201c9
4
- data.tar.gz: ac463292ad660a4299d29e8c01081e871897ad52
3
+ metadata.gz: efaf22afe32e29bb0cfac385bcc9333c055ab4bc
4
+ data.tar.gz: 37f4cc88d4eb8dcac0650a57c1e0355fc4f096d0
5
5
  SHA512:
6
- metadata.gz: 044072463462a5d5933abe0f33e7471a73e85774750579df1d44028cbc4bf7a7ecee113002ca2b8fd1ea88b62f51a9ab30381a01930900a8910d3a480825c592
7
- data.tar.gz: df970d1c61fb5b57e99d60ce8143cc84f445c36b7e27ae0aeb32f53a704ddec1124960b1a866e7babb40476824d5377cf6ae4edc6d3b1fbc7cc7e85ef952e31e
6
+ metadata.gz: f35c27cdd50c04f7a24a43a17ce7f57bcab1124673dbae7b44a2ad05ca09fde25d0f7be043496c18303849a514d8289376a6589fb0dc97e0ce301a891e16c99e
7
+ data.tar.gz: 95ce12f01ea5921415a781a91a7bc89b5a41cb5f35f3524783d72c8fff233ffb74cb9fa23f3a35398c931aa526caf25bbed27c9ca1d1cce8098dabbb5df2057e
@@ -13,7 +13,6 @@ module Slackbotsy
13
13
 
14
14
  ## use set of tokens for (more or less) O(1) lookup on multiple channels
15
15
  @options['outgoing_token'] = Array(@options['outgoing_token']).to_set
16
-
17
16
  @regexes = {}
18
17
  setup_incoming_webhook # http connection for async replies
19
18
  yield if block_given? # run any hear statements in block
@@ -27,28 +26,28 @@ module Slackbotsy
27
26
  @http.verify_mode = OpenSSL::SSL::VERIFY_PEER
28
27
  end
29
28
 
30
- ## format to send text to incoming webhook
31
- def encode_payload(text, options = {})
29
+ ## raw post of hash to slack
30
+ def post(options)
32
31
  payload = {
33
- text: text,
34
32
  username: @options['name'],
35
- channel: @options['channel'].gsub(/^#?/, '#'), # ensure channel begins with #
33
+ channel: @options['channel']
36
34
  }.merge(options)
37
-
38
- "payload=#{payload.to_json.to_s}"
35
+ payload[:channel] = payload[:channel].gsub(/^#?/, '#') #slack api needs leading # on channel
36
+ request = Net::HTTP::Post.new(@uri.request_uri)
37
+ request.set_form_data(payload: payload.to_json)
38
+ @http.request(request)
39
+ return nil # so as not to trigger text in outgoing webhook reply
39
40
  end
40
41
 
41
- ## send text to slack using incoming webhook
42
+ ## simple wrapper on post to send text
42
43
  def say(text, options = {})
43
- request = Net::HTTP::Post.new(@uri.request_uri)
44
- request.body = encode_payload(text, options)
45
- response = @http.request(request)
46
- return nil # so as not to trigger text in outgoing webhook reply
44
+ post({ text: text }.merge(options))
47
45
  end
48
46
 
49
- def attach(text, attachment, options = {})
50
- options = { attachments: [ attachment ] }.merge(options)
51
- say(text, options)
47
+ ## simple wrapper on post to send attachment(s)
48
+ def attach(ary, options = {})
49
+ attachments = ary.is_a?(Array) ? ary : [ ary ] #force first arg to array
50
+ post({ attachments: attachments }.merge(options))
52
51
  end
53
52
 
54
53
  ## add regex to things to hear
@@ -62,7 +61,7 @@ module Slackbotsy
62
61
  self.instance_eval File.open(file).read
63
62
  end
64
63
  end
65
-
64
+
66
65
  ## check message and run blocks for any matches
67
66
  def handle_item(msg)
68
67
  return nil unless @options['outgoing_token'].include? msg[:token] # ensure messages are for us from slack
@@ -2,7 +2,7 @@ module Slackbotsy
2
2
 
3
3
  class Message < Hash
4
4
  include Helper # mixin client helper methods
5
-
5
+
6
6
  ## convert message from a Hash obj to a Message obj
7
7
  def initialize(caller, msg)
8
8
  super()
@@ -10,10 +10,20 @@ module Slackbotsy
10
10
  @caller = caller # bot object
11
11
  end
12
12
 
13
- ## call say without bot object
13
+ ## convenience wrapper in message scope, so we can call it without @caller
14
+ ## and set default channel to same as received message
15
+ def post(options)
16
+ @caller.post({ channel: self['channel_name'] }.merge(options))
17
+ end
18
+
19
+ ## ditto
14
20
  def say(text, options = {})
15
- options[:channel] ||= self['channel_name'] # default to same channel as msg
16
- @caller.say(text, options)
21
+ @caller.say(text, { channel: self['channel_name'] }.merge(options))
22
+ end
23
+
24
+ ## ditto
25
+ def attach(attachments, options = {})
26
+ @caller.attach(attachments, { channel: self['channel_name'] }.merge(options))
17
27
  end
18
28
 
19
29
  ## convenience getter methods for message properties
@@ -22,7 +32,7 @@ module Slackbotsy
22
32
  self.fetch(method, nil)
23
33
  end
24
34
  end
25
-
35
+
26
36
  end
27
37
 
28
38
  end
@@ -1,3 +1,3 @@
1
1
  module Slackbotsy
2
- VERSION = "0.0.8"
2
+ VERSION = "0.1.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slackbotsy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Lister
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-09 00:00:00.000000000 Z
11
+ date: 2014-09-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -104,8 +104,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
104
104
  version: '0'
105
105
  requirements: []
106
106
  rubyforge_project:
107
- rubygems_version: 2.0.3
107
+ rubygems_version: 2.0.14
108
108
  signing_key:
109
109
  specification_version: 4
110
110
  summary: Ruby bot for Slack chat.
111
111
  test_files: []
112
+ has_rdoc: