Class: Banacle::Slack::Response
- Inherits:
-
Struct
- Object
- Struct
- Banacle::Slack::Response
- Defined in:
- lib/banacle/slack.rb
Defined Under Namespace
Classes: ValidationError
Instance Attribute Summary collapse
-
#attachments ⇒ Object
Returns the value of attribute attachments.
-
#replace_original ⇒ Object
Returns the value of attribute replace_original.
-
#response_type ⇒ Object
Returns the value of attribute response_type.
-
#text ⇒ Object
Returns the value of attribute text.
Instance Method Summary collapse
- #as_json ⇒ Object
-
#initialize(*args) ⇒ Response
constructor
A new instance of Response.
- #set_default! ⇒ Object
- #to_json ⇒ Object
- #validate! ⇒ Object
Constructor Details
#initialize(*args) ⇒ Response
Returns a new instance of Response.
6 7 8 9 10 11 |
# File 'lib/banacle/slack.rb', line 6 def initialize(*args) super self.set_default! self.validate! self end |
Instance Attribute Details
#attachments ⇒ Object
Returns the value of attribute attachments
3 4 5 |
# File 'lib/banacle/slack.rb', line 3 def @attachments end |
#replace_original ⇒ Object
Returns the value of attribute replace_original
3 4 5 |
# File 'lib/banacle/slack.rb', line 3 def replace_original @replace_original end |
#response_type ⇒ Object
Returns the value of attribute response_type
3 4 5 |
# File 'lib/banacle/slack.rb', line 3 def response_type @response_type end |
#text ⇒ Object
Returns the value of attribute text
3 4 5 |
# File 'lib/banacle/slack.rb', line 3 def text @text end |
Instance Method Details
#as_json ⇒ Object
38 39 40 |
# File 'lib/banacle/slack.rb', line 38 def as_json self.to_h.tap { |h| h[:attachments] = h[:attachments].map(&:as_json) } end |
#set_default! ⇒ Object
13 14 15 16 17 18 |
# File 'lib/banacle/slack.rb', line 13 def set_default! self.response_type ||= "in_channel" self.replace_original = true if self.replace_original.nil? self.text ||= "" self. ||= [] end |
#to_json ⇒ Object
42 43 44 |
# File 'lib/banacle/slack.rb', line 42 def to_json as_json.to_json end |
#validate! ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/banacle/slack.rb', line 20 def validate! unless self.replace_original.is_a?(TrueClass) || self.replace_original.is_a?(FalseClass) raise ValidationError.new("replace_original must be TrueClass or FalseClass") end %i(response_type text).each do |label| unless self.send(label).is_a?(String) raise ValidationError.new("#{attr} must be String") end end .each do |a| unless a.is_a?(Slack::Attachment) raise ValidationError.new("One of attachments #{a.inspect} must be Slack::Attachment") end end end |