Class: MiniProgram::Msg

Inherits:
Object
  • Object
show all
Defined in:
lib/mini_program/msg.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#dataObject (readonly)

Returns the value of attribute data.



4
5
6
# File 'lib/mini_program/msg.rb', line 4

def data
  @data
end

#msg_configObject (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

#typeObject (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_jsonObject



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

#configObject



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_programObject



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