Class: App

Inherits:
Thor
  • Object
show all
Defined in:
lib/wechat.rb

Defined Under Namespace

Classes: Helper

Instance Method Summary collapse

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(options)

  media_id = api.media_create("image", file)["media_id"]
  puts api.custom_message_send 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(options)

  api_opts = options.slice(:title, :description, :HQ_music_url)
  thumb_media_id = api.media_create("thumb", file)["thumb_media_id"]
  puts api.custom_message_send 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(options).custom_message_send 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, text_message
  puts Helper.with(options).custom_message_send Wechat::Message.to(openid).text(text_message)
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(options)

  api_opts = options.slice(:title, :description)
  media_id = api.media_create("video", file)["media_id"]
  puts api.custom_message_send 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(options)

  media_id = api.media_create("voice", file)["media_id"]
  puts api.custom_message_send 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(options).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(options).media_create(type, file)
end


46
47
48
# File 'lib/wechat.rb', line 46

def menu
  puts Helper.with(options).menu
end


56
57
58
59
# File 'lib/wechat.rb', line 56

def menu_create(menu_yaml)
  menu = YAML.load(File.new(menu_yaml).read)
  puts "Menu created" if Helper.with(options).menu_create(menu)
end


51
52
53
# File 'lib/wechat.rb', line 51

def menu_delete
  puts "Menu deleted" if Helper.with(options).menu_delete
end

#user(open_id) ⇒ Object



41
42
43
# File 'lib/wechat.rb', line 41

def user(open_id)
  puts Helper.with(options).user(open_id)
end

#usersObject



36
37
38
# File 'lib/wechat.rb', line 36

def users
  puts Helper.with(options).users
end