Class: Route53::AWSResponse

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resp, conn) ⇒ AWSResponse

Returns a new instance of AWSResponse.



232
233
234
235
236
237
238
239
240
241
242
243
244
245
# File 'lib/route53.rb', line 232

def initialize(resp,conn)
  @raw_data = resp
  if error?
    $stderr.puts "ERROR: Amazon returned an error for the request."
    $stderr.puts "ERROR: RAW_XML: "+@raw_data
    $stderr.puts "ERROR: "+error_message
    $stderr.puts ""
    $stderr.puts "What now? "+helpful_message
    #exit 1
  end
  @conn = conn
  @created = Time.now
  puts "Raw: #{@raw_data}" if @conn.verbose
end

Instance Attribute Details

#raw_dataObject (readonly)

Returns the value of attribute raw_data.



227
228
229
# File 'lib/route53.rb', line 227

def raw_data
  @raw_data
end

Instance Method Details

#complete?Boolean

Returns:

  • (Boolean)


265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
# File 'lib/route53.rb', line 265

def complete?
  return true if error?
  if @change_url.nil?
    change = Hpricot::XML(@raw_data).search("ChangeInfo")
    if change.size > 0
      @change_url = change.first.search("Id").first.innerText
    else
      return false
    end
  end
  if @complete.nil? || @complete == false
    status = Hpricot::XML(@conn.request(@conn.base_url+@change_url).raw_data).search("Status")
    @complete = status.size > 0 && status.first.innerText == "INSYNC" ? true : false
    if !@complete && @created - Time.now > 60
      $stderr.puts "WARNING: Amazon Route53 Change timed out on Sync. This may not be an issue as it may just be Amazon being assy. Then again your request may not have completed.'"
      @complete = true
    end
  end
  return @complete
end

#error?Boolean

Returns:

  • (Boolean)


247
248
249
# File 'lib/route53.rb', line 247

def error?
  return Hpricot::XML(@raw_data).search("ErrorResponse").size > 0
end

#error_messageObject



251
252
253
254
255
256
# File 'lib/route53.rb', line 251

def error_message
  xml = Hpricot::XML(@raw_data)
  msg_code = xml.search("Code")
  msg_text = xml.search("Message")
  return (msg_code.size > 0 ? msg_code.first.inner_text : "") + (msg_text.size > 0 ? ': ' + msg_text.first.innerText : "")
end

#helpful_messageObject



258
259
260
261
262
263
# File 'lib/route53.rb', line 258

def helpful_message
  xml = Hpricot::XML(@raw_data)
  msg_code = xml.search("Code").first.innerText
  return $messages[msg_code] if $messages[msg_code]
  return $messages["Other"]
end

#pending?Boolean

Returns:

  • (Boolean)


286
287
288
289
# File 'lib/route53.rb', line 286

def pending?
  #Return opposite of complete via XOR
  return complete? ^ true
end

#to_sObject



291
292
293
# File 'lib/route53.rb', line 291

def to_s
  return @raw_data
end