Class: Stellae::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/stellae/response.rb

Constant Summary collapse

CODES =
{
  "0001" => "success",
  "0002" => "Bad login information",
  "0003" => "Login points to multiple databases",
  "0005" => "Invalid order type must be OO or CM",
  "0006" => "Error creating order header",
  "0007" => "Bad UPC/EAN13",
  "0008" => "Duplicate order – order number exists in database",
  "0009" => "Problem with line item import"
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw_response, type) ⇒ Response

Returns a new instance of Response.



17
18
19
20
# File 'lib/stellae/response.rb', line 17

def initialize(raw_response, type)
  build_response(raw_response)
  @type = type
end

Instance Attribute Details

#responseObject

Returns the value of attribute response.



15
16
17
# File 'lib/stellae/response.rb', line 15

def response
  @response
end

#resultObject

Returns the value of attribute result.



15
16
17
# File 'lib/stellae/response.rb', line 15

def result
  @result
end

#statusObject

Returns the value of attribute status.



15
16
17
# File 'lib/stellae/response.rb', line 15

def status
  @status
end

Instance Method Details

#build_response(raw_response) ⇒ Object



22
23
24
25
26
27
# File 'lib/stellae/response.rb', line 22

def build_response(raw_response)
  @response ||= {
    raw:    raw_response,
    parsed: parse_response(raw_response)
  }
end

#errorObject



29
30
31
# File 'lib/stellae/response.rb', line 29

def error
  "Stellae::Error - #{status}"
end

#failure?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/stellae/response.rb', line 33

def failure?
  !success?
end

#parse_response(xml_response) ⇒ Object



53
54
55
56
# File 'lib/stellae/response.rb', line 53

def parse_response(xml_response)
  return nil if xml_response.empty?
  XmlSimple.xml_in(xml_response)
end

#raw_statusObject



41
42
43
# File 'lib/stellae/response.rb', line 41

def raw_status
  result['status'][0]
end

#success?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/stellae/response.rb', line 49

def success?
  status == 'success'
end