Class: NubankSdk::Client::HTTPS
- Inherits:
-
Object
- Object
- NubankSdk::Client::HTTPS
- Defined in:
- lib/nubank_sdk/client.rb
Instance Attribute Summary collapse
-
#headers ⇒ Object
Returns the value of attribute headers.
Instance Method Summary collapse
-
#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
62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/nubank_sdk/client.rb', line 62 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.
55 56 57 |
# File 'lib/nubank_sdk/client.rb', line 55 def headers @headers end |
Instance Method Details
#post(url, body) ⇒ Faraday::Response
Make a post request on connection
82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/nubank_sdk/client.rb', line 82 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 |