Class: SimpleWx::Menu

Inherits:
Base
  • Object
show all
Defined in:
lib/simple_wx/menu.rb

Instance Attribute Summary

Attributes inherited from Base

#error, #raise_flag

Instance Method Summary collapse

Methods inherited from Base

method_missing

Constructor Details

#initialize(options = {}) ⇒ Menu

Usage

———- class-methods ———-

SimpleWx::Menu.show SimpleWx::Menu.create(buttons)

> true/false

SimpleWx::Menu.delete

> true/false

———- instance-methods ———–

menu = SimpleWx::Menu.new menu.show

if menu.create(buttons)

...

else

p menu.error

end

menu.delete! when “errcode” existed in json of response, it will raise the error:

> “Weixin response json with errcode: #json”



30
31
32
# File 'lib/simple_wx/menu.rb', line 30

def initialize options = {}
  @access_token = options[:access_token] || AccessToken.access_token
end

Instance Method Details

#create(menu_hash) ⇒ Object



40
41
42
43
44
45
# File 'lib/simple_wx/menu.rb', line 40

def create menu_hash
  url = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=#{@access_token}"
  response = RestClient.post(url, JSON.generate({button: menu_hash}))
  errcode_check(JSON.parse(response))
  @error.blank?
end

#create!(menu_hash) ⇒ Object



54
55
56
57
# File 'lib/simple_wx/menu.rb', line 54

def create! menu_hash
  @raise_flag ||= true
  create menu_hash
end

#deleteObject



47
48
49
50
51
52
# File 'lib/simple_wx/menu.rb', line 47

def delete
  url = "https://api.weixin.qq.com/cgi-bin/menu/delete?access_token=#{@access_token}"
  response = RestClient.get url
  errcode_check(JSON.parse(response))
  @error.blank?
end

#delete!Object



59
60
61
62
# File 'lib/simple_wx/menu.rb', line 59

def delete!
  @raise_flag ||= true
  delete
end

#showObject



34
35
36
37
38
# File 'lib/simple_wx/menu.rb', line 34

def show
  url = "https://api.weixin.qq.com/cgi-bin/menu/get?access_token=#{@access_token}"
  response = RestClient.get url
  errcode_check(JSON.parse(response))
end