Module: Wechat::ApiLoader

Defined in:
lib/wechat/api_loader.rb

Class Method Summary collapse

Class Method Details

.config(account = :default) ⇒ Object



25
26
27
28
# File 'lib/wechat/api_loader.rb', line 25

def self.config( = :default)
  @configs ||= loading_config!
  @configs[.to_sym] || raise("Wechat configuration for #{account} is missing.")
end

.with(options) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/wechat/api_loader.rb', line 3

def self.with(options)
   = options[:account] || :default
  c = ApiLoader.config()

  token_file = options[:token_file] || c.access_token || '/var/tmp/wechat_access_token'
  js_token_file = options[:js_token_file] || c.jsapi_ticket || '/var/tmp/wechat_jsapi_ticket'

  if c.appid && c.secret && token_file.present?
    Wechat::Api.new(c.appid, c.secret, token_file, c.timeout, c.skip_verify_ssl, js_token_file)
  elsif c.corpid && c.corpsecret && token_file.present?
    Wechat::CorpApi.new(c.corpid, c.corpsecret, token_file, c.agentid, c.timeout, c.skip_verify_ssl, js_token_file)
  else
    puts "Need create ~/.wechat.yml with wechat appid and secret\nor running at rails root folder so wechat can read config/wechat.yml\n"
    exit 1
  end
end