module EnotasNfe::Request
Public Instance Methods
delete(path, body = {})
click to toggle source
# File lib/enotas_nfe/request.rb, line 13 def delete(path, body = {}) request(:delete, path, body) end
get(path, body = {})
click to toggle source
# File lib/enotas_nfe/request.rb, line 5 def get(path, body = {}) request(:get, path, body) end
multipart_post(path, body = {})
click to toggle source
# File lib/enotas_nfe/request.rb, line 17 def multipart_post(path, body = {}) request_multipart(path, body) end
post(path, body = {})
click to toggle source
# File lib/enotas_nfe/request.rb, line 9 def post(path, body = {}) request(:post, path, body) end
Private Instance Methods
request(method, path, body)
click to toggle source
# File lib/enotas_nfe/request.rb, line 37 def request(method, path, body) body_serialized = serialize_body(body) response = connection.send(method) do |request| path = URI::DEFAULT_PARSER.escape(path) case method when :get, :delete request.url(path, body_serialized) when :post request.path = path EnotasNfe.logger.info request.body = body_serialized.to_json request.headers end end response.body end
request_multipart(path, body)
click to toggle source
# File lib/enotas_nfe/request.rb, line 23 def request_multipart(path, body) response = connection.post do |request| multipart_body = {} multipart_body["arquivo"] = Faraday::UploadIO.new(body[:arquivo], "application/x-pkcs12") multipart_body["senha"] = body[:senha] request.path = path request.body = multipart_body request.headers['Content-Type'] = 'multipart/form-data' end response.body end
serialize_body(body)
click to toggle source
# File lib/enotas_nfe/request.rb, line 56 def serialize_body(body) VirtusConvert.new(body, reject_nils: true).to_hash end