Module: ConfirmationCode::Service::Damatu
- Extended by:
- Damatu
- Includes:
- ConfirmationCode
- Included in:
- Damatu
- Defined in:
- lib/confirmation_code/service/damatu.rb
Constant Summary collapse
- HOST =
'http://api.dama2.com:7766'- UPLOAD_URL =
File.join(HOST, 'app/d2Url?')
- ACCOUNT_URL =
File.join(HOST, 'app/d2Balance?')
- RECOGNITION_ERROR_URL =
File.join(HOST, 'app/d2ReportError?')
Constants included from ConfirmationCode
Instance Attribute Summary collapse
-
#app_id ⇒ Object
readonly
Returns the value of attribute app_id.
-
#app_key ⇒ Object
readonly
Returns the value of attribute app_key.
Attributes included from ConfirmationCode
Instance Method Summary collapse
- #account(options = {}) ⇒ Object
- #client ⇒ Object
- #damatu_options(options) ⇒ Object
- #get_pwd(user, pwd) ⇒ Object
- #md5(value) ⇒ Object
- #recognition_error(ret_id, options = {}) ⇒ Object
- #result(body) ⇒ Object
- #set_app_key(app_key) ⇒ Object
- #set_extra_options(options) ⇒ Object
- #sign(user, param = []) ⇒ Object
- #upload(image_url, options = {}) ⇒ Object
Methods included from ConfirmationCode
Instance Attribute Details
#app_id ⇒ Object (readonly)
Returns the value of attribute app_id.
21 22 23 |
# File 'lib/confirmation_code/service/damatu.rb', line 21 def app_id @app_id end |
#app_key ⇒ Object (readonly)
Returns the value of attribute app_key.
21 22 23 |
# File 'lib/confirmation_code/service/damatu.rb', line 21 def app_key @app_key end |
Instance Method Details
#account(options = {}) ⇒ Object
64 65 66 67 68 69 |
# File 'lib/confirmation_code/service/damatu.rb', line 64 def account( = {}) = () ['sign'] = sign(['user']) response = client.get(ACCOUNT_URL, ) result(JSON.parse(response.body)) end |
#client ⇒ Object
35 36 37 |
# File 'lib/confirmation_code/service/damatu.rb', line 35 def client @client ||= HTTPClient.new end |
#damatu_options(options) ⇒ Object
81 82 83 84 85 86 87 88 |
# File 'lib/confirmation_code/service/damatu.rb', line 81 def () = {} ['appID'] = @app_id ['user'] = [:user_name] ['pwd'] = get_pwd([:user_name], [:user_pw]) ['type'] = [:type] unless [:type].nil? return end |
#get_pwd(user, pwd) ⇒ Object
43 44 45 46 47 48 |
# File 'lib/confirmation_code/service/damatu.rb', line 43 def get_pwd(user, pwd) ap md5(user) ap md5(pwd) ap md5(md5(user) + md5(pwd)) return md5(@app_key + md5(md5(user) + md5(pwd))) end |
#md5(value) ⇒ Object
39 40 41 |
# File 'lib/confirmation_code/service/damatu.rb', line 39 def md5(value) return Digest::MD5.hexdigest(value) end |
#recognition_error(ret_id, options = {}) ⇒ Object
71 72 73 74 75 76 77 78 79 |
# File 'lib/confirmation_code/service/damatu.rb', line 71 def recognition_error(ret_id, = {}) = () ['id'] = ret_id.to_s ['sign'] = sign(['user'], ret_id.to_s.bytes) ap response = client.post(RECOGNITION_ERROR_URL, ) ap response.body result(JSON.parse(response.body)) end |
#result(body) ⇒ Object
90 91 92 93 94 95 |
# File 'lib/confirmation_code/service/damatu.rb', line 90 def result(body) { "success" => body['ret'] == 0, "data" => body.except('ret', 'sign', 'cookie') } end |
#set_app_key(app_key) ⇒ Object
31 32 33 |
# File 'lib/confirmation_code/service/damatu.rb', line 31 def set_app_key(app_key) @app_key = app_key end |
#set_extra_options(options) ⇒ Object
26 27 28 29 |
# File 'lib/confirmation_code/service/damatu.rb', line 26 def () @app_key = [:app_key] @app_id = [:app_id] end |
#sign(user, param = []) ⇒ Object
50 51 52 53 |
# File 'lib/confirmation_code/service/damatu.rb', line 50 def sign(user, param = []) encode_str = (@app_key.bytes + user.bytes + param).pack('c*') return md5(encode_str)[0..7] end |
#upload(image_url, options = {}) ⇒ Object
55 56 57 58 59 60 61 62 |
# File 'lib/confirmation_code/service/damatu.rb', line 55 def upload(image_url, = {}) = () ['url'] = CGI::escape(image_url) ['sign'] = sign(['user'], image_url.bytes) ['type'] = 200 if ['type'].nil? response = client.get(UPLOAD_URL, ) result(JSON.parse(response.body)) end |