Module: MotionWechat::API

Defined in:
lib/motion-wechat/api.rb

Constant Summary collapse

InvalidMediaObject =
Class.new StandardError

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.configObject


23
24
25
# File 'lib/motion-wechat/api.rb', line 23

def self.config
  NSBundle.mainBundle.objectForInfoDictionaryKey MotionWechat::Config.info_plist_key
end

.instanceObject

Returns singleton instance of MotionWechat

Example:

MotionWechat::API.instance

19
20
21
# File 'lib/motion-wechat/api.rb', line 19

def self.instance
  @instance ||= new config["key"], config["secret"]
end

Instance Method Details

#initialize(key, secret, options = {}) ⇒ Object

initialize weixin API using key and secret


8
9
10
11
12
# File 'lib/motion-wechat/api.rb', line 8

def initialize(key, secret, options={})
  @key    = key
  @secret = secret
  WXApi.registerApp(@key)
end

#send_text(text) ⇒ Object

Send text to wechat

Example:

MotionWechat::API.instance.send_text "hello, motion"

Arguments:

text: (String)

63
64
65
66
67
68
# File 'lib/motion-wechat/api.rb', line 63

def send_text(text)
  req = SendMessageToWXReq.alloc.init
  req.bText = false
  req.text = text
  WXApi.sendReq(req)
end

#wxObject


5
# File 'lib/motion-wechat/api.rb', line 5

def wx; WXApi; end