Module: ConfirmationCode::Service::Lianzhong

Extended by:
Lianzhong
Includes:
ConfirmationCode
Included in:
Lianzhong
Defined in:
lib/confirmation_code/service/lianzhong.rb

Constant Summary collapse

UPLOAD_URL =
'http://bbb4.hyslt.com/api.php?mod=php&act=upload'
ACCOUNT_URL =
'http://bbb4.hyslt.com/api.php?mod=php&act=point'
RECOGNITION_ERROR_URL =
'http://bbb4.hyslt.com/api.php?mod=php&act=error'

Constants included from ConfirmationCode

VERSION

Instance Attribute Summary

Attributes included from ConfirmationCode

#password, #username

Instance Method Summary collapse

Methods included from ConfirmationCode

#use

Instance Method Details

#account(options = {}) ⇒ Object



33
34
35
36
# File 'lib/confirmation_code/service/lianzhong.rb', line 33

def (options = {})
  response = client.post(ACCOUNT_URL, options)
  JSON.parse(response.body)
end

#clientObject



17
18
19
# File 'lib/confirmation_code/service/lianzhong.rb', line 17

def client
  @client ||= HTTPClient.new
end

#default_optionsObject



43
44
45
46
47
48
49
50
# File 'lib/confirmation_code/service/lianzhong.rb', line 43

def default_options
  {
      yzm_minlen:  '4',
      yzm_maxlen: '6',
      yzmtype_mark: '',
      zztool_token: '',
  }
end

#recognition_error(options = {}) ⇒ Object



38
39
40
41
# File 'lib/confirmation_code/service/lianzhong.rb', line 38

def recognition_error(options = {})
  response = client.post(RECOGNITION_ERROR_URL, options)
  JSON.parse(response.body)
end

#upload(image_url, options = {}) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/confirmation_code/service/lianzhong.rb', line 21

def upload(image_url, options = {})
  File.open("code.jpeg", "wb") do |f|
    f.write open(image_url).read
  end
  options = default_options.merge options
  File.open('code.jpeg') do |file|
    options['upload'] = file
    response = client.post(UPLOAD_URL, options)
    JSON.parse(response.body)
  end
end