Commit 6768d300 by lanrion

refactor menu.rb with "http_get" and "http_post" method

parent 29f216fc
...@@ -6,28 +6,28 @@ module WeixinAuthorize ...@@ -6,28 +6,28 @@ module WeixinAuthorize
# 自定义菜单查询接口 # 自定义菜单查询接口
# https://api.weixin.qq.com/cgi-bin/menu/get?access_token=ACCESS_TOKEN # https://api.weixin.qq.com/cgi-bin/menu/get?access_token=ACCESS_TOKEN
def menu def menu
get_menu_url = "#{menu_base_url}/get?#{access_token_param}" get_menu_url = "#{menu_base_url}/get"
JSON.parse(RestClient.get(get_menu_url)) http_get(get_menu_url)
end end
# 自定义菜单删除接口 # 自定义菜单删除接口
# https://api.weixin.qq.com/cgi-bin/menu/delete?access_token=ACCESS_TOKEN # https://api.weixin.qq.com/cgi-bin/menu/delete?access_token=ACCESS_TOKEN
def delete_menu def delete_menu
delete_menu_url = "#{menu_base_url}/delete?#{access_token_param}" delete_menu_url = "#{menu_base_url}/delete"
JSON.parse(RestClient.get(delete_menu_url)) http_get(delete_menu_url)
end end
# 自定义菜单创建接口 # 自定义菜单创建接口
# https://api.weixin.qq.com/cgi-bin/menu/create?access_token=ACCESS_TOKEN # https://api.weixin.qq.com/cgi-bin/menu/create?access_token=ACCESS_TOKEN
def create_menu(menu) def create_menu(menu)
create_menu_url = "#{menu_base_url}/create?#{access_token_param}" create_menu_url = "#{menu_base_url}/create"
JSON.parse(RestClient.post(create_menu_url, menu)) http_post(create_menu_url, menu)
end end
private private
def menu_base_url def menu_base_url
"#{endpoint}/menu" "/menu"
end end
end end
......
...@@ -6,7 +6,9 @@ describe WeixinAuthorize::Api::Menu do ...@@ -6,7 +6,9 @@ describe WeixinAuthorize::Api::Menu do
it "can create a menu" do it "can create a menu" do
menu = '{"button":[{"type":"click","name":"今日歌曲","key":"V1001_TODAY_MUSIC"},{"type":"click","name":"歌手简介","key":"V1001_TODAY_SINGER"},{"name":"菜单","sub_button":[{"type":"view","name":"搜索","url":"http://www.soso.com/"},{"type":"view","name":"视频","url":"http://v.qq.com/"},{"type":"click","name":"赞一下我们","key":"V1001_GOOD"}]}]}' menu = '{"button":[{"type":"click","name":"今日歌曲","key":"V1001_TODAY_MUSIC"},{"type":"click","name":"歌手简介","key":"V1001_TODAY_SINGER"},{"name":"菜单","sub_button":[{"type":"view","name":"搜索","url":"http://www.soso.com/"},{"type":"view","name":"视频","url":"http://v.qq.com/"},{"type":"click","name":"赞一下我们","key":"V1001_GOOD"}]}]}'
response = $client.create_menu(menu) response = $client.create_menu(menu)
puts response
expect(response["errcode"]).to eq(0) expect(response["errcode"]).to eq(0)
end end
it "can get a weixin Menu info" do it "can get a weixin Menu info" do
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment