Module: LanxinOpen

Extended by:
LanxinOpen
Included in:
LanxinOpen
Defined in:
lib/lanxin_open.rb,
lib/lanxin_open/version.rb,
lib/lanxin_open/net_util.rb,
lib/lanxin_open/openplatform.rb

Defined Under Namespace

Modules: Platform Classes: NetUtil, OpenPlatformV1

Constant Summary collapse

VERSION =
"0.0.7"

Class Method Summary collapse

Class Method Details

.config(&block) ⇒ Object



22
23
24
# File 'lib/lanxin_open.rb', line 22

def self.config(&block)
  instance_eval &block
end

.dean_hash2xml(p_hash) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/lanxin_open.rb', line 34

def self.dean_hash2xml(p_hash)
  # return nil if (not p_hash) or p_hash.length <= 0
  no_cdata_key = ["CreateTime","MsgId"]
  line_break = "" #"\n"
  xml_str = "<xml>#{line_break}"
  p_hash.each do |k,v|
    if no_cdata_key.include?(k)
      xml_str += "<#{k}>#{v}</#{k}>#{line_break}"
    else
      xml_str += "<#{k}><![CDATA[#{v}]]></#{k}>#{line_break}"
    end
  end
  xml_str += "</xml>"
end

.hash_to_xml(p_hash) ⇒ Object



49
50
51
52
# File 'lib/lanxin_open.rb', line 49

def self.hash_to_xml(p_hash)
  # return nil if (not p_hash) or p_hash.length <= 0
  return dean_hash2xml(p_hash)
end

.newObject



30
31
32
# File 'lib/lanxin_open.rb', line 30

def self.new
  OpenPlatformV1.new({})
end

.new_with_params(args) ⇒ Object



26
27
28
# File 'lib/lanxin_open.rb', line 26

def self.new_with_params(args)
  OpenPlatformV1.new(args)
end

.parameter(*names) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/lanxin_open.rb', line 9

def self.parameter(*names)
  names.each do |name|
    attr_accessor name
    # For each given symbol we generate accessor method that sets option's
    # value being called with an argument, or returns option's current value
    # when called without arguments
    define_method name do |*values|
      value = values.first
      value ? self.send("#{name}=", value) : instance_variable_get("@#{name}")
    end
  end
end

.parse_callback_xml(msgcontent) ⇒ Object



54
55
56
57
58
59
60
61
# File 'lib/lanxin_open.rb', line 54

def self.parse_callback_xml(msgcontent)
  begin
    hash = Hash.from_xml(msgcontent)
    xml_node = hash["xml"]
    return xml_node
  rescue
  end
end