Class: MiniProgram::Msg
- Inherits:
-
Object
- Object
- MiniProgram::Msg
- Defined in:
- lib/mini_program/msg.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#msg_config ⇒ Object
readonly
Returns the value of attribute msg_config.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #as_json ⇒ Object
- #config ⇒ Object
-
#initialize(type, data) ⇒ Msg
constructor
A new instance of Msg.
- #mini_program ⇒ Object
- #send_to(open_id) ⇒ Object
Constructor Details
#initialize(type, data) ⇒ Msg
Returns a new instance of Msg.
5 6 7 8 |
# File 'lib/mini_program/msg.rb', line 5 def initialize(type, data) @type = type @data = data end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
4 5 6 |
# File 'lib/mini_program/msg.rb', line 4 def data @data end |
#msg_config ⇒ Object (readonly)
Returns the value of attribute msg_config.
4 5 6 |
# File 'lib/mini_program/msg.rb', line 4 def msg_config @msg_config end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
4 5 6 |
# File 'lib/mini_program/msg.rb', line 4 def type @type end |
Instance Method Details
#as_json ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/mini_program/msg.rb', line 10 def as_json { template_id: config[:template_id], data: JSON.parse(config[:data].to_json % data), page: config[:page], } end |
#config ⇒ Object
26 27 28 |
# File 'lib/mini_program/msg.rb', line 26 def config @config ||= YAML.load_file(Rails.root.join("config/subscribe_msg.yml")).with_indifferent_access[type] end |
#mini_program ⇒ Object
22 23 24 |
# File 'lib/mini_program/msg.rb', line 22 def mini_program @mini_program ||= MiniProgram::Client.new end |
#send_to(open_id) ⇒ Object
18 19 20 |
# File 'lib/mini_program/msg.rb', line 18 def send_to(open_id) mini_program.send_msg(self, to: open_id) end |