Class: NubankSdk::Client::HTTPS
- Inherits:
-
Object
- Object
- NubankSdk::Client::HTTPS
- Defined in:
- lib/nubank_sdk/client.rb
Overview
Create a new instance of Faraday::Connection with client certificate
Instance Attribute Summary collapse
-
#headers ⇒ Object
Returns the value of attribute headers.
Instance Method Summary collapse
-
#get(url) ⇒ Faraday::Response
Make a get request on connection.
-
#initialize(certificate, connection_adapter = nil) ⇒ HTTPS
constructor
Create a new instance of Faraday::Connection with client certificate.
-
#post(url, body) ⇒ Faraday::Response
Make a post request on connection.
Constructor Details
#initialize(certificate, connection_adapter = nil) ⇒ HTTPS
Create a new instance of Faraday::Connection with client certificate
74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/nubank_sdk/client.rb', line 74 def initialize(certificate, connection_adapter = nil) client_cert = OpenSSL::X509::Certificate.new(certificate.certificate) client_key = OpenSSL::PKey::RSA.new(certificate.key) @connection = Faraday.new( ssl: { client_cert: client_cert, client_key: client_key } ) { |faraday| faraday.adapter(*connection_adapter) if connection_adapter } @headers = {} end |
Instance Attribute Details
#headers ⇒ Object
Returns the value of attribute headers.
67 68 69 |
# File 'lib/nubank_sdk/client.rb', line 67 def headers @headers end |
Instance Method Details
#get(url) ⇒ Faraday::Response
Make a get request on connection
114 115 116 117 118 119 120 121 122 123 |
# File 'lib/nubank_sdk/client.rb', line 114 def get(url) @connection.get(url) do |req| req.headers['X-Correlation-Id'] = '772428d8-f0ee-43d6-8093-a13de3c9ce96' req.headers['User-Agent'] = "NubankSdk Client (#{NubankSdk::VERSION})" @headers.each do |header_key, value| req.headers[header_key] = value end end end |
#post(url, body) ⇒ Faraday::Response
Make a post request on connection
94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/nubank_sdk/client.rb', line 94 def post(url, body) @connection.post(url) do |req| req.headers['Content-Type'] = 'application/json' req.headers['X-Correlation-Id'] = '772428d8-f0ee-43d6-8093-a13de3c9ce96' req.headers['User-Agent'] = "NubankSdk Client (#{NubankSdk::VERSION})" @headers.each do |header_key, value| req.headers[header_key] = value end req.body = body.to_json end end |