Class: SimpleWx::Menu
Instance Attribute Summary
Attributes inherited from Base
Class Method Summary collapse
Instance Method Summary collapse
- #create(menu_hash) ⇒ Object
- #create!(menu_hash) ⇒ Object
- #delete ⇒ Object
- #delete! ⇒ Object
-
#initialize(options = {}) ⇒ Menu
constructor
Usage.
- #show ⇒ Object
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 |
Class Method Details
.method_missing(m, *args) ⇒ Object
65 66 67 68 69 70 71 |
# File 'lib/simple_wx/menu.rb', line 65 def self.method_missing m, *args if instance_methods.include? m.to_sym self.new.send(m, *args) else super end end |
Instance Method Details
#create(menu_hash) ⇒ Object
41 42 43 44 45 46 |
# File 'lib/simple_wx/menu.rb', line 41 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
55 56 57 58 |
# File 'lib/simple_wx/menu.rb', line 55 def create! @raise_flag ||= true create end |
#delete ⇒ Object
48 49 50 51 52 53 |
# File 'lib/simple_wx/menu.rb', line 48 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
60 61 62 63 |
# File 'lib/simple_wx/menu.rb', line 60 def delete! @raise_flag ||= true delete end |
#show ⇒ Object
34 35 36 37 38 39 |
# 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 response_json = errcode_check(JSON.parse(response)) @menus = response_json["menu"] end |