Blame view

lib/syspro/syspro_response.rb 995 Bytes
db76748d   Isaac Lewis   cop a bunch of St...
1
2
3
  require "nokogiri"
  
  module Syspro
db76748d   Isaac Lewis   cop a bunch of St...
4
    class SysproResponse
0c0af54a   Isaac Lewis   error handling; c...
5
      attr_accessor :data, :http_body, :http_headers, :http_status, :request_id
db76748d   Isaac Lewis   cop a bunch of St...
6
7
8
  
      # 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...
9
10
      def self.from_faraday_hash(http_resp)
        resp = SysproResponse.new
db76748d   Isaac Lewis   cop a bunch of St...
11
        resp.http_body = http_resp[:body]
a61f2fc8   Isaac Lewis   parse logon profile
12
        resp.data = Nokogiri::XML(resp.http_body)
db76748d   Isaac Lewis   cop a bunch of St...
13
14
15
16
17
18
19
        resp.http_headers = http_resp[:headers]
        resp.http_status = http_resp[:status]
        resp.request_id = http_resp[:headers]["Request-Id"]
        resp
      end
  
      # Initializes a SysproResponse object from a Faraday HTTP response object.
db76748d   Isaac Lewis   cop a bunch of St...
20
21
      def self.from_faraday_response(http_resp)
        resp = SysproResponse.new
db76748d   Isaac Lewis   cop a bunch of St...
22
        resp.http_body = http_resp.body
a61f2fc8   Isaac Lewis   parse logon profile
23
        resp.data = Nokogiri::XML(resp.http_body)
db76748d   Isaac Lewis   cop a bunch of St...
24
25
26
27
28
29
30
        resp.http_headers = http_resp.headers
        resp.http_status = http_resp.status
        resp.request_id = http_resp.headers["Request-Id"]
        resp
      end
    end
  end