Class: SimpleWx::Menu
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
- #create(menu_hash) ⇒ Object
- #create!(menu_hash) ⇒ Object
- #delete ⇒ Object
- #delete! ⇒ Object
-
#initialize(options = {}) ⇒ Menu
constructor
Usage.
- #show ⇒ Object
Methods inherited from Base
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 .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 = {} @access_token = [: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 url = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=#{@access_token}" response = RestClient.post(url, JSON.generate({button: })) 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! @raise_flag ||= true create end |
#delete ⇒ Object
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 |
#show ⇒ Object
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 |