lib/crp/review_response.rb in crp-0.0.6 vs lib/crp/review_response.rb in crp-0.0.7

- old
+ new

@@ -1,29 +1,37 @@ require 'json' module CRP class ReviewResponse SUCCESS_STATUS_CODE = 200 - EMPTY_JSON = "{}" def initialize(response) @response = response end def successful? @response.code.to_i == SUCCESS_STATUS_CODE end def raw_review - body = successful? ? @response.body : EMPTY_JSON - JSON.parse(body) + successful? ? json_parsed_body : {} end + def raw_errors + successful? ? {} : json_parsed_body["errors"] + end + def internal_id raw_review.first["internalId"].to_s end def external_id raw_review.first["externalId"] + end + + private + + def json_parsed_body + JSON.parse(@response.body) end end end