class Object

Public Instance Methods

check_need_value_in_two_way_info(two_way_info) click to toggle source

twoWayInfo 내부에 필요한 데이터가 존재하는지 검사

# File lib/easycodefrb/easycodef.rb, line 292
def check_need_value_in_two_way_info(two_way_info)
  return two_way_info['jobIndex'] != nil &&
    two_way_info['threadIndex'] != nil &&
    two_way_info['jti'] != nil &&
    two_way_info['twoWayTimestamp'] != nil
end
encrypt_RSA(text, public_key) click to toggle source

RSA 암호화한다 암호화할 정보와 퍼블릭키를 인자로 받는다

# File lib/easycodefrb/util.rb, line 18
def encrypt_RSA(text, public_key)
  pub = Base64.decode64(public_key)
  key = OpenSSL::PKey::RSA.new(pub)
  enc_str = key.public_encrypt(text)
  return Base64.encode64(enc_str).gsub(/\n/, '')
end
execute(url_path, body, access_token_cls, req_info, service_type) click to toggle source

API 요청 실행

# File lib/easycodefrb/connector.rb, line 97
def execute(url_path, body, access_token_cls, req_info, service_type)
  set_token(
    req_info.client_id,
    req_info.client_secret,
    access_token_cls,
    service_type
  )
  enc_body = CGI::escape(body.to_json())
  return request_product(
    req_info.domain + url_path,
    access_token_cls.get_token(service_type),
    enc_body
  )
end
get_codef_domain(service_type) click to toggle source

서비스 타입에 해당하는 코드에프 도메인 반환

# File lib/easycodefrb/properties.rb, line 36
def get_codef_domain(service_type)
  return case service_type
  when EasyCodef::TYPE_PRODUCT
    EasyCodef::API_DOMAIN
  when EasyCodef::TYPE_DEMO
    EasyCodef::DEMO_DOMAIN
  else
    EasyCodef::SANDBOX_DOMAIN
  end
end
has_require_two_way_info(param) click to toggle source

2Way 필수 데이터 검사

# File lib/easycodefrb/easycodef.rb, line 274
def has_require_two_way_info(param)
  if param == nil
    return false
  end
  is2_way = param['is2Way']
  if !!is2_way != is2_way || !is2_way
    return false
  end

  two_way_info = param['twoWayInfo']
  if two_way_info == nil
    return false
  end

  return check_need_value_in_two_way_info(two_way_info)
end
is_empty_two_way_keyword(param) click to toggle source

2Way 키워드 존재 여부 검사

# File lib/easycodefrb/easycodef.rb, line 266
def is_empty_two_way_keyword(param)
  if param == nil
    return true
  end
  return param['is2Way'] == nil && param['twoWayInfo'] == nil
end
new_response_message(message_info) click to toggle source

메시지 정보로 결과 생성 MessageInfo 인스턴스를 받아서 메시지 정보로 해시를 만든다

# File lib/easycodefrb/response.rb, line 3
def new_response_message(message_info)
  return {
    'result'=>{
      'code'=>message_info.code,
      'message'=>message_info.message,
      'extra_message'=>message_info.extra_message,
    },
    'data'=>{}
  }
end
request_token(client_id, client_secret) click to toggle source

엑세스 토큰 요청

# File lib/easycodefrb/connector.rb, line 50
def request_token(client_id, client_secret)
  uri = URI.parse(EasyCodef::OAUTH_DOMAIN + EasyCodef::PATH_GET_TOKEN)

  auth = client_id + ':' + client_secret
  enc_auth = Base64.encode64(auth).gsub(/\n/, '')

  header = {
    'Content-Type': 'application/x-www-form-urlencoded',
    'Authorization': 'Basic ' + enc_auth
  } 

  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = true
  req = Net::HTTP::Post.new(uri.request_uri, header)
  req.body = 'grant_type=client_credentials&scope=read'
  
  res = http.request(req)

  return case res
  when Net::HTTPOK
    JSON.parse(res.body)
  else
    return nil
  end
end
set_token(client_id, client_secret, access_token_cls, service_type) click to toggle source

토큰 셋팅 Codef 인스턴스 변수에 조회된 access_token을 셋팅한다

# File lib/easycodefrb/connector.rb, line 78
def set_token(client_id, client_secret, access_token_cls, service_type)
  repeat_cnt = 3
  i = 0
  if access_token_cls.get_token(service_type) == ''
    while i < repeat_cnt
      token_map = request_token(client_id, client_secret)
      if token_map != nil
        access_token = token_map[EasyCodef::KEY_ACCESS_TOKEN]
        access_token_cls.set_token(access_token, service_type)
        if access_token != nil && access_token != ''
          break
        end
      end
      i += 1
    end
  end
end