Blame view

lib/syspro/syspro_response.rb 1.04 KB
dc8aa5b6   Joe Weakley   Rubocop corrections
1
2
3
  # frozen_string_literal: true
  
  require 'nokogiri'
db76748d   Isaac Lewis   cop a bunch of St...
4
5
  
  module Syspro
dc8aa5b6   Joe Weakley   Rubocop corrections
6
    # This class represents a syspro response
db76748d   Isaac Lewis   cop a bunch of St...
7
    class SysproResponse
0c0af54a   Isaac Lewis   error handling; c...
8
      attr_accessor :data, :http_body, :http_headers, :http_status, :request_id
db76748d   Isaac Lewis   cop a bunch of St...
9
10
11
  
      # Initializes a SysproResponse object from a Hash like the kind returned as
      # part of a Faraday exception.
db76748d   Isaac Lewis   cop a bunch of St...
12
13
      def self.from_faraday_hash(http_resp)
        resp = SysproResponse.new
db76748d   Isaac Lewis   cop a bunch of St...
14
        resp.http_body = http_resp[:body]
a61f2fc8   Isaac Lewis   parse logon profile
15
        resp.data = Nokogiri::XML(resp.http_body)
db76748d   Isaac Lewis   cop a bunch of St...
16
17
        resp.http_headers = http_resp[:headers]
        resp.http_status = http_resp[:status]
dc8aa5b6   Joe Weakley   Rubocop corrections
18
        resp.request_id = http_resp[:headers]['Request-Id']
db76748d   Isaac Lewis   cop a bunch of St...
19
20
21
22
        resp
      end
  
      # Initializes a SysproResponse object from a Faraday HTTP response object.
db76748d   Isaac Lewis   cop a bunch of St...
23
24
      def self.from_faraday_response(http_resp)
        resp = SysproResponse.new
db76748d   Isaac Lewis   cop a bunch of St...
25
        resp.http_body = http_resp.body
a61f2fc8   Isaac Lewis   parse logon profile
26
        resp.data = Nokogiri::XML(resp.http_body)
db76748d   Isaac Lewis   cop a bunch of St...
27
28
        resp.http_headers = http_resp.headers
        resp.http_status = http_resp.status
dc8aa5b6   Joe Weakley   Rubocop corrections
29
        resp.request_id = http_resp.headers['Request-Id']
db76748d   Isaac Lewis   cop a bunch of St...
30
31
32
33
        resp
      end
    end
  end