Class: SimpleWx::Messages::NewsMessage

Inherits:
SimpleWx::Message show all
Defined in:
lib/simple_wx/messages/news_message.rb

Instance Attribute Summary

Attributes inherited from SimpleWx::Message

#json, #openid, #xml

Attributes inherited from Base

#error, #raise_flag

Instance Method Summary collapse

Methods inherited from Base

method_missing

Constructor Details

#initialize(options) ⇒ NewsMessage

Returns a new instance of NewsMessage.



4
5
6
7
# File 'lib/simple_wx/messages/news_message.rb', line 4

def initialize options
  super
  @articles = options[:articles]
end

Instance Method Details

#send_jsonObject



9
10
11
12
13
14
# File 'lib/simple_wx/messages/news_message.rb', line 9

def send_json
  @json[:msgtype] = "news"
  @json[:news] = { articles: @articles }
  SimpleWx.logger.info("SimpleWxLog:#{self.class.name} -- #{@openid} -- #{json}")
  super
end

#to_xmlObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/simple_wx/messages/news_message.rb', line 16

def to_xml
  @xml["MsgType"] = "news"
  @xml["ArticleCount"] = @articles.size
  @xml["Articles"] = @articles.map do |item|
    {
      "item" =>
        {
          "Title"       => item[:title],
          "Description" => item[:description],
          "PicUrl"      => item[:picurl],
          "Url"         => item[:url]
        }
    }
  end
  super
end