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
# 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|
      case msg['ERR_CD']
      when 'ILLEGAL_OPERATION'
        raise IllegalOperationError, msg['INFO']
      when 'INTERNAL_ERROR'
        raise InternalErrorError, msg['INFO']
      when 'INVALID_DATA'
        raise InvalidDataError, msg['INFO']
      when 'INVALID_REQUEST'
        raise InvalidRequestError, msg['INFO']
      when 'INVALID_VERSION'
        raise InvalidVersionError, msg['INFO']
      when 'MISSING_DATA'
        raise MissingDataError, msg['INFO']
      when 'NOT_FOUND'
        raise NotFoundError, msg['INFO']
      when 'OPERATION_FAILED'
        raise OperationFailedError, msg['INFO']
      when 'PERMISSION_DENIED'
        raise PermissionDeniedError, msg['INFO']
      when 'SERVICE_UNAVAILABLE'
        raise ServiceUnavailableError, msg['INFO']
      when 'TARGET_EXISTS'
        raise TargetExistsError, msg['INFO']
      when 'UNKNOWN_ERROR'
        raise UnknownErrorError, msg['INFO']
      end
    end
  end
end

Instance Method Details

#[](key) ⇒ Object



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

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