Class: SimpleWx::Template

Inherits:
Message show all
Defined in:
lib/simple_wx/template.rb

Instance Attribute Summary collapse

Attributes inherited from Message

#json, #openid, #xml

Attributes inherited from Base

#error, #raise_flag

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

method_missing

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 options
  super
  @access_token = options[:access_token] || AccessToken.access_token
  @template_id_short = options[:template_id_short]
  @template_id = options[:template_id]
  @url = options[:url]
  @topcolor = options[:topcolor]
  @data = options[:data]
end

Instance Attribute Details

#template_idObject (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_idObject



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_jsonObject



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