Class: Slax::Complex::AttachmentBuilder

Inherits:
BasicObject
Defined in:
lib/slax/complex/attachment_builder.rb

Constant Summary collapse

VALID_PARAMS =
[:fallback, :color, :pretext, :author_name, 
 :author_link, :author_icon, :title, :title_link, 
 :text, :image_url, :thumb_url,
 :footer, :footer_icon, :ts
]

Instance Method Summary collapse

Constructor Details

#initializeAttachmentBuilder

Returns a new instance of AttachmentBuilder.



9
10
11
# File 'lib/slax/complex/attachment_builder.rb', line 9

def initialize
  @payload = { fallback: "" }
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object



13
14
15
16
17
18
19
20
21
22
# File 'lib/slax/complex/attachment_builder.rb', line 13

def method_missing(name, *args, &block)
  if VALID_PARAMS.include?(name)
    if args.count > 0
      @payload[name] = args.join(' ')
      @payload[name]
    end
  else
    super
  end
end

Instance Method Details

#fields(title, value, short = nil) ⇒ Object



24
25
26
27
28
29
30
31
32
33
# File 'lib/slax/complex/attachment_builder.rb', line 24

def fields(title, value, short = nil)
  @payload[:fields] ||= []
  @sub_payload = { title: title, value: value }

  unless short.nil?
    @sub_payload[:short] = short
  end
  
  @payload[:fields] << @sub_payload
end

#payloadObject



41
42
43
# File 'lib/slax/complex/attachment_builder.rb', line 41

def payload
  @payload
end

#timestamp(time) ⇒ Object Also known as: ts



35
36
37
# File 'lib/slax/complex/attachment_builder.rb', line 35

def timestamp(time)
  @payload[:ts] = time.to_i
end