Class: SimpleWx::Template
- Defined in:
- lib/simple_wx/template.rb
Instance Attribute Summary collapse
-
#template_id ⇒ Object
readonly
Returns the value of attribute template_id.
Attributes inherited from Message
Attributes inherited from Base
Class Method Summary collapse
Instance Method Summary collapse
- #get_template_id ⇒ Object
-
#initialize(options) ⇒ Template
constructor
A new instance of Template.
- #send_json ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(options) ⇒ Template
Returns a new instance of Template.
5 6 7 8 9 10 11 12 13 |
# File 'lib/simple_wx/template.rb', line 5 def initialize super @access_token = [:access_token] || AccessToken.access_token @template_id_short = [:template_id_short] @template_id = [:template_id] @url = [:url] @topcolor = [:topcolor] @data = [:data] end |
Instance Attribute Details
#template_id ⇒ Object (readonly)
Returns the value of attribute template_id.
3 4 5 |
# File 'lib/simple_wx/template.rb', line 3 def template_id @template_id end |
Class Method Details
.set_industry(id1, id2) ⇒ Object
35 36 37 38 39 |
# File 'lib/simple_wx/template.rb', line 35 def self.set_industry id1 ,id2 url = "https://api.weixin.qq.com/cgi-bin/template/api_set_industry?access_token=#{@access_token}" response = RestClient.post(url, JSON.generate({industry_id1: id1, industry_id2: id2})) errcode_check(JSON.parse(response)) end |
Instance Method Details
#get_template_id ⇒ Object
17 18 19 20 21 22 |
# File 'lib/simple_wx/template.rb', line 17 def get_template_id url = "https://api.weixin.qq.com/cgi-bin/template/api_add_template?access_token=#{@access_token}" response = RestClient.post(url, JSON.generate({template_id_short: @template_id_short})) response_json = errcode_check(JSON.parse(response)) @template_id = response_json["template_id"] end |
#send_json ⇒ Object
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/simple_wx/template.rb', line 24 def send_json set_json @json["template_id"] = @template_id @json["url"] = @url @json["topcolor"] = @topcolor @json["data"] = @data url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=#{@access_token}" response = RestClient.post(url, JSON.generate(@json)) errcode_check(JSON.parse(response)) end |