Module: OneLogin::Api::Util::Parser

Included in:
OneLogin::Api::Util
Defined in:
lib/onelogin/api/util/parser.rb

Instance Method Summary collapse

Instance Method Details

#extract_error_attribute_from_response(response) ⇒ Object


31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/onelogin/api/util/parser.rb', line 31

def extract_error_attribute_from_response(response)
  attribute = nil
  content = JSON.parse(response.body)
  if content && content.has_key?('status')
    status = content['status']
    if status.has_key?('message') && status['message'].instance_of?(Hash)
      if status['message'].has_key?('attribute')
        attribute = status['message']['attribute']
      end
    end
  end
  attribute
end

#extract_error_message_from_response(response) ⇒ Object


5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/onelogin/api/util/parser.rb', line 5

def extract_error_message_from_response(response)
  message = ''
  content = JSON.parse(response.body)
  if content
    if content.has_key?('status')
      status = content['status']
      if status.has_key?('message')
        if status['message'].instance_of?(Hash)
          if status['message'].has_key?('description')
            message = status['message']['description']
          end
        else
          message = status['message']
        end
      elsif status.has_key?('type')
        message = status['type']
      end
    elsif content.has_key?('message')
      message = content['message']
    elsif content.has_key?('name')
      message = content['name']
    end
  end
  message
end

#extract_status_code_from_response(response) ⇒ Object


45
46
47
48
49
50
51
52
# File 'lib/onelogin/api/util/parser.rb', line 45

def extract_status_code_from_response(response)
  status_code = ''
  content = JSON.parse(response.body)
  if content && content.has_key?('statusCode')
    status_code = content['statusCode']
  end
  status_code
end