Class: VeriTrans::ApiBase

Inherits:
Object
  • Object
show all
Defined in:
lib/veri_trans/api_base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(setting) ⇒ ApiBase

Returns a new instance of ApiBase.

Parameters:



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/veri_trans/api_base.rb', line 15

def initialize(setting)
  @server_key = setting.server_key
  @ca_cert_file_path = setting.ca_cert_path
  @host = setting.request_host
  @use_ssl = setting.use_https_request
  @port = setting.request_host_port
  @verify_ssl = setting.verify_ssl

  @http_request = HttpRequest.new(
    server_key: @server_key,
    host: @host,
    use_ssl: @use_ssl,
    port: @port,
    verify_ssl: @verify_ssl,
    ca_cert_file_path: @ca_cert_file_path,
  )

end

Instance Attribute Details

#ca_cert_file_pathObject

Returns the value of attribute ca_cert_file_path.



11
12
13
# File 'lib/veri_trans/api_base.rb', line 11

def ca_cert_file_path
  @ca_cert_file_path
end

#hostObject

Returns the value of attribute host.



11
12
13
# File 'lib/veri_trans/api_base.rb', line 11

def host
  @host
end

#http_requestObject (readonly)

Returns the value of attribute http_request.



12
13
14
# File 'lib/veri_trans/api_base.rb', line 12

def http_request
  @http_request
end

#portObject

Returns the value of attribute port.



11
12
13
# File 'lib/veri_trans/api_base.rb', line 11

def port
  @port
end

#server_keyObject

Returns the value of attribute server_key.



11
12
13
# File 'lib/veri_trans/api_base.rb', line 11

def server_key
  @server_key
end

#use_sslObject

Returns the value of attribute use_ssl.



11
12
13
# File 'lib/veri_trans/api_base.rb', line 11

def use_ssl
  @use_ssl
end

#verify_sslObject

Returns the value of attribute verify_ssl.



11
12
13
# File 'lib/veri_trans/api_base.rb', line 11

def verify_ssl
  @verify_ssl
end

Instance Method Details

#do_request_get(path, params) ⇒ Object

Returns Json decoded object.

Parameters:

  • path (String)
  • params (Array)

Returns:

  • (Object)

    Json decoded object



49
50
51
52
53
54
55
56
57
# File 'lib/veri_trans/api_base.rb', line 49

def do_request_get(path, params)
  result_body = @http_request.send_get_request(path: path, params: params)
  begin
    JSON.parse(result_body)
  rescue
    raise VtdException::VtDirectError("Could not decode from JSON to ruby object.\r\n#{result_body}")
  end

end

#do_request_post(path, entity) ⇒ Object

Parameters:

  • path (String)
  • entity (Object)


36
37
38
39
40
41
42
43
44
# File 'lib/veri_trans/api_base.rb', line 36

def do_request_post(path, entity)
  result_body = @http_request.send_post_request(path: path, body: ActiveSupport::JSON.encode(entity))
  begin
    JSON.parse(result_body)
  rescue
    raise VtdException::VtDirectError("Could not decode from JSON to ruby object.\r\n#{result_body}")
  end

end