Class: Fragile::Plugin::ImKayacOutput

Inherits:
Object
  • Object
show all
Defined in:
lib/fragile/plugin/im_kayac_output.rb

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ ImKayacOutput

Returns a new instance of ImKayacOutput.



8
9
10
11
12
13
14
# File 'lib/fragile/plugin/im_kayac_output.rb', line 8

def initialize(config)
  @base_url   = "http://im.kayac.com/api/post/"
  @username   = config[:username]
  @password   = config[:password]   || nil
  @secret_key = config[:secret_key] || nil
  @handler    = config[:handler]    || nil
end

Instance Method Details

#call(data = []) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/fragile/plugin/im_kayac_output.rb', line 16

def call(data=[])
  case
  when data.empty?
    # nothing
  when data.all? {|v| v.kind_of?(Hash) && v.key?(:link) && v.key?(:title)}
    data.each do |item|
      send_im_kayac(item[:title], :handler => item[:link])
    end
  else
    message = create_mesage(data)
    send_im_kayac(message)
  end
end