Module: Wechat

Defined in:
lib/wechat-rails.rb,
lib/wechat/client.rb,
lib/wechat/message.rb,
lib/wechat/responder.rb,
lib/wechat/access_token.rb

Defined Under Namespace

Modules: Responder Classes: AccessToken, AccessTokenExpiredError, Api, Client, Message, ResponseError

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



17
18
19
# File 'lib/wechat-rails.rb', line 17

def config
  @config
end

Class Method Details

.apiObject



33
34
35
# File 'lib/wechat-rails.rb', line 33

def self.api
  @api ||= Wechat::Api.new(self.config.appid, self.config.secret, self.config.access_token)
end

.configObject



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/wechat-rails.rb', line 19

def self.config
  @config ||= begin
    if defined? Rails
      config_file = Rails.root.join("config/wechat.yml")
      config = YAML.load(ERB.new(File.new(config_file).read).result)[Rails.env] if (File.exist?(config_file))
    end

    config ||= {appid: ENV["WECHAT_APPID"], secret: ENV["WECHAT_SECRET"], token: ENV["WECHAT_TOKEN"], access_token: ENV["WECHAT_ACCESS_TOKEN"]}
    config.symbolize_keys!
    config[:access_token] ||= Rails.root.join("tmp/access_token").to_s
    OpenStruct.new(config)
  end
end