Class: EmaySoap::Client

Inherits:
Object
  • Object
show all
Includes:
Configurable
Defined in:
lib/emay_soap/client.rb

Constant Summary collapse

ENDPOINT =
'http://sdk4report.eucp.b2m.cn:8080/sdk/SDKService?wsdl'.freeze

Instance Attribute Summary

Attributes included from Configurable

#cdkey, #key, #password, #prefix

Instance Method Summary collapse

Methods included from Configurable

default_options, #options, #setup, setup_keys

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



10
11
12
13
14
# File 'lib/emay_soap/client.rb', line 10

def initialize(options = {})
  EmaySoap::Configurable.setup_keys.each do |k|
    instance_variable_set(:"@#{k}", options[k] || EmaySoap::Configurable.default_options[k])
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object

Create all methods via method_missing,



63
64
65
66
67
68
69
70
71
72
73
# File 'lib/emay_soap/client.rb', line 63

def method_missing(method, *args)
  ary = args.each_with_index.inject([]) do |r, (e, i)|
    r << ["arg#{i+2}".to_sym, e]
  end
  message = Hash[ary]
  if operations.include?(method)
    call(method, message)
  else
    super
  end
end

Instance Method Details

#charge_up(cardno, cardpass) ⇒ Object



38
39
40
# File 'lib/emay_soap/client.rb', line 38

def charge_up(cardno, cardpass)
  call(:charge_up, arg2: cardno, arg3: cardpass)
end

#operation(action) ⇒ Object



20
21
22
# File 'lib/emay_soap/client.rb', line 20

def operation(action)
  savon.operation(action)
end

#operationsObject



16
17
18
# File 'lib/emay_soap/client.rb', line 16

def operations
  savon.operations
end

#regist_detail_info(options) ⇒ Object



29
30
31
32
33
34
35
36
# File 'lib/emay_soap/client.rb', line 29

def regist_detail_info(options)
  raise 'Detail info required' if options.blank?
  msg = { arg1: options[:e_name], arg2: options[:link_man],
          arg4: options[:phone_num], arg5: options[:mobile],
          arg6: options[:email], arg7: options[:fax],
          arg8: options[:address], arg9: options[:postcode] }
  call(:regist_detail_info, msg)
end

#regist_exObject

register cdkey



25
26
27
# File 'lib/emay_soap/client.rb', line 25

def regist_ex
  call(:regist_ex, arg2: @password)
end

#send_sms(mobiles, content, options = {}) ⇒ Object

send SMS out



50
51
52
53
54
55
56
# File 'lib/emay_soap/client.rb', line 50

def send_sms(mobiles, content, options = {})
  send_at = format_sent_at(options[:send_at]) unless options[:send_at].blank?
  mobiles = mobiles.is_a?(String) ? [mobiles] : mobiles
  content = "#{prefix} #{content}" unless prefix.nil?
  msg = { arg2: send_at, arg3: mobiles, arg4: content, arg5: options[:kind], arg6: nil, arg7: options[:priority], arg8: options[:id] }
  call(:send_sms, msg)
end

#serial_pwd_upd(new_password) ⇒ Object



58
59
60
# File 'lib/emay_soap/client.rb', line 58

def serial_pwd_upd(new_password)
  call(:serial_pwd_upd, arg2: @password, arg3: new_password)
end