Class: App
- Inherits:
-
Thor
- Object
- Thor
- App
- Defined in:
- lib/wechat.rb
Defined Under Namespace
Classes: Helper
Instance Method Summary collapse
- #custom_image(openid, image_path) ⇒ Object
- #custom_music(openid, thumbnail_path, music_url) ⇒ Object
- #custom_news(openid, news_yaml) ⇒ Object
- #custom_text(openid, text_message) ⇒ Object
- #custom_video(openid, video_path) ⇒ Object
- #custom_voice(openid, voice_path) ⇒ Object
- #media(media_id, path) ⇒ Object
- #media_create(type, path) ⇒ Object
- #menu ⇒ Object
- #menu_create(menu_yaml) ⇒ Object
- #menu_delete ⇒ Object
- #user(open_id) ⇒ Object
- #users ⇒ Object
Instance Method Details
#custom_image(openid, image_path) ⇒ Object
80 81 82 83 84 85 86 |
# File 'lib/wechat.rb', line 80 def custom_image openid, image_path file = File.new(image_path) api = Helper.with() media_id = api.media_create("image", file)["media_id"] puts api. Wechat::Message.to(openid).image(media_id) end |
#custom_music(openid, thumbnail_path, music_url) ⇒ Object
113 114 115 116 117 118 119 120 |
# File 'lib/wechat.rb', line 113 def custom_music openid, thumbnail_path, music_url file = File.new(thumbnail_path) api = Helper.with() api_opts = .slice(:title, :description, :HQ_music_url) thumb_media_id = api.media_create("thumb", file)["thumb_media_id"] puts api. Wechat::Message.to(openid).music(thumb_media_id, music_url, api_opts) end |
#custom_news(openid, news_yaml) ⇒ Object
123 124 125 126 |
# File 'lib/wechat.rb', line 123 def custom_news openid, news_yaml articles = YAML.load(File.new(news_yaml).read) puts Helper.with(). Wechat::Message.to(openid).news(articles["articles"]) end |
#custom_text(openid, text_message) ⇒ Object
75 76 77 |
# File 'lib/wechat.rb', line 75 def custom_text openid, puts Helper.with(). Wechat::Message.to(openid).text() end |
#custom_video(openid, video_path) ⇒ Object
100 101 102 103 104 105 106 107 |
# File 'lib/wechat.rb', line 100 def custom_video openid, video_path file = File.new(video_path) api = Helper.with() api_opts = .slice(:title, :description) media_id = api.media_create("video", file)["media_id"] puts api. Wechat::Message.to(openid).video(media_id, api_opts) end |
#custom_voice(openid, voice_path) ⇒ Object
89 90 91 92 93 94 95 |
# File 'lib/wechat.rb', line 89 def custom_voice openid, voice_path file = File.new(voice_path) api = Helper.with() media_id = api.media_create("voice", file)["media_id"] puts api. Wechat::Message.to(openid).voice(media_id) end |
#media(media_id, path) ⇒ Object
62 63 64 65 66 |
# File 'lib/wechat.rb', line 62 def media(media_id, path) tmp_file = Helper.with().media(media_id) FileUtils.mv(tmp_file.path, path) puts "File downloaded" end |
#media_create(type, path) ⇒ Object
69 70 71 72 |
# File 'lib/wechat.rb', line 69 def media_create(type, path) file = File.new(path) puts Helper.with().media_create(type, file) end |
#menu_create(menu_yaml) ⇒ Object
56 57 58 59 |
# File 'lib/wechat.rb', line 56 def () = YAML.load(File.new().read) puts "Menu created" if Helper.with().() end |
#menu_delete ⇒ Object
51 52 53 |
# File 'lib/wechat.rb', line 51 def puts "Menu deleted" if Helper.with(). end |