Class: WechatGate::Config

Inherits:
Object
  • Object
show all
Includes:
Media, Menu, Message, Oauth, SendMessage, Tokens::AccessToken, Tokens::Ext, Tokens::JsapiTicket, User
Defined in:
lib/wechat_gate/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from SendMessage

#mass_send, #single_send

Methods included from Message

#message_body

Methods included from Media

#medias

Methods included from Menu

#menu_create, #menu_get

Methods included from User

#user, #users

Methods included from Oauth

#oauth2_access_token, #oauth2_access_token_valid?, #oauth2_entrance_url, #oauth2_refresh_access_token, #oauth2_user

Methods included from Tokens::Ext

#generate_js_request_params, #write_token_to_file

Methods included from Tokens::JsapiTicket

included

Methods included from Tokens::AccessToken

included

Constructor Details

#initialize(app_name, config_file = nil) {|_self| ... } ⇒ Config

Returns a new instance of Config.

Yields:

  • (_self)

Yield Parameters:

Raises:



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/wechat_gate/config.rb', line 32

def initialize app_name, config_file = nil
  unless config_file
    if defined?(Rails)
      config_file = "#{Rails.root}/config/wechat.yml"
    end
  end

  raise Exception::ConfigException, "no wechat configuration file found!" unless config_file
  unless File.exists?(config_file)
    raise Exception::ConfigException, "configuration file does not exist!"
  end

  config_text = ERB.new(File.read(config_file)).result
  configs = YAML.load(config_text)
  unless configs[app_name]
    raise Exception::ConfigException, "no configuration found for app: #{app_name}!"
  end

  @config = if defined?(Rails)
    configs[app_name][Rails.env] || configs[app_name]
  else
    configs[app_name]
  end

  @app_name = app_name

  yield(self) if block_given?
end

Instance Attribute Details

#app_nameObject (readonly)

Returns the value of attribute app_name.



18
19
20
# File 'lib/wechat_gate/config.rb', line 18

def app_name
  @app_name
end

#configObject (readonly)

Returns the value of attribute config.



19
20
21
# File 'lib/wechat_gate/config.rb', line 19

def config
  @config
end

#output_typeObject (readonly)

Returns the value of attribute output_type.



20
21
22
# File 'lib/wechat_gate/config.rb', line 20

def output_type
  @output_type
end