Class: Cmbchina::SessionObject

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/cmbchina.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message = nil) ⇒ SessionObject

Returns a new instance of SessionObject.



117
118
119
120
121
122
123
124
# File 'lib/cmbchina.rb', line 117

def initialize(message = nil)
  if message.present? and message[0]=='Y'
    @client_no = message[1]
    @serial_no = message[2]
  else
    raise "could not connect the cmbchina api url"
  end
end

Instance Attribute Details

#client_noObject

会话号码



114
115
116
# File 'lib/cmbchina.rb', line 114

def client_no
  @client_no
end

#serial_noObject

序列号



115
116
117
# File 'lib/cmbchina.rb', line 115

def serial_no
  @serial_no
end

Instance Method Details

#get_order(bill_no, bill_date) ⇒ Object



153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'lib/cmbchina.rb', line 153

def get_order( bill_no, bill_date )
  options = {
    version: 1,
    co_no: Cmbchina.co_no,
    date: bill_date,
    bill_no: bill_no
  }
  message_order = post_command('DirectQuerySingleOrder', options)
  if message_order.shift == 'Y' and message_order.size > 2
    message_order.push bill_no
    Cmbchina::Order.new( message_order )
  end
end

#login(pwd = nil) ⇒ Object



126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/cmbchina.rb', line 126

def (pwd = nil)
  pwd = Cmbchina.password unless pwd
  message = post_command('DirectLogonC', { pwd: pwd })

  if message.present? and message[0]=='Y'
    @client_no = message[1] if message[1]
    @serial_no = message[2] if message[2]
  else
    raise "login fails"
  end
  message
end

#logoutObject



139
140
141
# File 'lib/cmbchina.rb', line 139

def logout
  post_command('DirectExit')
end

#query_refund_orders(options) ⇒ Object



148
149
150
151
# File 'lib/cmbchina.rb', line 148

def query_refund_orders(options)
  message_array = post_command('DirectQueryRefundByDate', query_order_options(options))
  explan_order_list( message_array )
end

#query_settled_orders(options) ⇒ Object



143
144
145
146
# File 'lib/cmbchina.rb', line 143

def query_settled_orders(options)
  message_array = post_command('DirectQuerySettledOrderByPage', query_order_options(options))
  explan_order_list( message_array )
end

#refund(options) ⇒ Object



167
168
169
170
171
172
173
174
175
176
# File 'lib/cmbchina.rb', line 167

def refund( options )
  refund_options = {
    date: options[:date],
    bill_no: options[:bill_no],
    amount: options[:amount],
    desc: options[:desc],
    vcode: get_vcode(options)
  }
  post_command('DirectRefund', refund_options )
end