slack_messenger 1.0.0 → 1.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 +4 -4
- data/.gitignore +1 -0
- data/README.md +3 -3
- data/lib/slack_messenger.rb +2 -1
- data/lib/slack_messenger/api.rb +9 -5
- data/lib/slack_messenger/error.rb +29 -0
- data/lib/slack_messenger/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: fef2dd7d2fb48e260595e1ace9e35752b54070b5
|
|
4
|
+
data.tar.gz: 325155b82d593d892e09283c80da45b3ecb062b3
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f5e1cc592a788bfc05760f0a909317a90d28b7d54c11ca591d29ea3697774fa467ea51ce47420e7e5ff8fdf154f07c27aa0c096b1eddc0569b6e24e64f329f2c
|
|
7
|
+
data.tar.gz: f3c65a6df4d02acc85c9aaa1e79e9dbebb7e04fb8c18c9f99c4d14eac87ca70058979605e95de5a3d7fd08c44ff35061ff4232c2ea90f4c4e1fee90860719cd1
|
data/.gitignore
CHANGED
data/README.md
CHANGED
|
@@ -103,9 +103,9 @@ Attachments can take a number of options:
|
|
|
103
103
|
#### `AttachmentField` Options
|
|
104
104
|
AttachmentFields can take 3 options
|
|
105
105
|
```ruby
|
|
106
|
-
title
|
|
107
|
-
value
|
|
108
|
-
short
|
|
106
|
+
:title # Bolded text at the top of field
|
|
107
|
+
:value # Unformatted text that appears in body of field
|
|
108
|
+
:short # Boolean value that sets width of field to 50% if true, otherwise is 100% of message width
|
|
109
109
|
```
|
|
110
110
|
|
|
111
111
|
|
data/lib/slack_messenger.rb
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
require "slack_messenger/error"
|
|
1
2
|
require "slack_messenger/version"
|
|
2
3
|
require "slack_messenger/api"
|
|
3
4
|
require "slack_messenger/message"
|
|
@@ -15,7 +16,7 @@ module SlackMessenger
|
|
|
15
16
|
end
|
|
16
17
|
|
|
17
18
|
def self.default_api
|
|
18
|
-
configuration.default_api
|
|
19
|
+
configuration.default_api rescue nil
|
|
19
20
|
end
|
|
20
21
|
|
|
21
22
|
def self.attachment_color
|
data/lib/slack_messenger/api.rb
CHANGED
|
@@ -12,16 +12,20 @@ module SlackMessenger
|
|
|
12
12
|
end
|
|
13
13
|
|
|
14
14
|
def self.send(message, api = nil)
|
|
15
|
-
|
|
15
|
+
if api.nil?
|
|
16
|
+
api = SlackMessenger.default_api
|
|
17
|
+
end
|
|
16
18
|
|
|
17
|
-
raise
|
|
18
|
-
raise
|
|
19
|
+
raise ApiNotSetError.new if api.nil?
|
|
20
|
+
raise EndpointNotSetError.new if api.endpoint.nil? || api.endpoint == ""
|
|
19
21
|
|
|
20
22
|
result = HTTParty.post(api.endpoint, body: message.as_json.to_json)
|
|
21
|
-
|
|
23
|
+
|
|
24
|
+
case result.code
|
|
25
|
+
when 200
|
|
22
26
|
true
|
|
23
27
|
else
|
|
24
|
-
|
|
28
|
+
raise SendError.new result.code
|
|
25
29
|
end
|
|
26
30
|
end
|
|
27
31
|
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
module SlackMessenger
|
|
2
|
+
class Error < StandardError
|
|
3
|
+
def initialize(msg="An unknown error occurred")
|
|
4
|
+
super(msg)
|
|
5
|
+
end
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
class ApiNotSetError < Error
|
|
9
|
+
def initialize
|
|
10
|
+
super "Default API not set, please set it via SlackMessenger.configure or add to ENV['SLACK_API_ENDPOINT']"
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
class EndpointNotSetError < Error
|
|
15
|
+
def initialize
|
|
16
|
+
super "The API's endpoint was not set"
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
class SendError < Error
|
|
21
|
+
attr_accessor :status_code
|
|
22
|
+
def initialize(status_code)
|
|
23
|
+
@status_code = status_code
|
|
24
|
+
msg = "Error encountered when sending payload (HTTP Status: #{status_code})"
|
|
25
|
+
|
|
26
|
+
super(msg)
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: slack_messenger
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Josh Tate
|
|
@@ -86,6 +86,7 @@ files:
|
|
|
86
86
|
- lib/slack_messenger/api.rb
|
|
87
87
|
- lib/slack_messenger/attachment.rb
|
|
88
88
|
- lib/slack_messenger/attachment_field.rb
|
|
89
|
+
- lib/slack_messenger/error.rb
|
|
89
90
|
- lib/slack_messenger/message.rb
|
|
90
91
|
- lib/slack_messenger/version.rb
|
|
91
92
|
- slack_messenger.gemspec
|