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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3d6ae454046f542a25563ea04c4b951190a0ab6a
4
- data.tar.gz: 9b844f70cd74566c45a2811a19062788c844285b
3
+ metadata.gz: fef2dd7d2fb48e260595e1ace9e35752b54070b5
4
+ data.tar.gz: 325155b82d593d892e09283c80da45b3ecb062b3
5
5
  SHA512:
6
- metadata.gz: bf66d653c8c241b8c9e8ea77361e14f1028adac287a5b3cd437b7fe262b9be50deb374d907d16e08cb61dd8b193b031a8c8da90f05238ff607abc868063099d1
7
- data.tar.gz: a0e4907a612392c028ff3e492040970060bcfaf46337080c254f4f88679f537d8bfef7c237cec7ca92f70239ce8ae0b99e1dde2270cbf2773ac8a95bd2f0e5f4
6
+ metadata.gz: f5e1cc592a788bfc05760f0a909317a90d28b7d54c11ca591d29ea3697774fa467ea51ce47420e7e5ff8fdf154f07c27aa0c096b1eddc0569b6e24e64f329f2c
7
+ data.tar.gz: f3c65a6df4d02acc85c9aaa1e79e9dbebb7e04fb8c18c9f99c4d14eac87ca70058979605e95de5a3d7fd08c44ff35061ff4232c2ea90f4c4e1fee90860719cd1
data/.gitignore CHANGED
@@ -7,3 +7,4 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+ *.gem
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: # 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
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
 
@@ -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
@@ -12,16 +12,20 @@ module SlackMessenger
12
12
  end
13
13
 
14
14
  def self.send(message, api = nil)
15
- api = SlackMessenger.default_api if api.nil?
15
+ if api.nil?
16
+ api = SlackMessenger.default_api
17
+ end
16
18
 
17
- raise "default_api not set" if api.nil?
18
- raise "No slack endpoint set" if api.endpoint.nil?
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
- if result.code == 200
23
+
24
+ case result.code
25
+ when 200
22
26
  true
23
27
  else
24
- false
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
@@ -1,3 +1,3 @@
1
1
  module SlackMessenger
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.0"
3
3
  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.0.0
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