Class: VeriTrans::HttpRequest
- Inherits:
-
Object
- Object
- VeriTrans::HttpRequest
- Defined in:
- lib/veri_trans/http_request.rb
Instance Attribute Summary collapse
-
#host ⇒ Object
Returns the value of attribute host.
-
#port ⇒ Object
Returns the value of attribute port.
-
#server_key ⇒ Object
Returns the value of attribute server_key.
-
#use_ssl ⇒ Object
Returns the value of attribute use_ssl.
Instance Method Summary collapse
- #generate_resource_option ⇒ Object
-
#initialize(server_key: nil, host: nil, use_ssl: true, port: 443, verify_ssl: true, ca_cert_file_path: nil) ⇒ HttpRequest
constructor
A new instance of HttpRequest.
- #send_get_request(path: nil, params: nil) ⇒ Object
- #send_post_request(path: nil, body: nil) ⇒ Object
Constructor Details
#initialize(server_key: nil, host: nil, use_ssl: true, port: 443, verify_ssl: true, ca_cert_file_path: nil) ⇒ HttpRequest
Returns a new instance of HttpRequest.
11 12 13 14 15 16 17 18 |
# File 'lib/veri_trans/http_request.rb', line 11 def initialize(server_key: nil, host: nil, use_ssl: true, port: 443, verify_ssl: true, ca_cert_file_path: nil) @server_key = server_key @host = host @port = port @use_ssl = use_ssl @verify_ssl = verify_ssl @ca_cert_file_path = ca_cert_file_path end |
Instance Attribute Details
#host ⇒ Object
Returns the value of attribute host.
9 10 11 |
# File 'lib/veri_trans/http_request.rb', line 9 def host @host end |
#port ⇒ Object
Returns the value of attribute port.
9 10 11 |
# File 'lib/veri_trans/http_request.rb', line 9 def port @port end |
#server_key ⇒ Object
Returns the value of attribute server_key.
9 10 11 |
# File 'lib/veri_trans/http_request.rb', line 9 def server_key @server_key end |
#use_ssl ⇒ Object
Returns the value of attribute use_ssl.
9 10 11 |
# File 'lib/veri_trans/http_request.rb', line 9 def use_ssl @use_ssl end |
Instance Method Details
#generate_resource_option ⇒ Object
62 63 64 65 66 67 68 |
# File 'lib/veri_trans/http_request.rb', line 62 def generate_resource_option { :timeout => 130, :verify_ssl => (@verify_ssl) ? OpenSSL::SSL::VERIFY_PEER : OpenSSL::SSL::VERIFY_NONE, :ssl_ca_file => @ca_cert_file_path } end |
#send_get_request(path: nil, params: nil) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/veri_trans/http_request.rb', line 20 def send_get_request(path: nil, params: nil) full_url = generate_api_url(path: path) full_url += '?' + params.to_query(nil) if params begin resource = RestClient::Resource.new(full_url, generate_resource_option) response = resource.get if response.code == 200 response.to_str else raise(VtdException::VtDirectNetworkError, 'Http status error occurred.') end rescue => e raise(VtdException::VtDirectNetworkError, e.) end end |
#send_post_request(path: nil, body: nil) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/veri_trans/http_request.rb', line 36 def send_post_request(path: nil, body: nil) full_url = generate_api_url(path: path) begin resource = RestClient::Resource.new(full_url, generate_resource_option) header = { :content_type => :json, :accept => :json, 'User-Agent' => "VTDirect/v1 RubyBindings/#{Setting::VERSION}", 'Authorization' => "Basic #{Base64.strict_encode64(@server_key)}" } response = resource.post( body, header ) if response.code == 200 response.to_str else raise(VtdException::VtDirectNetworkError, 'Http status error occurred.') end rescue => e raise(VtdException::VtDirectNetworkError, e.) end end |