Class: Kount::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/kount/request.rb

Direct Known Subclasses

RiskInquiry

Instance Method Summary collapse

Instance Method Details

#get_post_fields(query_params) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/kount/request.rb', line 30

def get_post_fields(query_params)
  fields = []
  query_params.each { |k,v|
    if v.is_a?(Array)
      v.each { |element|
        fields << Curl::PostField.content(k,element)
      }
    else
      fields << Curl::PostField.content(k,v)
    end
  }
  fields
end

#transmit(service_type, endpoint_url, get_or_post, query_params = {}) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/kount/request.rb', line 3

def transmit(service_type,endpoint_url,get_or_post,query_params={})
  url = [Kount::KOUNT_SERVER_URLS[service_type][Kount.mode],endpoint_url].join

  Rails.logger.info ["Kount request: ",url].join if defined?(Rails)

  c = Curl::Easy.new(url) do |curl|
    curl.certtype = 'PEM'
    if service_type == :api
      curl.cert = Kount.api_cert
      curl.cert_key = Kount.api_cert_key
    elsif service_type == :risk
      curl.cert = Kount.ris_cert
      curl.cert_key = Kount.ris_cert_key
    end
    curl.connect_timeout = 5
  end

  if get_or_post.downcase == 'get'
    c.http_get
  elsif get_or_post.downcase == 'post'
    c.http_post(get_post_fields(query_params))
  end
  Kount::Response.new(service_type,c)
rescue Exception => e
  Kount::Error.new(e)
end