Class: Dynect::Response

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

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ Response

Returns a new instance of Response.



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/dynect4r.rb', line 91

def initialize(response)

  # parse response
  begin
    @hash = JSON.parse(response)
  rescue JSON::ParserError
    if response =~ /REST\/Job\/[0-9]+/
      raise RedirectError, response
    else
     raise
    end
  end

  # raise error based on error code
  if @hash.has_key?('msgs')
    @hash['msgs'].each do |msg|
      m=msg['INFO']+" -- "+@hash.inspect
      case msg['ERR_CD']
      when 'ILLEGAL_OPERATION'
        raise IllegalOperationError, m
      when 'INTERNAL_ERROR'
        raise InternalErrorError, m
      when 'INVALID_DATA'
        raise InvalidDataError, m
      when 'INVALID_REQUEST'
        raise InvalidRequestError, m
      when 'INVALID_VERSION'
        raise InvalidVersionError, m
      when 'MISSING_DATA'
        raise MissingDataError, m
      when 'NOT_FOUND'
        raise NotFoundError, m
      when 'OPERATION_FAILED'
        raise OperationFailedError, m
      when 'PERMISSION_DENIED'
        raise PermissionDeniedError, m
      when 'SERVICE_UNAVAILABLE'
        raise ServiceUnavailableError, m
      when 'TARGET_EXISTS'
        raise TargetExistsError, m
      when 'UNKNOWN_ERROR'
        raise UnknownErrorError, m
      end
    end
  end
end

Instance Method Details

#[](key) ⇒ Object



138
139
140
# File 'lib/dynect4r.rb', line 138

def [](key)
  @hash[key]
end