blacksmith-hipchat 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 290b454dac3d338325f867d593942cb8ffb9b1ee
4
- data.tar.gz: f2a0e80fece3b8bc0871bfd17516071eb03eddc1
3
+ metadata.gz: b4a86ddc466446a6ee015b52b981ded581d31168
4
+ data.tar.gz: 34d62bdaeaa1a4967f6956da3ea9cbea12636a34
5
5
  SHA512:
6
- metadata.gz: 3fcb96091bd222ab080fd3b362f692c4447679be971d529ec098731289b6ca8cf3e58c9a2e7d0bce4e84892f5a8e0b4d81f3de6d2fff3ff9d9fc5571298cb9b8
7
- data.tar.gz: 53a0e2dad344e56e5f83f05129e67135c5f228e1fedf19219b4cc4fed8f50dd146536d6cd7244ed063ff68a9fecb6411cf7b4d480583d9d1c283a4185e5b73a6
6
+ metadata.gz: 27b86bae74e08631eb2a927ed01f095a279b7db21f0a6ad1d574e91c6f719fa9fa5fbb820113087c2f7360b99ef48ba90656925ef36857e7beba307af121dbe9
7
+ data.tar.gz: 31ea4fb9eb9aa7b518fd8e7bdb576c528b45ee7097f200967b2da5fe60a5acb3ba36f86d0f8db0dbc386f792948bf30da0ddf726d9500956696df3ce1c965191
data/README.md CHANGED
@@ -10,6 +10,8 @@ In `Gemfile`:
10
10
  gem 'blacksmith-hipchat'
11
11
  ```
12
12
 
13
+ run `bundle install` afterwards.
14
+
13
15
  In `Chatfile`:
14
16
 
15
17
  ```ruby
@@ -19,18 +21,23 @@ Robut::Plugin.plugins << Blacksmith::Listener
19
21
  # Select a room
20
22
  Blacksmith::Config.room = "chatbot"
21
23
 
22
- # Map the Images with Regexp
23
- Blacksmith::Config.draw do
24
- # If you want someone to approve something
25
- map /approve/, to: 'http://i.imgur.com/4L8lDAl.png'
24
+ # custom server_url
25
+ Blacksmith::Config.server_url = "https://custom_server.com"
26
26
 
27
- # If you want to have faith
28
- map /(have|has|had) faith/, to: 'http://i.imgur.com/BGnagT3.png'
27
+ # API token for the account sending all messages
28
+ # See how to generate a personal token at https://www.hipchat.com/docs/apiv2/method/generate_token
29
+ Blacksmith::Config.api_token = "..."
29
30
 
30
- # If you want to tell some one to do it
31
- map /do it/, to: 'http://i.imgur.com/4loCJ30.png'
31
+ # Map the Images with Regexp
32
+ Blacksmith::Config.draw do
33
+ # map /regexp/, to: 'image_url'
34
+ map /just do it/, to: 'https://i.imgur.com/4loCJ30.png'
32
35
  end
36
+ ```
33
37
 
34
- # Optional: Add a title
38
+ Optional setup:
39
+
40
+ ```ruby
41
+ # Add a title to the message sender
35
42
  Blacksmith::Config.title = "Memebot"
36
43
  ```
@@ -1,11 +1,23 @@
1
1
  module Blacksmith
2
2
  class Config
3
- SERVER_URL = ENV["HIPCHAT_SERVER_URL"]
4
- API_TOKEN = ENV["HIPCHAT_API_TOKEN"]
5
-
6
3
  class << self
4
+
5
+ attr_accessor :title, :room, :patterns, :server_url, :api_token
6
+
7
7
  def connection
8
- @client ||= HipChat::Client.new(API_TOKEN, server_url: SERVER_URL)
8
+ return @client if @client
9
+
10
+ ["room", "api_token"].each do |attr|
11
+ if eval(attr).nil?
12
+ raise ConfigError, "Missing configuration: #{attr}. Check README to setup."
13
+ end
14
+ end
15
+
16
+ @client = if server_url
17
+ HipChat::Client.new(api_token, server_url: server_url)
18
+ else
19
+ HipChat::Client.new(api_token)
20
+ end
9
21
  end
10
22
 
11
23
  def establish_connection!
@@ -17,34 +29,17 @@ module Blacksmith
17
29
  end
18
30
 
19
31
  def map(pattern = nil, options = {})
20
- raise MappingError, "No pattern is given" if pattern.nil?
21
- raise MappingError, "Pattern cannot be blank" if pattern == //
22
- raise MappingError, "Pattern should be a Regexp" unless pattern.is_a? Regexp
23
- raise MappingError, "Missing target in mapping. Use: to: 'target'" if options.is_a?(Hash).! || options[:to].nil?
24
- patterns[pattern] = options[:to]
25
- end
32
+ self.patterns ||= {}
26
33
 
27
- def patterns
28
- @patterns ||= {}
29
- end
30
-
31
- def title
32
- @title ||= ""
33
- end
34
-
35
- def title=(name)
36
- @title = name
37
- end
38
-
39
- def room
40
- @room ||= ""
41
- end
34
+ raise MappingError, "Pattern can only be a Regexp" unless pattern.is_a? Regexp
35
+ raise MappingError, "Pattern cannot be blank" if pattern == //
36
+ raise MappingError, "Missing target in mapping. Use: to: 'image_url'" if options.is_a?(Hash).! || options[:to].nil?
42
37
 
43
- def room=(name)
44
- @room = name
38
+ self.patterns[pattern] = options[:to]
45
39
  end
46
40
  end
47
41
  end
48
42
 
43
+ class ConfigError < StandardError; end
49
44
  class MappingError < StandardError; end
50
45
  end
@@ -5,11 +5,13 @@ module Blacksmith
5
5
  include Robut::Plugin
6
6
 
7
7
  def handle(time, sender, message)
8
+ # Don't handle messages sent from this plugin
8
9
  return if message.include?("File uploaded")
10
+
9
11
  Config.patterns.each do |pattern, url|
10
12
  if message[pattern]
11
13
  Hammer.new(url: url).slam
12
- return
14
+ break
13
15
  end
14
16
  end
15
17
  rescue => err
@@ -1,3 +1,3 @@
1
1
  module Blacksmith
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blacksmith-hipchat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adler Hsieh
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-08-29 00:00:00.000000000 Z
11
+ date: 2017-10-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: robut