Class: Spear::Structure::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/spear/structure/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ Base

Returns a new instance of Base.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/spear/structure/base.rb', line 7

def initialize(response)
  raise Spear::ParametersRequired.new('Response') if response.nil?

  @response = response

  # Note: <b>Application Form API</b> return html string.

  if response.kind_of?(Hash)
    # get the root keyvalue of the hash
    if response.to_h.has_key?('Errors')
      @root = response.to_h
    else
      @root = response.to_h.first.last
    end

    # Note: <b>Application Status API</b> is different.
    @status = @root["Status"] || @root['ApplicationStatus']
    @error_message = get_error_message(@root)
  end
end

Instance Attribute Details

#error_messageObject (readonly)

response is an instance of Httparty::Response



5
6
7
# File 'lib/spear/structure/base.rb', line 5

def error_message
  @error_message
end

#responseObject (readonly)

response is an instance of Httparty::Response



5
6
7
# File 'lib/spear/structure/base.rb', line 5

def response
  @response
end

#rootObject (readonly)

response is an instance of Httparty::Response



5
6
7
# File 'lib/spear/structure/base.rb', line 5

def root
  @root
end

#statusObject (readonly)

response is an instance of Httparty::Response



5
6
7
# File 'lib/spear/structure/base.rb', line 5

def status
  @status
end

Instance Method Details

#success?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/spear/structure/base.rb', line 28

def success?
  @status.nil? ? @error_message.nil? : (@status.include?('Success') or @status.include?('Complete'))
end